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.$value."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)==$value) { $s=sprintf("%.0f",$value); } else { $s=sprintf("%.2f",$value); } return "$s $u$units"; } if($units=="") { if(round($value)==$value) { 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 { $u="G"; $value=$value/(1024*1024*1024); } if(round($value)==$value) { $s=sprintf("%.0f",$value); } else { $s=sprintf("%.2f",$value); } return "$s $u$units"; } function get_template_permission_str($num) { $str=SPACE; if(($num&1)==1) $str=$str.S_ADD.SPACE; if(($num&2)==2) $str=$str.S_UPDATE.SPACE; if(($num&4)==4) $str=$str.S_DELETE.SPACE; return $str; } function get_media_count_by_userid($userid) { $sql="select count(mediaid) as cnt from media where userid=$userid"; $result=DBselect($sql); $row=DBfetch($result); return $row["cnt"]; } function get_action_count_by_triggerid($triggerid) { $cnt=0; $sql="select count(actionid) as cnt from actions where triggerid=$triggerid and scope=0"; $result=DBselect($sql); $row=DBfetch($result); $cnt=$cnt+$row["cnt"]; $sql="select count(actionid) as cnt from actions where scope=2"; $result=DBselect($sql); $row=DBfetch($result); $cnt=$cnt+$row["cnt"]; $sql="select distinct h.hostid from hosts h,items i,triggers t,functions f where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=$triggerid"; $result=DBselect($sql); while($row=DBfetch($result)) { $sql="select count(*) as cnt from actions a,hosts h,items i,triggers t,functions f where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and a.triggerid=".$row["hostid"]." and a.scope=1"; $result2=DBselect($sql); $row2=DBfetch($result2); $cnt=$cnt+$row2["cnt"]; } return $cnt; } function check_anyright($right,$permission) { global $USER_DETAILS; $sql="select permission from rights where name='Default permission' and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $default_permission="H"; if(DBnum_rows($result)>0) { $default_permission=""; while($row=DBfetch($result)) { $default_permission=$default_permission.$row["permission"]; } } # default_permission $sql="select permission from rights where name=".zbx_dbstr($right)." and id!=0 and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $all_permissions=""; if(DBnum_rows($result)>0) { while($row=DBfetch($result)) { $all_permissions=$all_permissions.$row["permission"]; } } # all_permissions // echo "$all_permissions|$default_permission
"; switch ($permission) { case 'A': if(strstr($all_permissions,"A")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"A")) { return 1; } break; case 'R': if(strstr($all_permissions,"R")) { return 1; } else if(strstr($all_permissions,"U")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"R")) { return 1; } else if(strstr($default_permission,"U")) { return 1; } break; case 'U': if(strstr($all_permissions,"U")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"U")) { return 1; } break; default: return 0; } return 0; } function check_right($right,$permission,$id) { global $USER_DETAILS; $sql="select permission from rights where name='Default permission' and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $default_permission="H"; if(DBnum_rows($result)>0) { $default_permission=""; while($row=DBfetch($result)) { $default_permission=$default_permission.$row["permission"]; } } # default_permission $sql="select permission from rights where name=".zbx_dbstr($right)." and id=0 and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $group_permission=""; if(DBnum_rows($result)>0) { while($row=DBfetch($result)) { $group_permission=$group_permission.$row["permission"]; } } # group_permission $id_permission=""; if($id!=0) { $sql="select permission from rights where name=".zbx_dbstr($right)." and id=$id and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); if(DBnum_rows($result)>0) { while($row=DBfetch($result)) { $id_permission=$id_permission.$row["permission"]; } } } # id_permission // echo "$id_permission|$group_permission|$default_permission
"; switch ($permission) { case 'A': if(strstr($id_permission,"H")) { return 0; } else if(strstr($id_permission,"A")) { return 1; } if(strstr($group_permission,"H")) { return 0; } else if(strstr($group_permission,"A")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"A")) { return 1; } break; case 'R': if(strstr($id_permission,"H")) { return 0; } else if(strstr($id_permission,"R")) { return 1; } else if(strstr($id_permission,"U")) { return 1; } if(strstr($group_permission,"H")) { return 0; } else if(strstr($group_permission,"R")) { return 1; } else if(strstr($group_permission,"U")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"R")) { return 1; } else if(strstr($default_permission,"U")) { return 1; } break; case 'U': if(strstr($id_permission,"H")) { return 0; } else if(strstr($id_permission,"U")) { return 1; } if(strstr($group_permission,"H")) { return 0; } else if(strstr($group_permission,"U")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"U")) { return 1; } break; default: return 0; } return 0; } /* function check_right($right,$permission,$id) { global $USER_DETAILS; if($id!=0) { $sql="select * from rights where name='$right' and permission in ('H') and id=$id and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); if(DBnum_rows($result)>0) { return 0; } } $sql="select permission from rights where name='Default permission' and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $default_permission="H"; if(DBnum_rows($result)>0) { $default_permission=""; while($row=DBfetch($result)) { $default_permission=$default_permission.$row["permission"]; } } if($permission=='R') { $cond="'R','U'"; } else { $cond="'".$permission."'"; } $sql="select * from rights where name='$right' and permission in ($cond) and (id=$id or id=0) and userid=".$USER_DETAILS["userid"]; // echo $sql; $result=DBselect($sql); if(DBnum_rows($result)>0) { return 1; } else { if(strstr($default_permission,"A")&&($permission=="A")) { return 1; } if(strstr($default_permission,"R")&&($permission=="R")) { return 1; } if(strstr($default_permission,"U")&&($permission=="R")) { return 1; } if(strstr($default_permission,"U")&&($permission=="U")) { return 1; } return 0; } } */ // The hash has form , function calc_trigger_hash() { $priorities=0; for($i=0;$i<=5;$i++) { $result=DBselect("select count(*) as cnt 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 and t.priority=$i"); $row=DBfetch($result); $priorities+=pow(100,$i)*$row["cnt"]; } $triggerids=""; $result=DBselect("select t.triggerid 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)) { $triggerids="$triggerids,".$row["triggerid"]; } $md5sum=md5($triggerids); return "$priorities,$md5sum"; } function get_image_by_name($imagetype,$name) { $sql="select * from images where imagetype=$imagetype and name=".zbx_dbstr($name); $result=DBselect($sql); if(DBnum_rows($result) == 1) { return DBfetch($result); } else { return 0; } } function get_function_by_functionid($functionid) { $sql="select * from functions where functionid=$functionid"; $result=DBselect($sql); if(DBnum_rows($result) == 1) { return DBfetch($result); } else { error("No function with functionid=[$functionid]"); } return $item; } function select_config() { $sql="select * from config"; $result=DBselect($sql); if(DBnum_rows($result) == 1) { return DBfetch($result); } else { error("Unable to select configuration"); } return $config; } function show_infomsg() { global $INFO_MSG; global $ERROR_MSG; if(is_array($INFO_MSG) && count($INFO_MSG)>0) { echo "

"; while($val = array_shift($INFO_MSG)) { echo $val.BR; } echo "

"; } } function show_messages($bool=TRUE,$msg=NULL,$errmsg=NULL) { global $ERROR_MSG; if(!$bool) { if(!is_null($errmsg)) $msg="ERROR:".$errmsg; $color="#AA0000"; } else { $color="#223344"; } if(isset($msg)) { echo "

"; echo ""; echo "[$msg]"; echo ""; echo "

"; } show_infomsg(); if(is_array($ERROR_MSG) && count($ERROR_MSG)>0) { echo "

"; while($val = array_shift($ERROR_MSG)) { echo $val.BR; } echo "

"; } } function show_message($msg) { show_messages(TRUE,$msg,''); } function show_error_message($msg) { show_messages(FALSE,'',$msg); } function validate_float($str) { // echo "Validating float:$str
"; if (eregi('^[ ]*([0-9]+)((\.)?)([0-9]*[KMG]{0,1})[ ]*$', $str, $arr)) { return 0; } else { return -1; } } // Check if str has format # or function validate_ticks($str) { // echo "Validating float:$str
"; if (eregi('^[ ]*#([0-9]+)((\.)?)([0-9]*)[ ]*$', $str, $arr)) { return 0; } else return validate_float($str); } // Does expression match server:key.function(param) ? function validate_simple_expression($expression) { // echo "Validating simple:$expression
"; // Before str() // if (eregi('^\{([0-9a-zA-Z[.-.]\_\.]+)\:([]\[0-9a-zA-Z\_\/\.\,]+)\.((diff)|(min)|(max)|(last)|(prev))\(([0-9\.]+)\)\}$', $expression, $arr)) // if (eregi('^\{([0-9a-zA-Z[.-.]\_\.]+)\:([]\[0-9a-zA-Z\_\/\.\,]+)\.((diff)|(min)|(max)|(last)|(prev)|(str))\(([0-9a-zA-Z\.\_\/\,]+)\)\}$', $expression, $arr)) if (eregi('^\{([0-9a-zA-Z\_\.-]+)\:([]\[0-9a-zA-Z\_\/\.\,\:\(\) -]+)\.([a-z]{3,11})\(([#0-9a-zA-Z\_\/\.\,]+)\)\}$', $expression, $arr)) { $host=$arr[1]; $key=$arr[2]; $function=$arr[3]; $parameter=$arr[4]; // echo $host,"
"; // echo $key,"
"; // echo $function,"
"; // echo $parameter,"
"; $sql="select count(*) as cnt from hosts h,items i where h.host=".zbx_dbstr($host)." and i.key_=".zbx_dbstr($key)." and h.hostid=i.hostid"; $result=DBselect($sql); $row=DBfetch($result); if($row["cnt"]!=1) { error("No such host ($host) or monitored parameter ($key)"); return -1; } if( ($function!="last")&& ($function!="diff")&& ($function!="min") && ($function!="max") && ($function!="avg") && ($function!="sum") && ($function!="count") && ($function!="prev")&& ($function!="delta")&& ($function!="change")&& ($function!="abschange")&& ($function!="nodata")&& ($function!="time")&& ($function!="dayofweek")&& ($function!="date")&& ($function!="now")&& ($function!="str")&& ($function!="fuzzytime")&& ($function!="logseverity")&& ($function!="logsource")&& ($function!="regexp") ) { error("Unknown function [$function]"); return -1; } if(in_array($function,array("last","diff","count", "prev","change","abschange","nodata","time","dayofweek", "date","now","fuzzytime")) && (validate_float($parameter)!=0) ) { error("[$parameter] is not a float"); return -1; } if(in_array($function,array("min","max","avg","sum", "delta")) && (validate_ticks($parameter)!=0) ) { error("[$parameter] is not a float"); return -1; } } else { error("Expression [$expression] does not match to [server:key.func(param)]"); return -1; } return 0; } /* function validate_expression($expression) { // echo "Validating expression: $expression
"; $ok=0; // Replace all {server:key.function(param)} with 0 while($ok==0) { // echo "Expression:$expression
"; $arr=""; if (eregi('^((.)*)[ ]*(\{((.)*)\})[ ]*((.)*)$', $expression, $arr)) { // for($i=0;$i<20;$i++) // { // if($arr[$i]) // echo " $i: ",$arr[$i],"
"; // } if(validate_simple_expression($arr[3])!=0) { return -1; } $expression=$arr[1]."0".$arr[6]; } else { $ok=1; } } // echo "Result:$expression

"; $ok=0; while($ok==0) { // Replace all with 0 // echo "Expression:$expression
"; $arr=""; if (eregi('^((.)*)([0-9\.]+[A-Z]{0,1})[ ]*([\&\|\>\<\=\+\-\*\/\#]{1})[ ]*([0-9\.]+[A-Z]{0,1})((.)*)$', $expression, $arr)) { // echo "OK
"; // for($i=0;$i<50;$i++) // { // if($arr[$i]!="") // echo " $i: ",$arr[$i],"
"; // } if(validate_float($arr[3])!=0) { error("[".$arr[3]."] is not a float"); return -1; } if(validate_float($arr[5])!=0) { error("[".$arr[5]."] is not a float"); return -1; } $expression=$arr[1]."(0)".$arr[6]; } else { $ok=1; } // Replace all (float) with 0 // echo "Expression2:[$expression]
"; $arr=""; if (eregi('^((.)*)(\(([ 0-9\.]+)\))((.)*)$', $expression, $arr)) { // echo "OK
"; // for($i=0;$i<30;$i++) // { // if($arr[$i]!="") // echo " $i: ",$arr[$i],"
"; // } if(validate_float($arr[4])!=0) { error("[".$arr[4]."] is not a float"); return -1; } $expression=$arr[1]."0".$arr[5]; $ok=0; } else { $ok=1; } } // echo "Result:$expression

"; if($expression=="0") { return 0; } return 1; } /**/ function cr() { echo "\n"; } function check_authorisation() { global $page; global $PHP_AUTH_USER,$PHP_AUTH_PW; global $USER_DETAILS; global $_COOKIE; global $_REQUEST; // global $sessionid; if(isset($_COOKIE["sessionid"])) { $sessionid=$_COOKIE["sessionid"]; } else { unset($sessionid); } if(isset($sessionid)) { $sql="select u.userid,u.alias,u.name,u.surname,u.lang,u.refresh from sessions s,users u where s.sessionid=".zbx_dbstr($sessionid)." and s.userid=u.userid and ((s.lastaccess+u.autologout>".time().") or (u.autologout=0))"; $result=DBselect($sql); if(DBnum_rows($result)==1) { // setcookie("sessionid",$sessionid,time()+3600); setcookie("sessionid",$sessionid); $sql="update sessions set lastaccess=".time()." where sessionid=".zbx_dbstr($sessionid); DBexecute($sql); $USER_DETAILS=DBfetch($result); return; } else { setcookie("sessionid",$sessionid,time()-3600); unset($sessionid); } } $sql="select u.userid,u.alias,u.name,u.surname,u.lang,u.refresh from users u where u.alias='guest'"; $result=DBselect($sql); if(DBnum_rows($result)==1) { $USER_DETAILS=DBfetch($result); return; } if($page["file"]!="index.php") { echo ""; } show_header("Login",0,1,1); show_error_message("Login name or password is incorrect"); insert_login_form(); show_page_footer(); exit; } # Header for HTML pages function show_header($title,$dorefresh=0,$nomenu=0,$noauth=0) { global $page; global $USER_DETAILS; if($noauth==0) { check_authorisation(); include_once "include/locales/".$USER_DETAILS["lang"].".inc.php"; process_locales(); } include_once "include/locales/en_gb.inc.php"; process_locales(); ?> \n"; echo " $title [refreshed every ".$USER_DETAILS["refresh"]." sec]\n"; } else { echo " $title\n"; } ?> array( "label"=>S_MONITORING, "pages"=>array("overview.php","latest.php","tr_status.php","queue.php","events.php","actions.php","maps.php","charts.php","screens.php","srv_status.php","alarms.php","history.php","tr_comments.php","report3.php","profile.php","acknow.php"), "level2"=>array( array("label"=>S_OVERVIEW,"url"=>"overview.php"), array("label"=>S_LATEST_DATA,"url"=>"latest.php"), array("label"=>S_TRIGGERS,"url"=>"tr_status.php"), array("label"=>S_QUEUE,"url"=>"queue.php"), array("label"=>S_EVENTS,"url"=>"events.php"), array("label"=>S_ACTIONS,"url"=>"actions.php"), array("label"=>S_MAPS,"url"=>"maps.php"), array("label"=>S_GRAPHS,"url"=>"charts.php"), array("label"=>S_SCREENS,"url"=>"screens.php"), array("label"=>S_IT_SERVICES,"url"=>"srv_status.php") ) ), "cm"=>array( "label"=>S_CONFIGURATION_MANAGEMENT, "pages"=>array("hostprofiles.php"), "level2"=>array( array("label"=>S_HOSTS,"url"=>"hostprofiles.php") ) ), "reports"=>array( "label"=>S_REPORTS, "pages"=>array("report1.php","report2.php"), "level2"=>array( array("label"=>S_STATUS_OF_ZABBIX,"url"=>"report1.php"), array("label"=>S_AVAILABILITY_REPORT,"url"=>"report2.php") ) ), "configuration"=>array( "label"=>S_CONFIGURATION, "pages"=>array("config.php","users.php","audit.php","hosts.php","items.php","triggers.php","sysmaps.php","graphs.php","screenconf.php","services.php","sysmap.php","media.php","screenedit.php","graph.php","actionconf.php","bulkloader.php"), "level2"=>array( array("label"=>S_GENERAL,"url"=>"config.php"), array("label"=>S_USERS,"url"=>"users.php"), array("label"=>S_AUDIT,"url"=>"audit.php"), array("label"=>S_HOSTS,"url"=>"hosts.php"), array("label"=>S_ITEMS,"url"=>"items.php"), array("label"=>S_TRIGGERS,"url"=>"triggers.php"), array("label"=>S_ACTIONS,"url"=>"actionconf.php"), array("label"=>S_MAPS,"url"=>"sysmaps.php"), array("label"=>S_GRAPHS,"url"=>"graphs.php"), array("label"=>S_SCREENS,"url"=>"screenconf.php"), array("label"=>S_IT_SERVICES,"url"=>"services.php"), array("label"=>S_MENU_BULKLOADER,"url"=>"bulkloader.php") ) ), "login"=>array( "label"=>S_LOGIN, "pages"=>array("index.php"), "level2"=>array( array("label"=>S_LOGIN,"url"=>"index.php"), ) ), ); $table = new CTable(NULL,"page_header"); $table->SetCellSpacing(0); $table->SetCellPadding(5); $col_r = array(new CLink(S_HELP, "http://www.zabbix.com/manual/v1.1/index.php", "small_font")); if($USER_DETAILS["alias"]!="guest") { array_push($col_r, "|"); array_push($col_r, new CLink(S_PROFILE, "profile.php", "small_font")); } $table->AddRow(array( new CCol(new CLink(new CImg("images/general/zabbix.png","ZABBIX")), "page_header_l"), new CCol($col_r, "page_header_r"))); $table->Show(); ?> $sub) { // Check permissions if($label=="configuration") { if( !check_anyright("Configuration of Zabbix","U") &&!check_anyright("User","U") &&!check_anyright("Host","U") &&!check_anyright("Graph","U") &&!check_anyright("Screen","U") &&!check_anyright("Network map","U") &&!check_anyright("Service","U") ) { continue; } if( !check_anyright("Default permission","R") &&!check_anyright("Host","R") ) { continue; } } // End of check permissions $active=0; foreach($sub["pages"] as $label2) { if($page["file"]==$label2) { $active=1; $active_level1=$label; } } if($i==0) $url=get_profile("web.menu.view.last",0); else if($i==1) $url=get_profile("web.menu.cm.last",0); else if($i==2) $url=get_profile("web.menu.reports.last",0); else if($i==3) $url=get_profile("web.menu.config.last",0); else if($i==4) $url="0"; if($url=="0") $url=$sub["level2"][0]["url"]; if($active==1) $class = "horizontal_menu"; else $class = "horizontal_menu_n"; echo "\n"; $i++; } ?>
SetHeader(array(S_TIMESTAMP,item_description($item["description"],$item["key_"]))); while($row=DBfetch($result)) { $table->AddRow(array(date(S_DATE_FORMAT_YMDHMS,$row["clock"]), $row["value"])); } return $table; } # Show values in plain text function show_plaintext($itemid, $from, $till) { $item=get_item_by_itemid($itemid); if($item["value_type"]==ITEM_VALUE_TYPE_FLOAT) { $sql="select clock,value from history where itemid=$itemid and clock>$from and clock<$till order by clock"; } else if($item["value_type"]==ITEM_VALUE_TYPE_UINT64) { $sql="select clock,value from history_uint where itemid=$itemid and clock>$from and clock<$till order by clock"; } else if($item["value_type"]==ITEM_VALUE_TYPE_LOG) { $sql="select clock,value from history_log where itemid=$itemid and clock>$from and clock<$till order by clock"; } else { $sql="select clock,value from history_str where itemid=$itemid and clock>$from and clock<$till order by clock"; } $result=DBselect($sql); echo "
\n";
		while($row=DBfetch($result))
		{
			$clock=$row["clock"];
			$value=$row["value"];
			echo date("Y-m-d H:i:s",$clock);
			echo "\t$clock\t$value\n";
		}
	}
 

	# Translate {10}>10 to something like localhost:procload.last(0)>10

	function	explode_exp ($expression, $html)
	{
#		echo "EXPRESSION:",$expression,"
"; $functionid=''; $exp=''; $state=''; for($i=0;$i".$row1["host"].":".$row1["key_"].".".$row1["function"]."(".$row1["parameter"].")}"; } else { $exp=$exp."{".$row1["host"].":".$row1["key_"].".".$row1["function"]."(".$row1["parameter"].")}"; } } continue; } if($state == "FUNCTIONID") { $functionid=$functionid.$expression[$i]; continue; } $exp=$exp.$expression[$i]; } # echo "EXP:",$exp,"
"; return $exp; } # Translate localhost:procload.last(0)>10 to {12}>10 /*function implode_exp ($expression, $triggerid) { // echo "Expression:$expression
"; $exp=''; $state=""; for($i=0;$i"; // echo "KEY:$key
"; // echo "FUNCTION:$function
"; // echo "PARAMETER:$parameter
"; $state=''; $sql="select i.itemid from items i,hosts h where i.key_=".zbx_dbstr($key). " and h.host=".zbx_dbstr($host)." and h.hostid=i.hostid"; # echo $sql,"
"; $res=DBselect($sql); $row=DBfetch($res); $itemid=$row["itemid"]; # echo "ITEMID:$itemid
"; $sql="insert into functions (itemid,triggerid,function,parameter)". " values ($itemid,$triggerid,".zbx_dbstr($function).",". zbx_dbstr($parameter).")"; # echo $sql,"
"; $res=DBexecute($sql); if(!$res) { # echo "ERROR
"; return $res; } $functionid=DBinsert_id($res,"functions","functionid"); $exp=$exp.'{'.$functionid.'}'; continue; } if($expression[$i] == '(') { if($state == "FUNCTION") { $state='PARAMETER'; continue; } } if($expression[$i] == ')') { if($state == "PARAMETER") { $state=''; continue; } } if(($expression[$i] == ':') && ($state == "HOST")) { $state="KEY"; continue; } if($expression[$i] == '.') { if($state == "KEY") { $state="FUNCTION"; continue; } // Support for '.' in KEY if($state == "FUNCTION") { $state="FUNCTION"; $key=$key.".".$function; $function=""; continue; } } if($state == "HOST") { $host=$host.$expression[$i]; continue; } if($state == "KEY") { $key=$key.$expression[$i]; continue; } if($state == "FUNCTION") { $function=$function.$expression[$i]; continue; } if($state == "PARAMETER") { $parameter=$parameter.$expression[$i]; continue; } $exp=$exp.$expression[$i]; } return $exp; }*/ function add_image($name,$imagetype,$file) { if(!is_null($file)) { if($file["error"] != 0 || $file["size"]==0) { error("Incorrect Image"); return FALSE; } if($file["size"]<1024*1024) { $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"])); $sql="insert into images (name,imagetype,image) values (".zbx_dbstr($name).",$imagetype,".zbx_dbstr($image).")"; return DBexecute($sql); } else { error("Image size must be less than 1Mb"); return FALSE; } } else { error("Select image to download"); return FALSE; } } function update_image($imageid,$name,$imagetype,$file) { if(!is_null($file)) { if($file["error"] != 0 || $file["size"]==0) { error("Incorrect Image"); return FALSE; } if($file["size"]<1024*1024) { $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"])); $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).",image=".zbx_dbstr($image)." where imageid=$imageid"; return DBexecute($sql); } else { error("Image size must be less than 1Mb"); return FALSE; } } else { $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype)." where imageid=$imageid"; return DBexecute($sql); } } function delete_image($imageid) { $sql="delete from images where imageid=$imageid"; return DBexecute($sql); } # Delete Alert by actionid function delete_alert_by_actionid( $actionid ) { $sql="delete from alerts where actionid=$actionid"; return DBexecute($sql); } function delete_rights_by_userid($userid ) { $sql="delete from rights where userid=$userid"; return DBexecute($sql); } # Delete from History function delete_history_by_itemid($itemid, $use_housekeeper=0) { $result = delete_trends_by_itemid($itemid,$use_housekeeper); if(!$result) return $result; if($use_housekeeper) { DBexecute("insert into housekeeper (tablename,field,value)". " values ('history_uint','itemid',$itemid)"); DBexecute("insert into housekeeper (tablename,field,value)". " values ('history_str','itemid',$itemid)"); DBexecute("insert into housekeeper (tablename,field,value)". " values ('history','itemid',$itemid)"); return TRUE; } DBexecute("delete from history_uint where itemid=$itemid"); DBexecute("delete from history_str where itemid=$itemid"); DBexecute("delete from history where itemid=$itemid"); return TRUE; } # Delete from Trends function delete_trends_by_itemid($itemid, $use_housekeeper=0) { if($use_housekeeper) { DBexecute("insert into housekeeper (tablename,field,value)". " values ('trends','itemid',$itemid)"); return TRUE; } return DBexecute("delete from trends where itemid=$itemid"); } # Add alarm function add_alarm($triggerid,$value) { $sql="select max(clock) from alarms where triggerid=$triggerid"; $result=DBselect($sql); $row=DBfetch($result); if($row[0]!="") { $sql="select value from alarms where triggerid=$triggerid and clock=".$row[0]; $result=DBselect($sql); if(DBnum_rows($result) == 1) { $row=DBfetch($result); if($row["value"] == $value) { return 0; } } } $now=time(); $sql="insert into alarms(triggerid,clock,value) values($triggerid,$now,$value)"; return DBexecute($sql); } function get_alarm_by_alarmid($alarmid) { $db_alarms = DBselect("select * from alarms where alarmid=$alarmid"); return DBfetch($db_alarms); } # Reset nextcheck for related items function reset_items_nextcheck($triggerid) { $sql="select itemid from functions where triggerid=$triggerid"; $result=DBselect($sql); while($row=DBfetch($result)) { $sql="update items set nextcheck=0 where itemid=".$row["itemid"]; DBexecute($sql); } } # Delete Media definition by mediatypeid function delete_media_by_mediatypeid($mediatypeid) { $sql="delete from media where mediatypeid=$mediatypeid"; return DBexecute($sql); } # Delete alrtes by mediatypeid function delete_alerts_by_mediatypeid($mediatypeid) { $sql="delete from alerts where mediatypeid=$mediatypeid"; return DBexecute($sql); } function get_mediatype_by_mediatypeid($mediatypeid) { $sql="select * from media_type where mediatypeid=$mediatypeid"; $result=DBselect($sql); if(DBnum_rows($result) == 1) { return DBfetch($result); } else { error("No media type with with mediatypeid=[$mediatypeid]"); } return $item; } # Delete media type function delete_mediatype($mediatypeid) { delete_media_by_mediatypeid($mediatypeid); delete_alerts_by_mediatypeid($mediatypeid); $sql="delete from media_type where mediatypeid=$mediatypeid"; return DBexecute($sql); } # Update media type function update_mediatype($mediatypeid,$type,$description,$smtp_server,$smtp_helo,$smtp_email,$exec_path) { $ret = 0; $sql="select * from media_type where description=".zbx_dbstr($description)." and mediatypeid!=$mediatypeid"; $result=DBexecute($sql); if(DBnum_rows($result)>0) { error("An action type with description '$description' already exists."); } else { $sql="update media_type set type=$type,description=".zbx_dbstr($description).",smtp_server=".zbx_dbstr($smtp_server).",smtp_helo=".zbx_dbstr($smtp_helo).",smtp_email=".zbx_dbstr($smtp_email).",exec_path=".zbx_dbstr($exec_path)." where mediatypeid=$mediatypeid"; $ret = DBexecute($sql); } return $ret; } # Add Media type function add_mediatype($type,$description,$smtp_server,$smtp_helo,$smtp_email,$exec_path) { $ret = 0; if($description==""){ error(S_INCORRECT_DESCRIPTION); return 0; } $sql="select * from media_type where description=".zbx_dbstr($description); $result=DBexecute($sql); if(DBnum_rows($result)>0) { error("An action type with description '$description' already exists."); } else { $sql="insert into media_type (type,description,smtp_server,smtp_helo,smtp_email,exec_path) values ($type,".zbx_dbstr($description).",".zbx_dbstr($smtp_server).",".zbx_dbstr($smtp_helo).",".zbx_dbstr($smtp_email).",".zbx_dbstr($exec_path).")"; $ret = DBexecute($sql); } return $ret; } # Add Media definition function add_media( $userid, $mediatypeid, $sendto, $severity, $active, $period) { $c=count($severity); $s=0; for($i=0;$i<$c;$i++) { $s=$s|pow(2,(int)$severity[$i]); } $sql="insert into media (userid,mediatypeid,sendto,active,severity,period) values ($userid,".zbx_dbstr($mediatypeid).",".zbx_dbstr($sendto).",$active,$s,".zbx_dbstr($period).")"; return DBexecute($sql); } # Update Media definition function update_media($mediaid, $userid, $mediatypeid, $sendto, $severity, $active, $period) { $c=count($severity); $s=0; for($i=0;$i<$c;$i++) { $s=$s|pow(2,(int)$severity[$i]); } $sql="update media set userid=$userid, mediatypeid=$mediatypeid, sendto=".zbx_dbstr($sendto).", active=$active,severity=$s,period=".zbx_dbstr($period)." where mediaid=$mediaid"; return DBexecute($sql); } # Delete Media definition function delete_media($mediaid) { $sql="delete from media where mediaid=$mediaid"; return DBexecute($sql); } # Delete Media definition by userid function delete_media_by_userid($userid) { $sql="delete from media where userid=$userid"; return DBexecute($sql); } function delete_profiles_by_userid($userid) { $sql="delete from profiles where userid=$userid"; return DBexecute($sql); } # Update configuration // function update_config($smtp_server,$smtp_helo,$smtp_email,$alarm_history,$alert_history) function update_config($alarm_history,$alert_history,$refresh_unsupported) { if(!check_right("Configuration of Zabbix","U",0)) { error("Insufficient permissions"); return 0; } // $sql="update config set smtp_server='$smtp_server',smtp_helo='$smtp_helo',smtp_email='$smtp_email',alarm_history=$alarm_history,alert_history=$alert_history"; $sql="update config set alarm_history=$alarm_history,alert_history=$alert_history,refresh_unsupported=$refresh_unsupported"; return DBexecute($sql); } # Activate Media function activate_media($mediaid) { $sql="update media set active=0 where mediaid=$mediaid"; return DBexecute($sql); } # Disactivate Media function disactivate_media($mediaid) { $sql="update media set active=1 where mediaid=$mediaid"; return DBexecute($sql); } # Delete User permission function delete_permission($rightid) { $sql="delete from rights where rightid=$rightid"; return DBexecute($sql); } # Delete User definition function delete_user($userid) { $sql="select * from users where userid=$userid and alias='guest'"; $result=DBselect($sql); if(DBnum_rows($result) == 1) { error("Cannot delete user 'guest'"); return 0; } delete_media_by_userid($userid); delete_actions_by_userid($userid); delete_rights_by_userid($userid); delete_profiles_by_userid($userid); $sql="delete from users_groups where userid=$userid"; DBexecute($sql); $sql="delete from users where userid=$userid"; return DBexecute($sql); } function show_table_h_delimiter() { // echo ""; cr(); echo ""; cr(); echo ""; cr(); // echo " "; cr(); } function show_table2_h_delimiter() { // echo ""; cr(); echo ""; cr(); // echo ""; echo ""; cr(); // echo " "; cr(); } function show_table3_h_delimiter($width=10) { ?> "; cr(); echo ""; cr(); cr(); */ } function show_table_v_delimiter($colspan=1) { // echo ""; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); // echo ""; cr(); } function show_table2_v_delimiter($rownum=0) { // echo ""; cr(); echo ""; cr(); echo ""; cr(); if($rownum%2 == 1) { echo ""; } else { echo ""; } cr(); // echo ""; echo ""; cr(); // echo ""; cr(); } function show_table3_v_delimiter() { ?> "; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); cr();*/ } function show_table2_v_delimiter2() { // echo ""; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); // echo ""; echo ""; cr(); // echo ""; cr(); } // function show_table2_header_begin() function show_form_begin($help="") { ?>

"; echo ""; echo "
\"?\""; } } function show_table_header_begin() { echo ""; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); echo "
"; cr(); echo ""; cr(); echo ""; cr(); // echo ""; cr(); echo ""; cr(); echo "
"; echo ""; cr(); // echo " "; cr(); } function show_header2($col1, $col2=SPACE, $before="", $after="") { echo $before; show_table_header($col1, $col2); echo $after; } function show_table3_header_begin() { ?> "; } function show_table2_header_end() { // cr(); // echo ""; // cr(); // echo ""; // cr(); // echo ""; cr(); echo "
"; // echo "

"; cr(); } function show_table_header_end() { /* cr(); echo "
"; cr();*/ echo "
"; } function show_table_header($col1, $col2=SPACE) { $table = new CTable(NULL,"header"); $table->SetCellSpacing(0); $table->SetCellPadding(1); $table->AddRow(array(new CCol($col1,"header_l"), new CCol($col2,"header_r"))); $table->Show(); } function insert_time_navigator($itemid,$period,$from) { $descr=array("January","February","March","April","May","June", "July","August","September","October","November","December"); $sql="select min(clock) as minn,max(clock) as maxx from history where itemid=$itemid"; $result=DBselect($sql); if(DBnum_rows($result) == 0) { $min=time(NULL); $max=time(NULL); } else { $row=DBfetch($result); $min=$row["minn"]; $max=$row["maxx"]; } $now=time()-3600*$from-$period; $year_min=date("Y",$min); $year_max=date("Y",$max); $year_now=date("Y",$now); $month_now=date("m",$now); $day_now=date("d",$now); $hour_now=date("H",$now); echo "

"; echo ""; echo ""; echo "Year"; echo ""; echo "Month"; echo ""; echo "Day"; echo ""; echo "Hour"; echo ""; echo "Period:"; echo ""; echo ""; echo "
"; } # Show History Graph function show_history($itemid,$from,$period) { if (!isset($from)) { $from=0; $till="NOW"; } else { $till=time(NULL)-$from*3600; $till=date(S_DATE_FORMAT_YMDHMS,$till); } if (!isset($period)) { $period=3600; show_table_header("TILL $till (LAST HOUR)"); } else { $tmp=$period/3600; show_table_header("TILL $till ($tmp HOURs)"); } // echo("
"); echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
"; echo ""; echo "
"; echo "
"; navigation_bar("history.php"); } # Show history function show_freehist($itemid,$period) { show_form_begin("history.period"); echo "Choose period"; show_table2_v_delimiter(); echo "
"; echo ""; echo "Period in seconds"; show_table2_h_delimiter(); echo ""; show_table2_v_delimiter(); echo "From (in hours)"; show_table2_h_delimiter(); echo ""; show_table2_v_delimiter2(); echo "Press "; echo " to see values in plain text"; show_table2_header_end(); show_page_footer(); } # Show in plain text function show_plaintxt($itemid,$period) { show_form_begin("history.plaim"); echo "Data in plain text format"; show_table2_v_delimiter(); echo ""; echo ""; echo ""; echo "From: (yyyy/mm/dd - HH:MM)"; show_table2_h_delimiter(); echo "/"; echo "/"; echo " - "; echo ":"; echo ""; show_table2_v_delimiter(); echo "Till: (yyyy/mm/dd - HH:MM)"; show_table2_h_delimiter(); echo "/"; echo "/"; echo " - "; echo ":"; echo ""; show_table2_v_delimiter2(); echo "Press to see data in "; echo ""; show_table2_header_end(); show_page_footer(); } function show_page_footer() { global $USER_DETAILS; show_messages(); echo BR; $table = new CTable(NULL,"page_footer"); $table->SetCellSpacing(0); $table->SetCellPadding(1); $table->AddRow(array( new CCol(new CLink( S_ZABBIX_VER.SPACE.S_COPYRIGHT_BY.SPACE.S_SIA_ZABBIX, "http://www.zabbix.com", "highlight"), "page_footer_l"), new CCol(array( new CSpan(SPACE.SPACE."|".SPACE.SPACE,"divider"), S_CONNECTED_AS.SPACE.$USER_DETAILS["alias"] ), "page_footer_r") )); $table->Show(); echo "\n"; echo "\n"; } function get_status() { global $DB_TYPE; $status = array(); // server if( (exec("ps -ef|grep zabbix_server|grep -v grep|wc -l")>0) || (exec("ps -ax|grep zabbix_server|grep -v grep|wc -l")>0) ) { $status["zabbix_server"] = S_YES; } else { $status["zabbix_server"] = S_NO; } // history & trends if ($DB_TYPE == "MYSQL") { $row=DBfetch(DBselect("show table status like 'history'")); $status["history_count"] = $row["Rows"]; $row=DBfetch(DBselect("show table status like 'history_log'")); $status["history_count"] += $row["Rows"]; $row=DBfetch(DBselect("show table status like 'history_str'")); $status["history_count"] += $row["Rows"]; $row=DBfetch(DBselect("show table status like 'history_uint'")); $status["history_count"] += $row["Rows"]; $row=DBfetch(DBselect("show table status like 'trends'")); $status["trends_count"] = $row["Rows"]; } else { $row=DBfetch(DBselect("select count(itemid) as cnt from history")); $status["history_count"] = $row["cnt"]; $row=DBfetch(DBselect("select count(itemid) as cnt from history_log")); $status["history_count"] += $row["cnt"]; $row=DBfetch(DBselect("select count(itemid) as cnt from history_str")); $status["history_count"] += $row["cnt"]; $row=DBfetch(DBselect("select count(itemid) as cnt from history_uint")); $status["history_count"] += $row["cnt"]; $result=DBselect("select count(itemid) as cnt from trends"); $row=DBfetch($result); $status["trends_count"]=$row["cnt"]; } // alarms $row=DBfetch(DBselect("select count(alarmid) as cnt from alarms")); $status["alarms_count"]=$row["cnt"]; // alerts $row=DBfetch(DBselect("select count(alertid) as cnt from alerts")); $status["alerts_count"]=$row["cnt"]; // triggers $sql = "select count(t.triggerid) as cnt from triggers t, functions f, items i, hosts h". " where t.triggerid=f.triggerid and f.itemid=i.itemid and i.status=0 and i.hostid=h.hostid and h.status=".HOST_STATUS_MONITORED; $row=DBfetch(DBselect($sql)); $status["triggers_count"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and t.status=0")); $status["triggers_count_enabled"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and t.status=1")); $status["triggers_count_disabled"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and t.status=0 and t.value=0")); $status["triggers_count_off"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and t.status=0 and t.value=1")); $status["triggers_count_on"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and t.status=0 and t.value=2")); $status["triggers_count_unknown"]=$row["cnt"]; // items $sql = "select count(i.itemid) as cnt from items i, hosts h where i.hostid=h.hostid and h.status=".HOST_STATUS_MONITORED; $row=DBfetch(DBselect($sql)); $status["items_count"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and i.status=0")); $status["items_count_monitored"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and i.status=1")); $status["items_count_disabled"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and i.status=3")); $status["items_count_not_supported"]=$row["cnt"]; $row=DBfetch(DBselect($sql." and i.type=2")); $status["items_count_trapper"]=$row["cnt"]; // hosts $row=DBfetch(DBselect("select count(hostid) as cnt from hosts")); $status["hosts_count"]=$row["cnt"]; $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_MONITORED)); $status["hosts_count_monitored"]=$row["cnt"]; $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_NOT_MONITORED)); $status["hosts_count_not_monitored"]=$row["cnt"]; $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_TEMPLATE)); $status["hosts_count_template"]=$row["cnt"]; $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_DELETED)); $status["hosts_count_deleted"]=$row["cnt"]; // users $row=DBfetch(DBselect("select count(userid) as cnt from users")); $status["users_count"]=$row["cnt"]; $status["users_online"]=DBnum_rows(DBselect("select distinct s.userid from sessions s, users u where u.userid=s.userid and (s.lastaccess+u.autologout)>".time())); return $status; } // If $period_start=$period_end=0, then take maximum period function calculate_availability($triggerid,$period_start,$period_end) { if(($period_start==0)&&($period_end==0)) { $sql="select count(*) as cnt,min(clock) as minn,max(clock) as maxx from alarms where triggerid=$triggerid"; } else { $sql="select count(*) as cnt,min(clock) as minn,max(clock) as maxx from alarms where triggerid=$triggerid and clock>=$period_start and clock<=$period_end"; } // echo $sql,"
"; $result=DBselect($sql); $row=DBfetch($result); if($row["cnt"]>0) { $min=$row["minn"]; $max=$row["maxx"]; } else { if(($period_start==0)&&($period_end==0)) { $max=time(); $min=$max-24*3600; } else { $ret["true_time"]=0; $ret["false_time"]=0; $ret["unknown_time"]=0; $ret["true"]=0; $ret["false"]=0; $ret["unknown"]=100; return $ret; } } $sql="select clock,value from alarms where triggerid=$triggerid and clock>=$min and clock<=$max"; // echo " $sql
"; $result=DBselect($sql); // echo $sql,"
"; // -1,0,1 $state=-1; $true_time=0; $false_time=0; $unknown_time=0; $time=$min; if(($period_start==0)&&($period_end==0)) { $max=time(); } while($row=DBfetch($result)) { $clock=$row["clock"]; $value=$row["value"]; $diff=$clock-$time; $time=$clock; if($state==-1) { $state=$value; if($state == 0) { $false_time+=$diff; } if($state == 1) { $true_time+=$diff; } if($state == 2) { $unknown_time+=$diff; } } else if($state==0) { $false_time+=$diff; $state=$value; } else if($state==1) { $true_time+=$diff; $state=$value; } else if($state==2) { $unknown_time+=$diff; $state=$value; } } if(DBnum_rows($result)==0) { $false_time=$max-$min; } else { if($state==0) { $false_time=$false_time+$max-$time; } elseif($state==1) { $true_time=$true_time+$max-$time; } elseif($state==3) { $unknown_time=$unknown_time+$max-$time; } } // echo "$true_time $false_time $unknown_time"; $total_time=$true_time+$false_time+$unknown_time; if($total_time==0) { $ret["true_time"]=0; $ret["false_time"]=0; $ret["unknown_time"]=0; $ret["true"]=0; $ret["false"]=0; $ret["unknown"]=100; } else { $ret["true_time"]=$true_time; $ret["false_time"]=$false_time; $ret["unknown_time"]=$unknown_time; $ret["true"]=(100*$true_time)/$total_time; $ret["false"]=(100*$false_time)/$total_time; $ret["unknown"]=(100*$unknown_time)/$total_time; } return $ret; } function get_resource_name($permission,$id) { $res="-"; if($permission=="Graph") { if(isset($id)&&($id!=0)) { $host=get_graph_by_graphid($id); $res=$host["name"]; } else { $res="All graphs"; } } else if($permission=="Host") { if(isset($id)&&($id!=0)) { $host=get_host_by_hostid($id); $res=$host["host"]; } else { $res="All hosts"; } } else if($permission=="Screen") { if(isset($id)&&($id!=0)) { $screen=get_screen_by_screenid($id); $res=$screen["name"]; } else { $res="All hosts"; } } else if($permission=="Item") { if(isset($id)&&($id!=0)) { $item=get_item_by_itemid($id); $host=get_host_by_hostid($item["hostid"]); $res=$host["host"].":".$item["description"]; } else { $res="All items"; } } else if($permission=="User") { if(isset($id)&&($id!=0)) { $user=get_user_by_userid($id); $res=$user["alias"]; } else { $res="All users"; } } else if($permission=="Network map") { if(isset($id)&&($id!=0)) { $user=get_map_by_sysmapid($id); $res=$user["name"]; } else { $res="All maps"; } } return $res; } function get_profile($idx,$default_value) { global $USER_DETAILS; if($USER_DETAILS["alias"]=="guest") { return $default_value; } $sql="select value from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx); $result=DBselect($sql); if(DBnum_rows($result)==0) { return $default_value; } else { $row=DBfetch($result); return $row["value"]; } } function update_profile($idx,$value) { global $USER_DETAILS; if($USER_DETAILS["alias"]=="guest") { return; } $sql="select value from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx); $result=DBselect($sql); if(DBnum_rows($result)==0) { $sql="insert into profiles (userid,idx,value) values (".$USER_DETAILS["userid"].",".zbx_dbstr($idx).",".zbx_dbstr($value).")"; DBexecute($sql); } else { $row=DBfetch($result); $sql="update profiles set value=".zbx_dbstr($value)." where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx); DBexecute($sql); } } function get_drawtype_description($drawtype) { if($drawtype==0) return "Line"; if($drawtype==1) return "Filled region"; if($drawtype==2) return "Bold line"; if($drawtype==3) return "Dot"; if($drawtype==4) return "Dashed line"; return "Unknown"; } function insert_confirm_javascript() { echo " "; } function insert_javascript_clock($form, $field) { echo " "; } function start_javascript_clock() { echo " "; } function SetFocus($frm_name, $fld_name) { echo " "; } /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ if(function_exists("imagesetstyle")) { function DashedLine($image,$x1,$y1,$x2,$y2,$color) { // Style for dashed lines // $style = array($color, $color, $color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($image, $style); ImageLine($image,$x1,$y1,$x2,$y2,IMG_COLOR_STYLED); } } else { function DashedLine($image,$x1,$y1,$x2,$y2,$color) { ImageDashedLine($image,$x1,$y1,$x2,$y2,$color); } } function time_navigator($resource="graphid",$id) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
"; echo "
"; echo "".S_PERIOD.":".SPACE; $hour=3600; $a=array(S_1H=>3600,S_2H=>2*3600,S_4H=>4*3600,S_8H=>8*3600,S_12H=>12*3600, S_24H=>24*3600,S_WEEK_SMALL=>7*24*3600,S_MONTH_SMALL=>31*24*3600,S_YEAR_SMALL=>365*24*3600); foreach($a as $label=>$sec) { echo "["; if($_REQUEST["period"]>$sec) { $tmp=$_REQUEST["period"]-$sec; echo("-"); } else { echo "-"; } echo(""); echo($label.""); $tmp=$_REQUEST["period"]+$sec; echo("+"); echo "]".SPACE; } echo("
"); echo "
"; echo "".nbsp(S_KEEP_PERIOD).":".SPACE; if($_REQUEST["keep"] == 1) { echo("[".S_ON_C."]"); } else { echo("[".S_OFF_C."]"); } echo "
"; if(isset($_REQUEST["stime"])) { echo "
" ; echo "".S_MOVE.":".SPACE; $day=24; // $a already defined // $a=array("1h"=>1,"2h"=>2,"4h"=>4,"8h"=>8,"12h"=>12, // "24h"=>24,"week"=>7*24,"month"=>31*24,"year"=>365*24); foreach($a as $label=>$hours) { echo "["; $stime=$_REQUEST["stime"]; $tmp=mktime(substr($stime,8,2),substr($stime,10,2),0,substr($stime,4,2),substr($stime,6,2),substr($stime,0,4)); $tmp=$tmp-3600*$hours; $tmp=date("YmdHi",$tmp); echo("-"); echo($label); $stime=$_REQUEST["stime"]; $tmp=mktime(substr($stime,8,2),substr($stime,10,2),0,substr($stime,4,2),substr($stime,6,2),substr($stime,0,4)); $tmp=$tmp+3600*$hours; $tmp=date("YmdHi",$tmp); echo("+"); echo "]".SPACE; } echo("
"); } else { echo "
"; echo "".S_MOVE.":".SPACE; $day=24; // $a already defined // $a=array("1h"=>1,"2h"=>2,"4h"=>4,"8h"=>8,"12h"=>12, // "24h"=>24,"week"=>7*24,"month"=>31*24,"year"=>365*24); foreach($a as $label=>$hours) { echo "["; $tmp=$_REQUEST["from"]+$hours; echo("-"); echo($label); if($_REQUEST["from"]>=$hours) { $tmp=$_REQUEST["from"]-$hours; echo("+"); } else { echo "+"; } echo "]".SPACE; } echo("
"); } echo "
"; // echo("
"); echo ""; echo ""; echo ""; if(isset($_REQUEST["stime"])) { echo ""; } else { echo ""; } echo SPACE; echo ""; echo ""; // echo("
"); echo "
"; } function ImageOut($image) { // ImageJPEG($image); ImagePNG($image); } function add_mapping_to_valuemap($valuemapid, $mappings) { DBexecute("delete from mappings where valuemapid=$valuemapid"); foreach($mappings as $map) { $result = DBexecute("insert into mappings (valuemapid, value, newvalue)". " values (".$valuemapid.",".zbx_dbstr($map["value"]).",". zbx_dbstr($map["newvalue"]).")"); if(!$result) return $result; } return TRUE; } function add_valuemap($name, $mappings) { if(!is_array($mappings)) return FALSE; $result = DBexecute("insert into valuemaps (name) values (".zbx_dbstr($name).")"); if(!$result) return $result; $valuemapid = DBinsert_id($result,"valuemaps","valuemapid"); $result = add_mapping_to_valuemap($valuemapid, $mappings); if(!$result){ delete_valuemap($valuemapid); } return $result; } function update_valuemap($valuemapid, $name, $mappings) { if(!is_array($mappings)) return FALSE; $result = DBexecute("update valuemaps set name=".zbx_dbstr($name). " where valuemapid=$valuemapid"); if(!$result) return $result; $result = add_mapping_to_valuemap($valuemapid, $mappings); if(!$result){ delete_valuemap($valuemapid); } return $result; } function delete_valuemap($valuemapid) { DBexecute("delete from mappings where valuemapid=$valuemapid"); DBexecute("delete from valuemaps where valuemapid=$valuemapid"); return TRUE; } function replace_value_by_map($value, $valuemapid) { $result = DBselect("select newvalue from mappings". " where valuemapid=".zbx_dbstr($valuemapid)." and value=".zbx_dbstr($value)); if(DBnum_rows($result)) { $result = DBfetch($result); return $result["newvalue"].SPACE."($value)"; } return $value; } function Alert($msg) { echo " "; } ?>