diff options
author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-06-25 15:38:32 +0000 |
---|---|---|
committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-06-25 15:38:32 +0000 |
commit | e20118aa386b5d231699ee309a6cd7cbdd166756 (patch) | |
tree | 9c0a0dc1adc4960ab13b3595f7e58c1cd8974f52 | |
parent | bb28985b6446269b6eed7c487a7ad5c961f24ffd (diff) | |
download | zabbix-e20118aa386b5d231699ee309a6cd7cbdd166756.tar.gz zabbix-e20118aa386b5d231699ee309a6cd7cbdd166756.tar.xz zabbix-e20118aa386b5d231699ee309a6cd7cbdd166756.zip |
- [DEV-137] improvements to triggers & items actions (Artem)
- [DEV-137] code relocation for more comfortable use (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5792 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r-- | frontends/php/include/config.inc.php | 837 | ||||
-rw-r--r-- | frontends/php/include/db.inc.php | 10 | ||||
-rw-r--r-- | frontends/php/include/events.inc.php | 5 | ||||
-rw-r--r-- | frontends/php/include/func.inc.php | 304 | ||||
-rw-r--r-- | frontends/php/include/graphs.inc.php | 72 | ||||
-rw-r--r-- | frontends/php/include/profiles.inc.php | 64 | ||||
-rw-r--r-- | frontends/php/items.php | 47 | ||||
-rw-r--r-- | frontends/php/tr_status.php | 1 | ||||
-rw-r--r-- | frontends/php/triggers.php | 32 |
9 files changed, 703 insertions, 669 deletions
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index f031b854..01b79851 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -27,6 +27,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! require_once "include/defines.inc.php"; require_once "include/html.inc.php"; require_once "include/copt.lib.php"; + require_once "include/func.inc.php"; require_once "include/profiles.inc.php"; require_once "conf/maintenance.inc.php"; @@ -342,335 +343,6 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! return $default; } - function zbx_strlen(&$str){ - if(!$strlen = strlen($str)) return $strlen; - - $reallen = 0; - $fbin= 1 << 7; - $sbin= 1 << 6; - - // check first byte for 11xxxxxx or 0xxxxxxx - for($i=0; $i < $strlen; $i++){ - if(((ord($str[$i]) & $fbin) && (ord($str[$i]) & $sbin)) || !(ord($str[$i]) & $fbin)) $reallen++; - } - return $reallen; - } - - function zbx_strstr($haystack,$needle){ - $pos = strpos($haystack,$needle); - if($pos !== FALSE){ - $pos = substr($haystack,$pos); - } - return $pos; - } - - function zbx_stristr($haystack,$needle){ - $haystack_B = strtoupper($haystack); - $needle = strtoupper($needle); - - $pos = strpos($haystack_B,$needle); - if($pos !== FALSE){ - $pos = substr($haystack,$pos); - } - return $pos; - } - - function uint_in_array($needle,$haystack){ - foreach($haystack as $id => $value) - if(bccomp($needle,$value) == 0) return true; - return false; - } - - function str_in_array($needle,$haystack,$strict=false){ - if(is_array($needle)){ - return in_array($needle,$haystack,$strict); - } - else if($strict){ - foreach($haystack as $id => $value) - if($needle === $value) return true; - } - else{ - foreach($haystack as $id => $value) - if(strcmp($needle,$value) == 0) return true; - } - return false; - } - - function zbx_stripslashes($value){ - if(is_array($value)){ - foreach($value as $id => $data) - $value[$id] = zbx_stripslashes($data); - // $value = array_map('zbx_stripslashes',$value); /* don't use 'array_map' it buggy with indexes */ - } elseif (is_string($value)){ - $value = stripslashes($value); - } - return $value; - } - - function get_request($name, $def=NULL){ - if(isset($_REQUEST[$name])) - return $_REQUEST[$name]; - else - return $def; - } - - function info($msg){ - global $ZBX_MESSAGES; - - if(is_null($ZBX_MESSAGES)) - $ZBX_MESSAGES = array(); - - array_push($ZBX_MESSAGES, array('type' => 'info', 'message' => $msg)); - } - - function error($msg){ - global $ZBX_MESSAGES; - - if(is_null($ZBX_MESSAGES)) - $ZBX_MESSAGES = array(); - - array_push($ZBX_MESSAGES, array('type' => 'error', 'message' => $msg)); - } - - function clear_messages(){ - global $ZBX_MESSAGES; - - $ZBX_MESSAGES = null; - } - - function asort_by_key(&$array, $key){ - if(!is_array($array)) { - error('Incorrect type of asort_by_key'); - return array(); - } - - $key = htmlspecialchars($key); - uasort($array, create_function('$a,$b', 'return $a[\''.$key.'\'] - $b[\''.$key.'\'];')); - return $array; - } - - function fatal_error($msg){ - include_once "include/page_header.php"; - show_error_message($msg); - include_once "include/page_footer.php"; - } - - function str2mem($val){ - $val = trim($val); - $last = strtolower($val{strlen($val)-1}); - switch($last){ - // The 'G' modifier is available since PHP 5.1.0 - case 'g': - $val *= 1024; - case 'm': - $val *= 1024; - case 'k': - $val *= 1024; - } - - return $val; - } - - function mem2str($size){ - $prefix = 'B'; - if($size > 1048576) { $size = $size/1048576; $prefix = 'M'; } - elseif($size > 1024) { $size = $size/1024; $prefix = 'K'; } - return round($size, 6).$prefix; - } - - function getmicrotime(){ - list($usec, $sec) = explode(" ",microtime()); - return ((float)$usec + (float)$sec); - } - - /* Do not forget to sync it with add_value_suffix in evalfunc.c! */ - function convert_units($value,$units){ -// Special processing for unix timestamps - if($units=="unixtime"){ - $ret=date("Y.m.d H:i:s",$value); - return $ret; - } -//Special processing of uptime - if($units=="uptime"){ - $ret=""; - $days=floor($value/(24*3600)); - if($days>0){ - $value=$value-$days*(24*3600); - } - $hours=floor($value/(3600)); - if($hours>0){ - $value=$value-$hours*3600; - } - $min=floor($value/(60)); - if($min>0){ - $value=$value-$min*(60); - } - if($days==0){ - $ret = sprintf("%02d:%02d:%02d", $hours, $min, $value); - } - else{ - $ret = sprintf("%d days, %02d:%02d:%02d", $days, $hours, $min, $value); - } - return $ret; - } -// Special processing for seconds - if($units=="s"){ - $ret=""; - - $t=floor($value/(365*24*3600)); - if($t>0) - { - $ret=$t."y"; - $value=$value-$t*(365*24*3600); - } - $t=floor($value/(30*24*3600)); - if($t>0) - { - $ret=$ret.$t."m"; - $value=$value-$t*(30*24*3600); - } - $t=floor($value/(24*3600)); - if($t>0) - { - $ret=$ret.$t."d"; - $value=$value-$t*(24*3600); - } - $t=floor($value/(3600)); - if($t>0) - { - $ret=$ret.$t."h"; - $value=$value-$t*(3600); - } - $t=floor($value/(60)); - if($t>0) - { - $ret=$ret.$t."m"; - $value=$value-$t*(60); - } - $ret=$ret.round($value, 2)."s"; - - return $ret; - } - - $u=""; - -// Special processing for bits (kilo=1000, not 1024 for bits) - if( ($units=="b") || ($units=="bps")){ - $abs=abs($value); - - if($abs<1000) - { - $u=""; - } - else if($abs<1000*1000) - { - $u="K"; - $value=$value/1000; - } - else if($abs<1000*1000*1000) - { - $u="M"; - $value=$value/(1000*1000); - } - else - { - $u="G"; - $value=$value/(1000*1000*1000); - } - - if(round($value) == round($value,2)) - { - $s=sprintf("%.0f",$value); - } - else - { - $s=sprintf("%.2f",$value); - } - - return "$s $u$units"; - } - - - if($units==""){ - if(round($value) == round($value,2)) - { - return sprintf("%.0f",$value); - } - else - { - return sprintf("%.2f",$value); - } - } - - $abs=abs($value); - - if($abs<1024){ - $u=""; - } - else if($abs<1024*1024){ - $u="K"; - $value=$value/1024; - } - else if($abs<1024*1024*1024){ - $u="M"; - $value=$value/(1024*1024); - } - else if($abs<1024*1024*1024*1024){ - $u="G"; - $value=$value/(1024*1024*1024); - } - else{ - $u="T"; - $value=$value/(1024*1024*1024*1024); - } - - if(round($value) == round($value,2)){ - $s=sprintf("%.0f",$value); - } - else{ - $s=sprintf("%.2f",$value); - } - - return "$s $u$units"; - } - - -// The hash has form <md5sum of triggerid>,<sum of priorities> - function calc_trigger_hash(){ - - $priority = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0); - $triggerids=""; - - $result=DBselect('select t.triggerid,t.priority from triggers t,hosts h,items i,functions f'. - ' where t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0'); - - while($row=DBfetch($result)){ - $ack = get_last_event_by_triggerid($row["triggerid"]); - if($ack["acknowledged"] == 1) continue; - - $triggerids="$triggerids,".$row["triggerid"]; - $priority[$row["priority"]]++; - } - - $md5sum=md5($triggerids); - - $priorities=0; - for($i=0;$i<=5;$i++) $priorities += pow(100,$i)*$priority[$i]; - - return "$priorities,$md5sum"; - } - - function select_config(){ - $row=DBfetch(DBselect("select * from config where ".DBin_node("configid", get_current_nodeid(false)))); - if($row){ - return $row; - } - else{ - error("Unable to select configuration"); - } - return $row; - } - function show_messages($bool=TRUE,$okmsg=NULL,$errmsg=NULL){ global $page, $ZBX_MESSAGES; @@ -818,6 +490,61 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! show_messages(FALSE,'',$msg); } + function info($msg){ + global $ZBX_MESSAGES; + + if(is_null($ZBX_MESSAGES)) + $ZBX_MESSAGES = array(); + + array_push($ZBX_MESSAGES, array('type' => 'info', 'message' => $msg)); + } + + function error($msg){ + global $ZBX_MESSAGES; + + if(is_null($ZBX_MESSAGES)) + $ZBX_MESSAGES = array(); + + array_push($ZBX_MESSAGES, array('type' => 'error', 'message' => $msg)); + } + + function clear_messages(){ + global $ZBX_MESSAGES; + + $ZBX_MESSAGES = null; + } + + function fatal_error($msg){ + include_once "include/page_header.php"; + show_error_message($msg); + include_once "include/page_footer.php"; + } + +// The hash has form <md5sum of triggerid>,<sum of priorities> + function calc_trigger_hash(){ + + $priority = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0); + $triggerids=""; + + $result=DBselect('select t.triggerid,t.priority from triggers t,hosts h,items i,functions f'. + ' where t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0'); + + while($row=DBfetch($result)){ + $ack = get_last_event_by_triggerid($row["triggerid"]); + if($ack["acknowledged"] == 1) continue; + + $triggerids="$triggerids,".$row["triggerid"]; + $priority[$row["priority"]]++; + } + + $md5sum=md5($triggerids); + + $priorities=0; + for($i=0;$i<=5;$i++) $priorities += pow(100,$i)*$priority[$i]; + + return "$priorities,$md5sum"; + } + function parse_period($str){ $out = NULL; $str = trim($str,';'); @@ -825,8 +552,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! foreach($periods as $preiod){ if(!ereg('^([1-7])-([1-7]),([0-9]{1,2}):([0-9]{1,2})-([0-9]{1,2}):([0-9]{1,2})$', $preiod, $arr)) return NULL; - for($i = $arr[1]; $i <= $arr[2]; $i++) - { + for($i = $arr[1]; $i <= $arr[2]; $i++){ if(!isset($out[$i])) $out[$i] = array(); array_push($out[$i], array( @@ -848,8 +574,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! if(isset($periods[$wday])){ $next_h = -1; $next_m = -1; - foreach($periods[$wday] as $period) - { + foreach($periods[$wday] as $period){ $per_start = $period['start_h']*100+$period['start_m']; if($per_start > $curr) { @@ -864,15 +589,13 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! if($per_end <= $curr) continue; return $time; } - if($next_h >= 0 && $next_m >= 0) - { + if($next_h >= 0 && $next_m >= 0){ return mktime($next_h, $next_m, 0, $date['mon'], $date['mday'], $date['year']); } } for($days=1; $days < 7 ; ++$days){ $new_wday = (($wday + $days - 1)%7 + 1); - if(isset($periods[$new_wday ])) - { + if(isset($periods[$new_wday ])){ $next_h = -1; $next_m = -1; foreach($periods[$new_wday] as $period) @@ -901,8 +624,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! if(isset($periods[$wday])){ $next_h = -1; $next_m = -1; - foreach($periods[$wday] as $period) - { + foreach($periods[$wday] as $period){ $per_start = $period['start_h']*100+$period['start_m']; $per_end = $period['end_h']*100+$period['end_m']; if($per_start > $curr) continue; @@ -914,8 +636,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! $next_m = $period['end_m']; } } - if($next_h >= 0 && $next_m >= 0) - { + if($next_h >= 0 && $next_m >= 0){ $new_time = mktime($next_h, $next_m, 0, $date['mon'], $date['mday'], $date['year']); if($new_time == $time) @@ -979,13 +700,6 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! else return validate_float($str); } - # Add event - - function get_event_by_eventid($eventid){ - $db_events = DBselect("select * from events where eventid=$eventid"); - return DBfetch($db_events); - } - /****************************************************************************** * * @@ -1003,65 +717,6 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! } } - # Update configuration - - function update_config($configs){ - $update = array(); - - if(isset($configs['work_period']) && !is_null($configs['work_period'])){ - if(!validate_period($configs['work_period'])){ - error(S_ICORRECT_WORK_PERIOD); - return NULL; - } - } - if(isset($configs['alert_usrgrpid']) && !is_null($configs['alert_usrgrpid'])){ - if(($configs['alert_usrgrpid'] != 0) && !DBfetch(DBselect('select usrgrpid from usrgrp where usrgrpid='.$configs['alert_usrgrpid']))){ - error(S_INCORRECT_GROUP);; - return NULL; - } - } - - foreach($configs as $key => $value){ - if(!is_null($value)) - $update[] = $key.'='.zbx_dbstr($value); - } - - if(count($update) == 0){ - error(S_NOTHING_TO_DO); - return NULL; - } - - return DBexecute('update config set '.implode(',',$update).' where '.DBin_node('configid', get_current_nodeid(false))); - } - - # Show History Graph - function show_history($itemid,$from,$stime,$period){ - $till=date(S_DATE_FORMAT_YMDHMS,time(NULL)-$from*3600); - - show_table_header(S_TILL.SPACE.$till.' ( '.zbx_date2age($stime,$stime+$period).' )'); - - $td = new CCol(get_js_sizeable_graph('graph','chart.php?itemid='.$itemid. - url_param($from,false,'from'). - url_param($stime,false,'stime'). - url_param($period,false,'period'))); - $td->AddOption('align','center'); - - $tr = new CRow($td); - $tr->AddOption('bgcolor','#dddddd'); - - $table = new CTable(); - $table->AddOption('width','100%'); - $table->AddOption('bgcolor','#cccccc'); - $table->AddOption('cellspacing','1'); - $table->AddOption('cellpadding','3'); - - $table->AddRow($tr); - - $table->Show(); - echo SBR; - } - - function get_status(){ // global $DB; $status = array(); @@ -1240,8 +895,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! if($user=get_sysmap_by_sysmapid($id)) $res=$user["name"]; } - else if(!isset($id) || $id == 0) - { + else if(!isset($id) || $id == 0){ $res="All maps"; } } @@ -1270,17 +924,6 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! return $res; } - function zbx_empty($var){ - if(is_null($var)) return true; - if(is_array($var) && empty($var)) return true; - if(is_string($var) && ($var === '')) return true; - return false; - } - - function empty2null($var){ - return ($var == "") ? null : $var; - } - /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ if(function_exists("imagesetstyle")){ function DashedLine($image,$x1,$y1,$x2,$y2,$color){ @@ -1306,6 +949,42 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! } + function set_image_header($format=null){ + global $IMAGE_FORMAT_DEFAULT; + + if(is_null($format)) $format = $IMAGE_FORMAT_DEFAULT; + + if(IMAGE_FORMAT_JPEG == $format) Header( "Content-type: image/jpeg"); + if(IMAGE_FORMAT_TEXT == $format) Header( "Content-type: text/html"); + else Header( "Content-type: image/png"); + + Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); + } + + function ImageOut($image,$format=NULL){ + global $IMAGE_FORMAT_DEFAULT; + + if(is_null($format)) $format = $IMAGE_FORMAT_DEFAULT; + + if(IMAGE_FORMAT_JPEG == $format) + ImageJPEG($image); + else + ImagePNG($image); + + imagedestroy($image); + } + + function encode_log($data){ + if(defined('ZBX_LOG_ENCODING_DEFAULT') && function_exists('mb_convert_encoding')){ + $new=mb_convert_encoding($data, S_HTML_CHARSET, ZBX_LOG_ENCODING_DEFAULT); + } + else{ + $new = $data; + } + return $new; + } + +/*************** VALUE MAPPING ******************/ function add_mapping_to_valuemap($valuemapid, $mappings){ DBexecute("delete from mappings where valuemapid=$valuemapid"); @@ -1374,209 +1053,177 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! } return $value; } +/*************** END VALUE MAPPING ******************/ - function natksort(&$array) { - $keys = array_keys($array); - natcasesort($keys); +/*************** CONVERTING ******************/ - $new_array = array(); - - foreach ($keys as $k) { - $new_array[$k] = $array[$k]; - } - - $array = $new_array; - return true; - } - - function set_image_header($format=null){ - global $IMAGE_FORMAT_DEFAULT; - - if(is_null($format)) $format = $IMAGE_FORMAT_DEFAULT; - - if(IMAGE_FORMAT_JPEG == $format) Header( "Content-type: image/jpeg"); - if(IMAGE_FORMAT_TEXT == $format) Header( "Content-type: text/html"); - else Header( "Content-type: image/png"); - - Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); + function empty2null($var){ + return ($var == "") ? null : $var; } - function ImageOut($image,$format=NULL){ - global $IMAGE_FORMAT_DEFAULT; - - if(is_null($format)) $format = $IMAGE_FORMAT_DEFAULT; - - if(IMAGE_FORMAT_JPEG == $format) - ImageJPEG($image); - else - ImagePNG($image); - - imagedestroy($image); - } - - /* function: - * get_cookie - * - * description: - * return cookie value by name, - * if cookie is not present return $default_value. - * - * author: Eugene Grigorjev - */ - function get_cookie($name, $default_value=null){ - if(isset($_COOKIE[$name])) return $_COOKIE[$name]; - // else - return $default_value; - } + function str2mem($val){ + $val = trim($val); + $last = strtolower($val{strlen($val)-1}); + switch($last){ + // The 'G' modifier is available since PHP 5.1.0 + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } - /* function: - * zbx_setcookie - * - * description: - * set cookies. - * - * author: Eugene Grigorjev - */ - function zbx_setcookie($name, $value, $time=null){ - setcookie($name, $value, isset($time) ? $time : (0)); - $_COOKIE[$name] = $value; + return $val; } - /* function: - * zbx_unsetcookie - * - * description: - * unset and clear cookies. - * - * author: Aly - */ - function zbx_unsetcookie($name){ - zbx_setcookie($name, null, -99999); - unset($_COOKIE[$name]); + function mem2str($size){ + $prefix = 'B'; + if($size > 1048576) { $size = $size/1048576; $prefix = 'M'; } + elseif($size > 1024) { $size = $size/1024; $prefix = 'K'; } + return round($size, 6).$prefix; } - - /* function: - * zbx_flush_post_cookies - * - * description: - * set posted cookies. - * - * author: Eugene Grigorjev - */ - function zbx_flush_post_cookies($unset=false){ - global $ZBX_PAGE_COOKIES; - if(isset($ZBX_PAGE_COOKIES)){ - foreach($ZBX_PAGE_COOKIES as $cookie){ - if($unset) - zbx_unsetcookie($cookie[0]); - else - zbx_setcookie($cookie[0], $cookie[1], $cookie[2]); + /* Do not forget to sync it with add_value_suffix in evalfunc.c! */ + function convert_units($value,$units){ +// Special processing for unix timestamps + if($units=="unixtime"){ + $ret=date("Y.m.d H:i:s",$value); + return $ret; + } +//Special processing of uptime + if($units=="uptime"){ + $ret=""; + $days=floor($value/(24*3600)); + if($days>0){ + $value=$value-$days*(24*3600); } - unset($ZBX_PAGE_COOKIES); + $hours=floor($value/(3600)); + if($hours>0){ + $value=$value-$hours*3600; + } + $min=floor($value/(60)); + if($min>0){ + $value=$value-$min*(60); + } + if($days==0){ + $ret = sprintf("%02d:%02d:%02d", $hours, $min, $value); + } + else{ + $ret = sprintf("%d days, %02d:%02d:%02d", $days, $hours, $min, $value); + } + return $ret; } - } +// Special processing for seconds + if($units=="s"){ + $ret=""; - /* function: - * zbx_set_post_cookie - * - * description: - * set cookies after authorisation. - * require calling 'zbx_flush_post_cookies' function - * Called from: - * a) in 'include/page_header.php' - * b) from 'redirect()' - * - * author: Eugene Grigorjev - */ - function zbx_set_post_cookie($name, $value, $time=null){ - global $ZBX_PAGE_COOKIES; + $t=floor($value/(365*24*3600)); + if($t>0){ + $ret=$t."y"; + $value=$value-$t*(365*24*3600); + } + $t=floor($value/(30*24*3600)); + if($t>0){ + $ret=$ret.$t."m"; + $value=$value-$t*(30*24*3600); + } + $t=floor($value/(24*3600)); + if($t>0){ + $ret=$ret.$t."d"; + $value=$value-$t*(24*3600); + } + $t=floor($value/(3600)); + if($t>0){ + $ret=$ret.$t."h"; + $value=$value-$t*(3600); + } + $t=floor($value/(60)); + if($t>0){ + $ret=$ret.$t."m"; + $value=$value-$t*(60); + } + $ret=$ret.round($value, 2)."s"; + + return $ret; + } - $ZBX_PAGE_COOKIES[] = array($name, $value, isset($time) ? $time : (0)); - } + $u=""; - function inarr_isset($keys, $array=null){ - if(is_null($array)) $array =& $_REQUEST; +// Special processing for bits (kilo=1000, not 1024 for bits) + if( ($units=="b") || ($units=="bps")){ + $abs=abs($value); - if(is_array($keys)){ - foreach($keys as $id => $key){ - if( !isset($array[$key]) ) - return false; + if($abs<1000){ + $u=""; + } + else if($abs<1000*1000){ + $u="K"; + $value=$value/1000; + } + else if($abs<1000*1000*1000){ + $u="M"; + $value=$value/(1000*1000); + } + else{ + $u="G"; + $value=$value/(1000*1000*1000); + } + + if(round($value) == round($value,2)){ + $s=sprintf("%.0f",$value); + } + else{ + $s=sprintf("%.2f",$value); } - return true; - } - return isset($array[$keys]); - } + return "$s $u$units"; + } - /* function: - * zbx_rksort - * - * description: - * Recursively sort an array by key - * - * author: Eugene Grigorjev - */ - function zbx_rksort(&$array, $flags=NULL){ - if(is_array($array)){ - foreach($array as $id => $data) - zbx_rksort($array[$id]); - ksort($array,$flags); + if($units==""){ + if(round($value) == round($value,2)){ + return sprintf("%.0f",$value); + } + else{ + return sprintf("%.2f",$value); + } } - return $array; - } - /* function: - * zbx_date2str - * - * description: - * Convert timestamp to string representation. Retun 'Never' if 0. - * - * author: Alexei Vladishev - */ - function zbx_date2str($format, $timestamp){ - return ($timestamp==0)?S_NEVER:date($format,$timestamp); - } - - /* function: - * zbx_date2age - * - * description: - * Calculate and convert timestamp to string representation. - * - * author: Aly - */ - function zbx_date2age($start_date,$end_date=0){ - - $start_date=date('U',$start_date); - if($end_date) - $end_date=date('U',$end_date); - else - $end_date = time(); + $abs=abs($value); - $time = abs($end_date-$start_date); - -//SDI($start_date.' - '.$end_date.' = '.$time); - - $days = (int) ($time / 86400); - $hours = (int) (($time - $days*86400) / 3600); - $minutes = (int) ((($time - $days*86400) - ($hours*3600)) / 60); - $str = (($days)?$days.'d ':'').(($hours)?$hours.'h ':'').$minutes.'m'; - return $str; - } + if($abs<1024){ + $u=""; + } + else if($abs<1024*1024){ + $u="K"; + $value=$value/1024; + } + else if($abs<1024*1024*1024){ + $u="M"; + $value=$value/(1024*1024); + } + else if($abs<1024*1024*1024*1024){ + $u="G"; + $value=$value/(1024*1024*1024); + } + else{ + $u="T"; + $value=$value/(1024*1024*1024*1024); + } - function encode_log($data){ - if(defined('ZBX_LOG_ENCODING_DEFAULT') && function_exists('mb_convert_encoding')){ - $new=mb_convert_encoding($data, S_HTML_CHARSET, ZBX_LOG_ENCODING_DEFAULT); + if(round($value) == round($value,2)){ + $s=sprintf("%.0f",$value); } else{ - $new = $data; + $s=sprintf("%.2f",$value); } - return $new; + + return "$s $u$units"; } +/*************** END CONVERTING ******************/ - +/*************** TABLE SORTING ******************/ /* function: * validate_sort_and_sortorder * diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php index 31f018c3..f4198945 100644 --- a/frontends/php/include/db.inc.php +++ b/frontends/php/include/db.inc.php @@ -364,7 +364,7 @@ if(!isset($DB)){ if( isset($DB['DB']) && !empty($DB['DB']) ) switch($DB['TYPE']){ case "MYSQL": - if(is_numeric($limit)){ + if(zbx_numeric($limit)){ $query .= ' limit '.intval($limit); } $result=mysql_query($query,$DB['DB']); @@ -373,7 +373,7 @@ if(!isset($DB)){ } break; case "POSTGRESQL": - if(is_numeric($limit)){ + if(zbx_numeric($limit)){ $query .= ' limit '.intval($limit); } $result = pg_query($DB['DB'],$query); @@ -382,7 +382,7 @@ if(!isset($DB)){ } break; case "ORACLE": - if(is_numeric($limit)){ + if(zbx_numeric($limit)){ $query = 'select * from ('.$query.') where rownum<='.intval($limit); } $result = DBexecute($query); @@ -632,7 +632,7 @@ else { if ( !eregi('([0-9\,]+)', $nodes ) ) fatal_error('Incorrect "nodes" for "DBin_node". Passed ['.$nodes.']'); } - else if(!is_numeric($nodes)){ + else if(!zbx_numeric($nodes)){ fatal_error('Incorrect type of "nodes" for "DBin_node". Passed ['.gettype($nodes).']'); } return (' '.DBid2nodeid($id_name).' in ('.$nodes.') '); @@ -645,7 +645,7 @@ else { if(empty($nodes)) $nodes = 0; - if(is_numeric($nodes)){ + if(zbx_numeric($nodes)){ $nodes = array($nodes); } else if(is_string($nodes)){ diff --git a/frontends/php/include/events.inc.php b/frontends/php/include/events.inc.php index ce85022b..c903935c 100644 --- a/frontends/php/include/events.inc.php +++ b/frontends/php/include/events.inc.php @@ -27,6 +27,11 @@ } } + function get_event_by_eventid($eventid){ + $db_events = DBselect("select * from events where eventid=$eventid"); + return DBfetch($db_events); + } + function get_tr_event_by_eventid($eventid){ $result = DBfetch(DBselect('SELECT e.*,t.triggerid, t.description,t.priority,t.status,t.type '. ' FROM events e,triggers t '. diff --git a/frontends/php/include/func.inc.php b/frontends/php/include/func.inc.php new file mode 100644 index 00000000..d3599abe --- /dev/null +++ b/frontends/php/include/func.inc.php @@ -0,0 +1,304 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php +/************ REQUEST ************/ +function get_request($name, $def=NULL){ + if(isset($_REQUEST[$name])) + return $_REQUEST[$name]; + else + return $def; +} + + +function inarr_isset($keys, $array=null){ + if(is_null($array)) $array =& $_REQUEST; + + if(is_array($keys)){ + foreach($keys as $id => $key){ + if( !isset($array[$key]) ) + return false; + } + return true; + } + + return isset($array[$keys]); +} +/************ END REQUEST ************/ + +/************ COOKIES ************/ +/* function: + * get_cookie + * + * description: + * return cookie value by name, + * if cookie is not present return $default_value. + * + * author: Eugene Grigorjev + */ +function get_cookie($name, $default_value=null){ + if(isset($_COOKIE[$name])) return $_COOKIE[$name]; + // else + return $default_value; +} + +/* function: + * zbx_setcookie + * + * description: + * set cookies. + * + * author: Eugene Grigorjev + */ +function zbx_setcookie($name, $value, $time=null){ + setcookie($name, $value, isset($time) ? $time : (0)); + $_COOKIE[$name] = $value; +} + +/* function: + * zbx_unsetcookie + * + * description: + * unset and clear cookies. + * + * author: Aly + */ +function zbx_unsetcookie($name){ + zbx_setcookie($name, null, -99999); + unset($_COOKIE[$name]); +} + +/* function: + * zbx_flush_post_cookies + * + * description: + * set posted cookies. + * + * author: Eugene Grigorjev + */ +function zbx_flush_post_cookies($unset=false){ + global $ZBX_PAGE_COOKIES; + + if(isset($ZBX_PAGE_COOKIES)){ + foreach($ZBX_PAGE_COOKIES as $cookie){ + if($unset) + zbx_unsetcookie($cookie[0]); + else + zbx_setcookie($cookie[0], $cookie[1], $cookie[2]); + } + unset($ZBX_PAGE_COOKIES); + } +} + +/* function: + * zbx_set_post_cookie + * + * description: + * set cookies after authorisation. + * require calling 'zbx_flush_post_cookies' function + * Called from: + * a) in 'include/page_header.php' + * b) from 'redirect()' + * + * author: Eugene Grigorjev + */ +function zbx_set_post_cookie($name, $value, $time=null){ + global $ZBX_PAGE_COOKIES; + + $ZBX_PAGE_COOKIES[] = array($name, $value, isset($time) ? $time : (0)); +} + +/************ END COOKIES ************/ + +/************* DATE *************/ +/* function: + * zbx_date2str + * + * description: + * Convert timestamp to string representation. Retun 'Never' if 0. + * + * author: Alexei Vladishev + */ +function zbx_date2str($format, $timestamp){ + return ($timestamp==0)?S_NEVER:date($format,$timestamp); +} + +/* function: + * zbx_date2age + * + * description: + * Calculate and convert timestamp to string representation. + * + * author: Aly + */ +function zbx_date2age($start_date,$end_date=0){ + + $start_date=date('U',$start_date); + if($end_date) + $end_date=date('U',$end_date); + else + $end_date = time(); + + $time = abs($end_date-$start_date); + +//SDI($start_date.' - '.$end_date.' = '.$time); + + $days = (int) ($time / 86400); + $hours = (int) (($time - $days*86400) / 3600); + $minutes = (int) ((($time - $days*86400) - ($hours*3600)) / 60); + $str = (($days)?$days.'d ':'').(($hours)?$hours.'h ':'').$minutes.'m'; +return $str; +} + +function getmicrotime(){ + list($usec, $sec) = explode(" ",microtime()); + return ((float)$usec + (float)$sec); +} + +/************* END DATE *************/ + + +/************* SORT *************/ +function natksort(&$array) { + $keys = array_keys($array); + natcasesort($keys); + + $new_array = array(); + + foreach ($keys as $k) { + $new_array[$k] = $array[$k]; + } + + $array = $new_array; + return true; +} + +function asort_by_key(&$array, $key){ + if(!is_array($array)) { + error('Incorrect type of asort_by_key'); + return array(); + } + + $key = htmlspecialchars($key); + uasort($array, create_function('$a,$b', 'return $a[\''.$key.'\'] - $b[\''.$key.'\'];')); +return $array; +} + + +/* function: + * zbx_rksort + * + * description: + * Recursively sort an array by key + * + * author: Eugene Grigorjev + */ +function zbx_rksort(&$array, $flags=NULL){ + if(is_array($array)){ + foreach($array as $id => $data) + zbx_rksort($array[$id]); + + ksort($array,$flags); + } + return $array; +} + +/************* END SORT *************/ + +/************* ZBX MISC *************/ +function zbx_numeric($value){ + if(is_array($value)) return false; + + $value = strval($value); +return ctype_digit($value); +} + +function zbx_empty($value){ + if(is_null($value)) return true; + if(is_array($value) && empty($value)) return true; + if(is_string($value) && ($value === '')) return true; +return false; +} + +function zbx_strlen(&$str){ + if(!$strlen = strlen($str)) return $strlen; + + $reallen = 0; + $fbin= 1 << 7; + $sbin= 1 << 6; + +// check first byte for 11xxxxxx or 0xxxxxxx + for($i=0; $i < $strlen; $i++){ + if(((ord($str[$i]) & $fbin) && (ord($str[$i]) & $sbin)) || !(ord($str[$i]) & $fbin)) $reallen++; + } +return $reallen; +} + +function zbx_strstr($haystack,$needle){ + $pos = strpos($haystack,$needle); + if($pos !== FALSE){ + $pos = substr($haystack,$pos); + } +return $pos; +} + +function zbx_stristr($haystack,$needle){ + $haystack_B = strtoupper($haystack); + $needle = strtoupper($needle); + + $pos = strpos($haystack_B,$needle); + if($pos !== FALSE){ + $pos = substr($haystack,$pos); + } +return $pos; +} + +function uint_in_array($needle,$haystack){ + foreach($haystack as $id => $value) + if(bccomp($needle,$value) == 0) return true; +return false; +} + +function str_in_array($needle,$haystack,$strict=false){ + if(is_array($needle)){ + return in_array($needle,$haystack,$strict); + } + else if($strict){ + foreach($haystack as $id => $value) + if($needle === $value) return true; + } + else{ + foreach($haystack as $id => $value) + if(strcmp($needle,$value) == 0) return true; + } +return false; +} + +function zbx_stripslashes($value){ + if(is_array($value)){ + foreach($value as $id => $data) + $value[$id] = zbx_stripslashes($data); + // $value = array_map('zbx_stripslashes',$value); /* don't use 'array_map' it buggy with indexes */ + } elseif (is_string($value)){ + $value = stripslashes($value); + } + return $value; +} +?>
\ No newline at end of file diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index 1c4d35b4..b6b64fd9 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -29,7 +29,7 @@ * Eugene Grigorjev * */ - function graph_item_type2str($type,$count=null){ + function graph_item_type2str($type,$count=null){ switch($type){ case GRAPH_ITEM_SUM: $type = S_GRAPH_SUM; @@ -42,7 +42,7 @@ $type = S_SIMPLE; break; } - return $type; + return $type; } /* @@ -55,7 +55,7 @@ * Eugene Grigorjev * */ - function graph_item_drawtypes(){ + function graph_item_drawtypes(){ return array( GRAPH_ITEM_DRAWTYPE_LINE, GRAPH_ITEM_DRAWTYPE_FILLED_REGION, @@ -75,7 +75,7 @@ * Eugene Grigorjev * */ - function graph_item_drawtype2str($drawtype,$type=null){ + function graph_item_drawtype2str($drawtype,$type=null){ if($type == GRAPH_ITEM_AGGREGATED) return '-'; switch($drawtype){ @@ -99,7 +99,7 @@ * Eugene Grigorjev * */ - function graph_item_calc_fnc2str($calc_fnc, $type=null){ + function graph_item_calc_fnc2str($calc_fnc, $type=null){ if($type == GRAPH_ITEM_AGGREGATED) return '-'; switch($calc_fnc){ @@ -258,17 +258,17 @@ return 0; } - /* - * Function: get_min_itemclock_by_itemid - * - * Description: - * Return the time of the 1st apearance of item in trends - * - * Author: - * Aly - * - */ - function get_min_itemclock_by_itemid($itemid){ +/* + * Function: get_min_itemclock_by_itemid + * + * Description: + * Return the time of the 1st apearance of item in trends + * + * Author: + * Aly + * + */ + function get_min_itemclock_by_itemid($itemid){ $row = DBfetch(DBselect('SELECT MIN(t.clock) as clock '. ' FROM trends t '. ' WHERE t.itemid='.$itemid)); @@ -277,9 +277,35 @@ return $row['clock']; return 0; } + +// Show History Graph + function show_history($itemid,$from,$stime,$period){ + $till=date(S_DATE_FORMAT_YMDHMS,time(NULL)-$from*3600); + + show_table_header(S_TILL.SPACE.$till.' ( '.zbx_date2age($stime,$stime+$period).' )'); - function get_graphitem_by_gitemid($gitemid) - { + $td = new CCol(get_js_sizeable_graph('graph','chart.php?itemid='.$itemid. + url_param($from,false,'from'). + url_param($stime,false,'stime'). + url_param($period,false,'period'))); + $td->AddOption('align','center'); + + $tr = new CRow($td); + $tr->AddOption('bgcolor','#dddddd'); + + $table = new CTable(); + $table->AddOption('width','100%'); + $table->AddOption('bgcolor','#cccccc'); + $table->AddOption('cellspacing','1'); + $table->AddOption('cellpadding','3'); + + $table->AddRow($tr); + + $table->Show(); + echo SBR; + } + + function get_graphitem_by_gitemid($gitemid){ $result=DBselect("SELECT * FROM graphs_items WHERE gitemid=$gitemid"); $row=DBfetch($result); if($row){ @@ -579,8 +605,7 @@ DBexecute('delete from graphs_items where graphid='.$graphid); - foreach($gitems as $gitem) - { + foreach($gitems as $gitem){ if ( ! ($result = add_item_to_graph( $graphid, $gitem['itemid'], @@ -596,13 +621,12 @@ } } - if ( ($result = update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod, - $showtriggers,$graphtype,$legend,$graph3d,$templateid)) ) + if ($result = update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod, + $showtriggers,$graphtype,$legend,$graph3d,$templateid)) { $host_list = array(); $db_hosts = get_hosts_by_graphid($graphid); - while($db_host = DBfetch($db_hosts)) - { + while($db_host = DBfetch($db_hosts)){ $host_list[] = '"'.$db_host["host"].'"'; } diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php index 1e7bb474..b062b461 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(is_numeric($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); + if(zbx_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(is_numeric($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); + if(zbx_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(is_numeric($idx2)) $sql_cond = ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); + if(zbx_numeric($idx2)) $sql_cond = ' AND idx2='.$idx2.' AND '.DBin_node('idx2'); DBstart(); if(profile_type($type,'array')){ @@ -125,7 +125,7 @@ function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN,$idx2=null,$sourc ' WHERE userid='.$USER_DETAILS["userid"]. ' AND idx='.zbx_dbstr($idx). $sql_cond; - + DBexecute($sql); foreach($value as $id => $val){ insert_profile($idx,$val,$type,$idx2,$source); @@ -153,7 +153,7 @@ function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN,$idx2=null,$sourc $val[$value_type] = $value; - $idx2 = is_numeric($idx2)?$idx2:0; + $idx2 = zbx_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 = is_numeric($idx2)?$idx2:0; + $idx2 = zbx_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=is_numeric($value['value'])?PROFILE_TYPE_ARRAY_ID:PROFILE_TYPE_ARRAY_STR; + $type=zbx_numeric($value['value'])?PROFILE_TYPE_ARRAY_ID:PROFILE_TYPE_ARRAY_STR; } else{ - $type=is_numeric($value)?PROFILE_TYPE_ARRAY_ID:PROFILE_TYPE_ARRAY_STR; + $type=zbx_numeric($value)?PROFILE_TYPE_ARRAY_ID:PROFILE_TYPE_ARRAY_STR; } } else{ - if(is_numeric($value)) $type = PROFILE_TYPE_ID; + if(zbx_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(is_numeric($value['value'])){ + if(zbx_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 = is_numeric($value)?intval($value):false; + $result = zbx_numeric($value)?intval($value):false; break; case PROFILE_TYPE_STR: $result = strval($value); @@ -328,6 +328,48 @@ return $result; /********** END MISC ***********/ +/************ CONFIG **************/ + +function select_config(){ + $row=DBfetch(DBselect("select * from config where ".DBin_node("configid", get_current_nodeid(false)))); + if($row){ + return $row; + } + else{ + error("Unable to select configuration"); + } + return $row; +} + +function update_config($configs){ + $update = array(); + + if(isset($configs['work_period']) && !is_null($configs['work_period'])){ + if(!validate_period($configs['work_period'])){ + error(S_ICORRECT_WORK_PERIOD); + return NULL; + } + } + if(isset($configs['alert_usrgrpid']) && !is_null($configs['alert_usrgrpid'])){ + if(($configs['alert_usrgrpid'] != 0) && !DBfetch(DBselect('select usrgrpid from usrgrp where usrgrpid='.$configs['alert_usrgrpid']))){ + error(S_INCORRECT_GROUP);; + return NULL; + } + } + + foreach($configs as $key => $value){ + if(!is_null($value)) + $update[] = $key.'='.zbx_dbstr($value); + } + + if(count($update) == 0){ + error(S_NOTHING_TO_DO); + return NULL; + } + +return DBexecute('update config set '.implode(',',$update).' where '.DBin_node('configid', get_current_nodeid(false))); +} +/************ END CONFIG **************/ /************ HISTORY **************/ // Author: Aly diff --git a/frontends/php/items.php b/frontends/php/items.php index b63c3920..8d23745b 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -421,11 +421,11 @@ include_once "include/page_header.php"; if("0" === get_request("formula",null)) $_REQUEST['multiplier']=0; $group_itemid = $_REQUEST["group_itemid"]; - $result = true; + $result = false; DBstart(); foreach($group_itemid as $id){ - $result &= smart_update_item($id, + $result |= smart_update_item($id, null,null,null,get_request("delay"), get_request("history"),get_request("status"),get_request("type"), get_request("snmp_community"),get_request("snmp_oid"),get_request("value_type"), @@ -435,7 +435,7 @@ include_once "include/page_header.php"; get_request("snmpv3_privpassphrase"),get_request("formula"),get_request("trends"), get_request("logtimefmt"),get_request("valuemapid"),$db_delay_flex,null,$applications); } - $result = DBend($result && !empty($group_itemid)); + $result = DBend($result); show_messages($result, S_ITEMS_UPDATED); unset($_REQUEST["group_itemid"], $_REQUEST["form_mass_update"], $_REQUEST["update"]); @@ -561,7 +561,7 @@ include_once "include/page_header.php"; } else if(isset($_REQUEST["group_task"])&&isset($_REQUEST["group_itemid"])){ if($_REQUEST["group_task"]==S_DELETE_SELECTED){ - $result = true; + $result = false; $group_itemid = $_REQUEST["group_itemid"]; DBstart(); @@ -569,15 +569,16 @@ include_once "include/page_header.php"; if(!$item = get_item_by_itemid($id)) continue; if($item["templateid"]<>0) continue; - $result &= delete_item($id); - - if($result){ + $cur_result = delete_item($id); + $result |= $cur_result; + + if($cur_result){ $host = get_host_by_hostid($item["hostid"]); add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_ITEM,S_ITEM." [".$item["key_"]."] [".$id."] ".S_HOST." [".$host['host']."]"); } } - $result = DBend($result && !empty($group_itemid)); + $result = DBend($result); show_messages($result, S_ITEMS_DELETED, null); } else if($_REQUEST["group_task"]==S_ACTIVATE_SELECTED){ @@ -588,12 +589,16 @@ include_once "include/page_header.php"; foreach($group_itemid as $id){ if(!$item = get_item_by_itemid($id)) continue; - if(activate_item($id)){ - $result = true; + $cur_result = activate_item($id); + $result |= $cur_result; + + if($cur_result){ $host = get_host_by_hostid($item["hostid"]); add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM,S_ITEM." [".$item["key_"]."] [".$id."] ".S_HOST." [".$host['host']."] ".S_ITEMS_ACTIVATED); } } + + $result = DBend($result); show_messages($result, S_ITEMS_ACTIVATED, null); } else if($_REQUEST["group_task"]==S_DISABLE_SELECTED){ @@ -602,29 +607,31 @@ include_once "include/page_header.php"; DBstart(); foreach($group_itemid as $id){ - if(!($item = get_item_by_itemid($id))) continue; + if(!$item = get_item_by_itemid($id)) continue; - if(disable_item($id)){ - $result = true; - + $cur_result = disable_item($id); + $result |= $cur_result; + + if($cur_result){ $host = get_host_by_hostid($item["hostid"]); add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, S_ITEM." [".$item["key_"]."] [".$id."] ".S_HOST." [".$host['host']."] ".S_ITEMS_DISABLED); } } - $result = DBend($result && !empty($group_itemid)); + $result = DBend($result); show_messages($result, S_ITEMS_DISABLED, null); } else if($_REQUEST["group_task"]==S_CLEAN_HISTORY_SELECTED_ITEMS){ - $result = true; + $result = false; $group_itemid = $_REQUEST["group_itemid"]; DBstart(); foreach($group_itemid as $id){ if(!$item = get_item_by_itemid($id)) continue; - - $result &= delete_history_by_itemid($id); - if($result){ + $cur_result = delete_history_by_itemid($id); + $result |= $cur_result; + + if($cur_result){ DBexecute("update items set nextcheck=0,lastvalue=null,lastclock=null,prevvalue=null where itemid=$id"); $host = get_host_by_hostid($item["hostid"]); @@ -632,7 +639,7 @@ include_once "include/page_header.php"; S_ITEM." [".$item["key_"]."] [".$id."] ".S_HOST." [".$host['host']."] ".S_HISTORY_CLEANED); } } - $result = DBend($result && !empty($group_itemid)); + $result = DBend($result); show_messages($result, S_HISTORY_CLEANED, $result); } } diff --git a/frontends/php/tr_status.php b/frontends/php/tr_status.php index e1e4a391..95a07f88 100644 --- a/frontends/php/tr_status.php +++ b/frontends/php/tr_status.php @@ -250,7 +250,6 @@ include_once "include/page_header.php"; show_table_header($text,$r_form); - if(!$_REQUEST["fullscreen"]){ $left_col = array(); diff --git a/frontends/php/triggers.php b/frontends/php/triggers.php index 703323b7..37ad4df6 100644 --- a/frontends/php/triggers.php +++ b/frontends/php/triggers.php @@ -201,11 +201,11 @@ include_once "include/page_header.php"; array_push($hosts_ids, $db_host['hostid']); } } - $result = true; + $result = false; DBstart(); foreach($_REQUEST['g_triggerid'] as $trigger_id) foreach($hosts_ids as $host_id){ - $result &= copy_trigger_to_host($trigger_id, $host_id, true); + $result |= copy_trigger_to_host($trigger_id, $host_id, true); } $result = DBend($result); unset($_REQUEST['form_copy_to']); @@ -233,7 +233,7 @@ include_once "include/page_header.php"; } /* GROUP ACTIONS */ else if(isset($_REQUEST["group_enable"])&&isset($_REQUEST["g_triggerid"])){ - $result = true; + $result = false; DBstart(); foreach($_REQUEST["g_triggerid"] as $triggerid){ @@ -242,8 +242,10 @@ include_once "include/page_header.php"; $res = DBselect('SELECT triggerid FROM triggers t WHERE t.triggerid='.zbx_dbstr($triggerid)); if(!$row = DBfetch($res)) continue; - if($result &= update_trigger_status($row['triggerid'],0)){ - + $cur_result = update_trigger_status($row['triggerid'],0); + $result |= $cur_result; + + if($cur_result){ $serv_status = get_service_status_of_trigger($row['triggerid']); update_services($triggerid, $serv_status); // updating status to all services by the dependency @@ -251,12 +253,12 @@ include_once "include/page_header.php"; S_TRIGGER." [".$triggerid."] [".expand_trigger_description($triggerid)."] ".S_ENABLED); } } - $result = DBend($result && !empty($_REQUEST["g_triggerid"])); + $result = DBend($result); show_messages($result, S_STATUS_UPDATED, S_CANNOT_UPDATE_STATUS); } else if(isset($_REQUEST["group_disable"])&&isset($_REQUEST["g_triggerid"])){ - $result = true; + $result = false; DBstart(); foreach($_REQUEST["g_triggerid"] as $triggerid){ @@ -265,19 +267,22 @@ include_once "include/page_header.php"; $res=DBselect("SELECT triggerid FROM triggers t WHERE t.triggerid=".zbx_dbstr($triggerid)); if(!$row = DBfetch($res)) continue; - if($result &= update_trigger_status($row["triggerid"],1));{ + $cur_result = update_trigger_status($row["triggerid"],1); + $result |= $cur_result; + + if($cur_result){ update_services($triggerid, 0); // updating status to all services by the dependency add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_TRIGGER, S_TRIGGER." [".$triggerid."] [".expand_trigger_description($triggerid)."] ".S_DISABLED); } } - $result = DBend($result && !empty($_REQUEST["g_triggerid"])); + $result = DBend($result); show_messages($result, S_STATUS_UPDATED, S_CANNOT_UPDATE_STATUS); } else if(isset($_REQUEST["group_delete"])&&isset($_REQUEST["g_triggerid"])){ - $result = true; + $result = false; DBstart(); foreach($_REQUEST["g_triggerid"] as $triggerid){ @@ -288,14 +293,15 @@ include_once "include/page_header.php"; if($row["templateid"] <> 0) continue; $description = expand_trigger_description($triggerid); - $result &= delete_trigger($row["triggerid"]); + $cur_result = delete_trigger($row["triggerid"]); + $result |= $cur_result; - if($result){ + if($cur_result){ add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_TRIGGER, S_TRIGGER." [".$triggerid."] [".$description."] ".S_DISABLED); } } - $result = DBend($result && !empty($_REQUEST["g_triggerid"])); + $result = DBend($result); show_messages($result, S_TRIGGERS_DELETED, S_CANNOT_DELETE_TRIGGERS); } ?> |