diff options
author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-06-25 13:42:08 +0000 |
---|---|---|
committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-06-25 13:42:08 +0000 |
commit | bb28985b6446269b6eed7c487a7ad5c961f24ffd (patch) | |
tree | f17fb69d180caee260457e049754a48c21387d1d /frontends/php | |
parent | 820ab6ba3fbd1e0322664156162bb51e9daeaf7d (diff) | |
download | zabbix-bb28985b6446269b6eed7c487a7ad5c961f24ffd.tar.gz zabbix-bb28985b6446269b6eed7c487a7ad5c961f24ffd.tar.xz zabbix-bb28985b6446269b6eed7c487a7ad5c961f24ffd.zip |
- [DEV-137] fixes to types definition (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5791 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
-rw-r--r-- | frontends/php/include/db.inc.php | 2 | ||||
-rw-r--r-- | frontends/php/include/items.inc.php | 110 | ||||
-rw-r--r-- | frontends/php/include/profiles.inc.php | 20 | ||||
-rw-r--r-- | frontends/php/items.php | 4 |
4 files changed, 61 insertions, 75 deletions
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php index 1136adcc..31f018c3 100644 --- a/frontends/php/include/db.inc.php +++ b/frontends/php/include/db.inc.php @@ -645,7 +645,7 @@ else { if(empty($nodes)) $nodes = 0; - if(ctype_digit($nodes)){ + if(is_numeric($nodes)){ $nodes = array($nodes); } else if(is_string($nodes)){ diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index 10fec58c..c2c41c9b 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -194,43 +194,35 @@ if(($i = array_search(0,$applications)) !== FALSE) unset($applications[$i]); - if( !eregi('^'.ZBX_EREG_ITEM_KEY_FORMAT.'$', $key) ) - { + if( !eregi('^'.ZBX_EREG_ITEM_KEY_FORMAT.'$', $key) ){ error("Incorrect key format 'key_name[param1,param2,...]'"); return false; } - if($delay<1) - { + if($delay<1){ error("Delay cannot be less than 1 second"); return FALSE; } - if( ($snmp_port<1)||($snmp_port>65535)) - { + if( ($snmp_port<1)||($snmp_port>65535)){ error("Invalid SNMP port"); return FALSE; } - if($value_type == ITEM_VALUE_TYPE_STR) - { + if($value_type == ITEM_VALUE_TYPE_STR){ $delta=0; } - if( ($type == ITEM_TYPE_AGGREGATE) && ($value_type != ITEM_VALUE_TYPE_FLOAT)) - { + if( ($type == ITEM_TYPE_AGGREGATE) && ($value_type != ITEM_VALUE_TYPE_FLOAT)){ error("Value type must be Float for aggregate items"); return FALSE; } - if($type == ITEM_TYPE_AGGREGATE) - { + if($type == ITEM_TYPE_AGGREGATE){ /* grpfunc('group','key','itemfunc','numeric param') */ // if(eregi('^((.)*)(\(\'((.)*)\'\,\'((.)*)\'\,\'((.)*)\'\,\'([0-9]+)\'\))$', $key, $arr)) - if(eregi('^((.)*)(\[\"((.)*)\"\,\"((.)*)\"\,\"((.)*)\"\,\"([0-9]+)\"\])$', $key, $arr)) - { + if(eregi('^((.)*)(\[\"((.)*)\"\,\"((.)*)\"\,\"((.)*)\"\,\"([0-9]+)\"\])$', $key, $arr)){ $g=$arr[1]; - if(!str_in_array($g,array("grpmax","grpmin","grpsum","grpavg"))) - { + if(!str_in_array($g,array("grpmax","grpmin","grpsum","grpavg"))){ error("Group function [$g] is not one of [grpmax,grpmin,grpsum,grpavg]"); return FALSE; } @@ -240,71 +232,72 @@ $g=$arr[6]; // Item function $g=$arr[8]; - if(!str_in_array($g,array("last", "min", "max", "avg", "sum","count"))) - { - error("Item function [$g] is not one of [last, min, max, avg, sum,count]"); + if(!str_in_array($g,array('last', 'min', 'max', 'avg', 'sum','count'))){ + error('Item function ['.$g.'] is not one of [last, min, max, avg, sum,count]'); return FALSE; } // Parameter $g=$arr[10]; } - else - { - error("Key does not match grpfunc[\"group\",\"key\",\"itemfunc\",\"numeric param\")"); + else{ + error('Key does not match grpfunc["group","key","itemfunc","numeric param")'); return FALSE; } } - $db_item = DBfetch(DBselect("select itemid,hostid from items". - " where hostid=$hostid and key_=".zbx_dbstr($key))); + $db_item = DBfetch(DBselect('SELECT itemid,hostid '. + ' FROM items '. + ' WHERE hostid='.$hostid. + ' AND key_='.zbx_dbstr($key))); if($db_item && $templateid == 0){ - error("An item with the Key [".$key."] already exists for host [".$host["host"]."].". - " The key must be unique."); + error('An item with the Key ['.$key.'] already exists for host ['.$host['host'].']. The key must be unique.'); return FALSE; } else if ($db_item && $templateid != 0){ $result = update_item( - $db_item["itemid"], $description, $key, $db_item["hostid"], + $db_item['itemid'], $description, $key, $db_item['hostid'], $delay, $history, $status, $type, $snmp_community, $snmp_oid, $value_type, $trapper_hosts, $snmp_port, $units, $multiplier, $delta, $snmpv3_securityname, $snmpv3_securitylevel, $snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula, $trends, $logtimefmt, $valuemapid, $delay_flex, $params, - get_same_applications_for_host($applications, $db_item["hostid"]), + get_same_applications_for_host($applications, $db_item['hostid']), $templateid); return $result; } // first add mother item - $itemid=get_dbid("items","itemid"); - $result=DBexecute("insert into items". - " (itemid,description,key_,hostid,delay,history,nextcheck,status,type,". - "snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,". - "delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,". - "snmpv3_privpassphrase,formula,trends,logtimefmt,valuemapid,delay_flex,params,templateid)". - " values ($itemid,".zbx_dbstr($description).",".zbx_dbstr($key).",$hostid,$delay,$history,0, - $status,$type,".zbx_dbstr($snmp_community).",".zbx_dbstr($snmp_oid).",$value_type,". - zbx_dbstr($trapper_hosts).",$snmp_port,".zbx_dbstr($units).",$multiplier,$delta,". - zbx_dbstr($snmpv3_securityname).",$snmpv3_securitylevel,". - zbx_dbstr($snmpv3_authpassphrase).",".zbx_dbstr($snmpv3_privpassphrase).",". - zbx_dbstr($formula).",$trends,".zbx_dbstr($logtimefmt).",$valuemapid,". - zbx_dbstr($delay_flex).",".zbx_dbstr($params).",$templateid)"); + $itemid=get_dbid('items','itemid'); + $result=DBexecute('INSERT INTO items '. + ' (itemid,description,key_,hostid,delay,history,nextcheck,status,type,'. + 'snmp_community,snmp_oid,value_type,trapper_hosts,'. + 'snmp_port,units,multiplier,'. + 'delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,'. + 'snmpv3_privpassphrase,formula,trends,logtimefmt,valuemapid,'. + 'delay_flex,params,templateid)'. + ' VALUES ('.$itemid.','.zbx_dbstr($description).','.zbx_dbstr($key).','.$hostid.','.$delay.','.$history.',0,'.$status.','.$type.','. + zbx_dbstr($snmp_community).','.zbx_dbstr($snmp_oid).','.$value_type.','.zbx_dbstr($trapper_hosts).','. + $snmp_port.','.zbx_dbstr($units).','.$multiplier.','. + $delta.','.zbx_dbstr($snmpv3_securityname).','.$snmpv3_securitylevel.','.zbx_dbstr($snmpv3_authpassphrase).','. + zbx_dbstr($snmpv3_privpassphrase).','.zbx_dbstr($formula).','.$trends.','.zbx_dbstr($logtimefmt).','.$valuemapid.','. + zbx_dbstr($delay_flex).','.zbx_dbstr($params).','.$templateid.')' + ); if(!$result) return $result; foreach($applications as $appid){ - $itemappid=get_dbid("items_applications","itemappid"); - DBexecute("insert into items_applications (itemappid,itemid,applicationid) values($itemappid,".$itemid.",".$appid.")"); + $itemappid=get_dbid('items_applications','itemappid'); + DBexecute('INSERT INTO items_applications (itemappid,itemid,applicationid) VALUES('.$itemappid.','.$itemid.','.$appid.')'); } - info("Added new item ".$host["host"].":$key"); + info('Added new item '.$host['host'].':$key'); // add items to child hosts - $db_hosts = get_hosts_by_templateid($host["hostid"]); + $db_hosts = get_hosts_by_templateid($host['hostid']); while($db_host = DBfetch($db_hosts)){ // recursion $result = add_item($description, $key, $db_host["hostid"], @@ -537,33 +530,26 @@ * Comments: !!! Don't forget sync code with C !!! * */ - function delete_template_items($hostid, $templateid = null, $unlink_mode = false) - { + function delete_template_items($hostid, $templateid = null, $unlink_mode = false){ $db_items = get_items_by_hostid($hostid); - while($db_item = DBfetch($db_items)) - { + while($db_item = DBfetch($db_items)){ if($db_item["templateid"] == 0) continue; - if( !is_null($templateid)) - { - if ( !is_array($templateid) ) $templateid = array($templateid); + if( !is_null($templateid)){ + if(!is_array($templateid)) $templateid = array($templateid); $db_tmp_item = get_item_by_itemid($db_item["templateid"]); - if ( !uint_in_array($db_tmp_item["hostid"], $templateid) ) - continue; + if(!uint_in_array($db_tmp_item["hostid"], $templateid)) continue; } - if($unlink_mode) - { - if(DBexecute("update items set templateid=0 where itemid=".$db_item["itemid"])) - { - info("Item '".$db_item["key_"]."' unlinked"); - } + if($unlink_mode){ + if(DBexecute("update items set templateid=0 where itemid=".$db_item["itemid"])){ + info("Item '".$db_item["key_"]."' unlinked"); + } } - else - { + else{ delete_item($db_item["itemid"]); } } diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php index 5790c356..1e7bb474 100644 --- a/frontends/php/include/profiles.inc.php +++ b/frontends/php/include/profiles.inc.php @@ -31,7 +31,7 @@ function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNKNOWN,$idx2=n if($USER_DETAILS["alias"]!=ZBX_GUEST_USER){ $sql_cond = ''; if(profile_type($type,'id')) $sql_cond.= ' AND '.DBin_node('value_id'); - if(ctype_digit($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); + if(is_numeric($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); if(!is_null($source)) $sql_cond.= ' AND source='.zbx_dbstr($source); $sql = 'SELECT value_id, value_int, value_str, type '. @@ -72,7 +72,7 @@ function get_source_profile($idx,$default_value=array(),$type=PROFILE_TYPE_UNKNO if($USER_DETAILS["alias"]!=ZBX_GUEST_USER){ $sql_cond = ''; if(profile_type($type,'id')) $sql_cond.= ' AND '.DBin_node('value_id'); - if(ctype_digit($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); + if(is_numeric($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); if(!is_null($source)) $sql_cond.= ' AND source='.zbx_dbstr($source); $sql = 'SELECT value_id,value_int,value_str,source,type '. @@ -116,7 +116,7 @@ function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN,$idx2=null,$sourc if($value === false) return false; $sql_cond = ''; - if(ctype_digit($idx2)) $sql_cond = ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); + if(is_numeric($idx2)) $sql_cond = ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); DBstart(); if(profile_type($type,'array')){ @@ -153,7 +153,7 @@ function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN,$idx2=null,$sourc $val[$value_type] = $value; - $idx2 = ctype_digit($idx2)?$idx2:0; + $idx2 = is_numeric($idx2)?$idx2:0; $src = is_null($source)?'':$source; if(is_array($value)){ @@ -195,7 +195,7 @@ function insert_profile($idx,$value,$type,$idx2,$source){ $val[$value_type] = $value; - $idx2 = ctype_digit($idx2)?$idx2:0; + $idx2 = is_numeric($idx2)?$idx2:0; $src = is_null($source)?'':$source; if(is_array($value)){ @@ -271,14 +271,14 @@ function profile_type_by_value($value,$type=PROFILE_TYPE_UNKNOWN){ if(is_array($value)){ if(isset($value['value'])) - $type=ctype_digit($value['value'])?PROFILE_TYPE_ARRAY_ID:PROFILE_TYPE_ARRAY_STR; + $type=is_numeric($value['value'])?PROFILE_TYPE_ARRAY_ID:PROFILE_TYPE_ARRAY_STR; } else{ - $type=ctype_digit($value)?PROFILE_TYPE_ARRAY_ID:PROFILE_TYPE_ARRAY_STR; + $type=is_numeric($value)?PROFILE_TYPE_ARRAY_ID:PROFILE_TYPE_ARRAY_STR; } } else{ - if(ctype_digit($value)) $type = PROFILE_TYPE_ID; + if(is_numeric($value)) $type = PROFILE_TYPE_ID; else $type = PROFILE_TYPE_STR; } return $type; @@ -296,7 +296,7 @@ function profile_value_by_type(&$value,$type){ switch($type){ case PROFILE_TYPE_ID: case PROFILE_TYPE_INT: - if(ctype_digit($value['value'])){ + if(is_numeric($value['value'])){ $result['value'] = intval($value['value']); } else{ @@ -314,7 +314,7 @@ function profile_value_by_type(&$value,$type){ switch($type){ case PROFILE_TYPE_ID: case PROFILE_TYPE_INT: - $result = ctype_digit($value)?intval($value):false; + $result = is_numeric($value)?intval($value):false; break; case PROFILE_TYPE_STR: $result = strval($value); diff --git a/frontends/php/items.php b/frontends/php/items.php index 8b78bed6..b63c3920 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -462,11 +462,11 @@ include_once "include/page_header.php"; } } - $result = true; + $result = false; DBstart(); foreach($_REQUEST["group_itemid"] as $item_id) foreach($hosts_ids as $host_id){ - $result &= copy_item_to_host($item_id, $host_id, true); + $result |= copy_item_to_host($item_id, $host_id, true); } $result = DBend($result); |