0 and gitemid=$gitemid"; return DBexecute($sql); } function move_down_graph_item($gitemid) { if($gitemid<=0) return; $sql="update graphs_items set sortorder=sortorder+1 where sortorder<100 and gitemid=$gitemid"; return DBexecute($sql); } function copy_graphitems_for_host($src_graphid,$dist_graphid,$hostid) { $ret_code=0; $src_graphitems=get_graphitems_by_graphid($src_graphid); while($src_graphitem=DBfetch($src_graphitems)) { $src_item=get_item_by_itemid($src_graphitem["itemid"]); $host_items=get_items_by_hostid($hostid); $item_exist=0; while($host_item=DBfetch($host_items)) { if($src_item["key_"]==$host_item["key_"]) { $item_exist=1; $host_itemid=$host_item["itemid"]; break; } } if($item_exist==0) { $ret_code|=1; continue; } if(!add_item_to_graph($dist_graphid,$host_itemid,$src_graphitem["color"],$src_graphitem["drawtype"],$src_graphitem["sortorder"],$src_graphitem["yaxisside"])) { $ret_code|=2; } } return $ret_code; } function add_graph_item_to_templates($template_graphid,$template_itemid,$color,$drawtype,$sortorder,$yaxisside) { if($template_graphid<=0) return; $template_hosts = get_hosts_by_graphid($template_graphid); if(!$template_hosts) return; $template_hosts_cnt=DBnum_rows($template_hosts); if($template_hosts_cnt==0) { $template_host=get_host_by_itemid($template_itemid); $template_hosts_cnt++; } else if($template_hosts_cnt==1) { $template_host=DBfetch($template_hosts); $item_host=get_host_by_itemid($template_itemid); if($template_host["hostid"]!=$item_host["hostid"]) $template_hosts_cnt++; } if($template_hosts_cnt!=1) return; $template_item=get_item_by_itemid($template_itemid); $sql="select hostid,templateid,graphs from hosts_templates where templateid=".$template_host["hostid"]; $hosts=DBselect($sql); while($host=DBfetch($hosts)) { if($host["graphs"]&2 == 0) continue; $sql="select i.itemid from items i where i.key_='".zbx_ads($template_item["key_"])."' and i.hostid=".$host["hostid"]; $items=DBselect($sql); if(DBnum_rows($items)==0) continue; $item=DBfetch($items); $find_graph=0; $graphs=get_graphs_by_hostid($host["hostid"]); while($graph=DBfetch($graphs)) { if(!cmp_graphs($template_graphid,$graph["graphid"])) continue; if(!cmp_graph_by_item_key($template_graphid,$graph["graphid"])) continue; add_item_to_graph($graph["graphid"],$item["itemid"],$color,$drawtype,$sortorder,$yaxisside); $host_info=get_host_by_hostid($host["hostid"]); info("Added item to graph '".$graph["name"]."' from linked host '".$host_info["host"]."'"); remove_durpblicated_graphs($graph["graphid"]); $find_graph=1; } if($find_graph==0) { # duplicate graph for new host $template_graph=get_graph_by_graphid($template_graphid); $new_graphid=add_graph($template_graph["name"],$template_graph["width"],$template_graph["height"],$template_graph["yaxistype"],$template_graph["yaxismin"],$template_graph["yaxismax"]); if(copy_graphitems_for_host($template_graphid,$new_graphid,$host["hostid"])!=0) { delete_graph($new_graphid); } else { add_item_to_graph($new_graphid,$item["itemid"],$color,$drawtype,$sortorder,$yaxisside); $new_graph=get_graph_by_graphid($new_graphid); $host_info=get_host_by_hostid($host["hostid"]); info("Graph ".$new_graph["name"]." coped for linked host ".$host_info["host"]); remove_durpblicated_graphs($new_graphid); } } } } function move_up_graph_item_from_templates($gitemid) { if($gitemid<=0) return; $graph_item=get_graphitem_by_gitemid($gitemid); $graph=get_graph_by_graphid($graph_item["graphid"]); $item=get_item_by_itemid($graph_item["itemid"]); $sql="select hostid,templateid,graphs from hosts_templates where templateid=".$item["hostid"]; $result=DBselect($sql); while($row=DBfetch($result)) { if($row["graphs"]&2 == 0) continue; $sql="select i.itemid from items i where i.key_='".zbx_ads($item["key_"])."' and i.hostid=".$row["hostid"]; $result2=DBselect($sql); if(DBnum_rows($result2)==0) continue; $row2=DBfetch($result2); $sql="select distinct gi.gitemid,gi.graphid from graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=".$row["hostid"]." and i.itemid=".$row2["itemid"]." and gi.drawtype=".$graph_item["drawtype"]." and gi.sortorder=".$graph_item["sortorder"]." and gi.color='".zbx_ads($graph_item["color"])."' and gi.yaxisside= ".$graph_item["yaxisside"]; $result3=DBselect($sql); if(DBnum_rows($result3)==0) continue; $row3=DBfetch($result3); $graph2=get_graph_by_graphid($row3["graphid"]); if(!cmp_graphs($graph["graphid"],$graph2["graphid"])) continue; if(!cmp_graph_by_item_key($graph["graphid"],$graph2["graphid"]))continue; move_up_graph_item($row3["gitemid"]); $host=get_host_by_hostid($row["hostid"]); info("Updated graph element ".$item["key_"]." from linked host ".$host["host"]); } } function move_down_graph_item_from_templates($gitemid) { if($gitemid<=0) return; $graph_item=get_graphitem_by_gitemid($gitemid); $graph=get_graph_by_graphid($graph_item["graphid"]); $item=get_item_by_itemid($graph_item["itemid"]); $sql="select hostid,templateid,graphs from hosts_templates where templateid=".$item["hostid"]; $result=DBselect($sql); while($row=DBfetch($result)) { if($row["graphs"]&2 == 0) continue; $sql="select i.itemid from items i where i.key_='".zbx_ads($item["key_"])."' and i.hostid=".$row["hostid"]; $result2=DBselect($sql); if(DBnum_rows($result2)==0) continue; $row2=DBfetch($result2); $sql="select distinct gi.gitemid,gi.graphid from graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=".$row["hostid"]." and i.itemid=".$row2["itemid"]." and gi.drawtype=".$graph_item["drawtype"]." and gi.sortorder=".$graph_item["sortorder"]." and gi.color='".zbx_ads($graph_item["color"])."' and gi.yaxisside= ".$graph_item["yaxisside"]; $result3=DBselect($sql); if(DBnum_rows($result3)==0) continue; $row3=DBfetch($result3); $graph2=get_graph_by_graphid($row3["graphid"]); if(!cmp_graphs($graph["graphid"],$graph2["graphid"])) continue; if(!cmp_graph_by_item_key($graph["graphid"],$graph2["graphid"]))continue; move_down_graph_item($row3["gitemid"]); $host=get_host_by_hostid($row["hostid"]); info("Updated graph element ".$item["key_"]." from linked host ".$host["host"]); } } function update_graph_item_from_templates($gitemid,$itemid,$color,$drawtype,$sortorder,$yaxisside) { if($gitemid<=0) return; $graph_item=get_graphitem_by_gitemid($gitemid); $graph=get_graph_by_graphid($graph_item["graphid"]); $item=get_item_by_itemid($graph_item["itemid"]); $sql="select hostid,templateid,graphs from hosts_templates where templateid=".$item["hostid"]; $result=DBselect($sql); while($row=DBfetch($result)) { if($row["graphs"]&2 == 0) continue; $sql="select i.itemid from items i where i.key_='".zbx_ads($item["key_"])."' and i.hostid=".$row["hostid"]; $result2=DBselect($sql); if(DBnum_rows($result2)==0) continue; $row2=DBfetch($result2); $sql="select distinct gi.gitemid,gi.graphid from graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=".$row["hostid"]." and i.itemid=".$row2["itemid"]." and gi.drawtype=".$graph_item["drawtype"]." and gi.sortorder=".$graph_item["sortorder"]." and gi.color='".zbx_ads($graph_item["color"])."' and gi.yaxisside= ".$graph_item["yaxisside"]; $result3=DBselect($sql); if(DBnum_rows($result3)==0) continue; $row3=DBfetch($result3); $graph2=get_graph_by_graphid($row3["graphid"]); if(!cmp_graphs($graph["graphid"],$graph2["graphid"])) continue; if(!cmp_graph_by_item_key($graph["graphid"],$graph2["graphid"]))continue; update_graph_item($row3["gitemid"],$row2["itemid"],$color,$drawtype,$sortorder,$yaxisside); $host=get_host_by_hostid($row["hostid"]); info("Updated graph element ".$item["key_"]." from linked host ".$host["host"]); } } function delete_graph_item_from_templates($gitemid) { if($gitemid<=0) return; $graph_item=get_graphitem_by_gitemid($gitemid); $graph=get_graph_by_graphid($graph_item["graphid"]); $item=get_item_by_itemid($graph_item["itemid"]); $sql="select hostid,templateid,graphs from hosts_templates where templateid=".$item["hostid"]; $result=DBselect($sql); while($row=DBfetch($result)) { if($row["graphs"]&2 == 0) continue; $sql="select i.itemid from items i where i.key_='".zbx_ads($item["key_"])."' and i.hostid=".$row["hostid"]; $result2=DBselect($sql); if(DBnum_rows($result2)==0) continue; $row2=DBfetch($result2); $itemid=$row2["itemid"]; $sql="select distinct gi.gitemid,gi.graphid from graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=".$row["hostid"]." and i.itemid=".$row2["itemid"]." and gi.drawtype=".$graph_item["drawtype"]." and gi.sortorder=".$graph_item["sortorder"]." and gi.color='".zbx_ads($graph_item["color"])."' and gi.yaxisside= ".$graph_item["yaxisside"]; $result3=DBselect($sql); if(DBnum_rows($result3)==0) continue; $row3=DBfetch($result3); $graph2=get_graph_by_graphid($row3["graphid"]); if(!cmp_graphs($graph["graphid"],$graph2["graphid"])) continue; if(!cmp_graph_by_item_key($graph["graphid"],$graph2["graphid"]))continue; delete_graphs_item($row3["gitemid"]); $host=get_host_by_hostid($row["hostid"]); info("Deleted graph element ".$item["key_"]." from linked host ".$host["host"]); $sql="select count(*) as count from graphs_items where graphid=".$row3["graphid"]; $result4=DBselect($sql); $row4=DBfetch($result4); if($row4["count"]==0) { delete_graph($row3["graphid"]); info("Deleted graph from linked host ".$host["host"]); } } } function navigation_bar_calc() { $workingperiod = 3600; if(!isset($_REQUEST["period"])) $_REQUEST["period"]=3600; if(!isset($_REQUEST["from"])) $_REQUEST["from"]=0; if(isset($_REQUEST["inc"])) $workingperiod= $_REQUEST["period"]+$_REQUEST["inc"]; if(isset($_REQUEST["dec"])) $workingperiod= $workingperiod-$_REQUEST["dec"]; //if(isset($_REQUEST["inc"])) $_REQUEST["period"]= $_REQUEST["period"]+$_REQUEST["inc"]; //if(isset($_REQUEST["dec"])) $_REQUEST["period"]= $_REQUEST["period"]-$_REQUEST["dec"]; if(isset($_REQUEST["left"])) $_REQUEST["from"]= $_REQUEST["from"]+$_REQUEST["left"]; if(isset($_REQUEST["right"])) $_REQUEST["from"]= $_REQUEST["from"]-$_REQUEST["right"]; //unset($_REQUEST["inc"]); //unset($_REQUEST["dec"]); unset($_REQUEST["left"]); unset($_REQUEST["right"]); if($_REQUEST["from"]<=0) $_REQUEST["from"]=0; if($_REQUEST["period"]<=0) $_REQUEST["period"]=3600; if(isset($_REQUEST["reset"])) { $_REQUEST["period"]=3600; $_REQUEST["from"]=0; $workingperiod=3600; } return $workingperiod; } function navigation_bar($url) { $h1=S_NAVIGATE; $h2=S_PERIOD." "; $h2=$h2.""; $h2=$h2.""; $h2=$h2.""; $h2=$h2." ".S_MOVE." "; $h2=$h2.""; $h2=$h2.""; $h2=$h2." "; $h2=$h2.""; $h2=$h2." "; $h2=$h2.""; $h2=$h2.""; if(isset($_REQUEST["graphid"])&&($_REQUEST["graphid"]!=0)) { $h2=$h2.""; } if(isset($_REQUEST["screenid"])&&($_REQUEST["screenid"]!=0)) { $h2=$h2.""; } if(isset($_REQUEST["itemid"])&&($_REQUEST["itemid"]!=0)) { $h2=$h2.""; } if(isset($_REQUEST["action"])) { $h2=$h2.""; } if(isset($_REQUEST["from"])) { $h2=$h2.""; } if(isset($_REQUEST["fullscreen"])) { $h2=$h2.""; } show_header2($h1,$h2,"
"); return; echo "| ";
echo " ";
echo "".S_PERIOD.": ";
$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 "] ";
}
echo(" ");
echo " | ";
echo ""; echo "".nbsp(S_KEEP_PERIOD).": "; if($_REQUEST["keep"] == 1) { echo("[".S_ON_C."]"); } else { echo("[".S_OFF_C."]"); } echo " | "; echo "
| ";
if(isset($_REQUEST["stime"]))
{
echo " " ;
echo "".S_MOVE.": " ;
$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 "] ";
}
echo(" ");
}
else
{
echo "";
echo "".S_MOVE.": ";
$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 "] ";
}
echo(" ");
}
echo " | ";
echo ""; echo ""; echo " | "; echo "