summaryrefslogtreecommitdiffstats
path: root/frontends
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2002-09-08 11:30:16 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2002-09-08 11:30:16 +0000
commit3320cc1223ca948a495463d4881197e681260b82 (patch)
tree1570e143c81148b14074874fad5e43b082f0fc83 /frontends
parentdcafb4317aa97aaad0bd47b79cc94c21fb2cd5fb (diff)
downloadzabbix-3320cc1223ca948a495463d4881197e681260b82.tar.gz
zabbix-3320cc1223ca948a495463d4881197e681260b82.tar.xz
zabbix-3320cc1223ca948a495463d4881197e681260b82.zip
- availability graph for IT Services (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@488 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends')
-rw-r--r--frontends/php/chart4.php2
-rw-r--r--frontends/php/chart5.php195
-rw-r--r--frontends/php/include/config.inc.php98
-rw-r--r--frontends/php/srv_status.php17
4 files changed, 311 insertions, 1 deletions
diff --git a/frontends/php/chart4.php b/frontends/php/chart4.php
index adf79d01..e4ee1a07 100644
--- a/frontends/php/chart4.php
+++ b/frontends/php/chart4.php
@@ -32,7 +32,7 @@
}
$sizeX=900;
- $sizeY=200;
+ $sizeY=300;
$shiftX=12;
$shiftYup=17;
diff --git a/frontends/php/chart5.php b/frontends/php/chart5.php
new file mode 100644
index 00000000..f25d0b65
--- /dev/null
+++ b/frontends/php/chart5.php
@@ -0,0 +1,195 @@
+<?
+ include "include/config.inc.php";
+
+# PARAMETERS:
+
+# itemid
+# type
+
+ $start_time=time(NULL);
+
+ if(!isset($HTTP_GET_VARS["type"]))
+ {
+ $HTTP_GET_VARS["type"]="week";
+ }
+
+ if($HTTP_GET_VARS["type"] == "month")
+ {
+ $period=30*24*3600;
+ }
+ else if($HTTP_GET_VARS["type"] == "week")
+ {
+ $period=7*24*3600;
+ }
+ else if($HTTP_GET_VARS["type"] == "year")
+ {
+ $period=365*24*3600;
+ }
+ else
+ {
+ $period=7*24*3600;
+ $type="week";
+ }
+
+ $sizeX=900;
+ $sizeY=300;
+
+ $shiftX=12;
+ $shiftYup=17;
+ $shiftYdown=25+15*3;
+
+
+// Header( "Content-type: text/html");
+ Header( "Content-type: image/png");
+ Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT");
+
+ check_authorisation();
+
+ $im = imagecreate($sizeX+$shiftX+61,$sizeY+$shiftYup+$shiftYdown+10);
+
+ $red=ImageColorAllocate($im,255,0,0);
+ $darkred=ImageColorAllocate($im,150,0,0);
+ $green=ImageColorAllocate($im,0,255,0);
+ $darkgreen=ImageColorAllocate($im,0,150,0);
+ $blue=ImageColorAllocate($im,0,0,255);
+ $darkblue=ImageColorAllocate($im,0,0,150);
+ $yellow=ImageColorAllocate($im,255,255,0);
+ $darkyellow=ImageColorAllocate($im,150,150,0);
+ $cyan=ImageColorAllocate($im,0,255,255);
+ $black=ImageColorAllocate($im,0,0,0);
+ $gray=ImageColorAllocate($im,150,150,150);
+ $white=ImageColorAllocate($im,255,255,255);
+ $bg=ImageColorAllocate($im,6+6*16,7+7*16,8+8*16);
+
+ $x=imagesx($im);
+ $y=imagesy($im);
+
+// ImageFilledRectangle($im,0,0,$sizeX+$shiftX+61,$sizeY+$shiftYup+$shiftYdown+10,$white);
+ ImageFilledRectangle($im,0,0,$x,$y,$white);
+ ImageRectangle($im,0,0,$x-1,$y-1,$black);
+
+// if(!check_right_on_trigger("R",$HTTP_GET_VARS["triggerid"]))
+// {
+// ImagePng($im);
+// ImageDestroy($im);
+// exit;
+// }
+
+
+ $service=get_service_by_serviceid($HTTP_GET_VARS["serviceid"]);
+
+ $str=$service["name"]." (year ".date("Y").")";
+ $x=imagesx($im)/2-ImageFontWidth(4)*strlen($str)/2;
+ ImageString($im, 4,$x,1, $str , $darkred);
+
+ $now = time(NULL);
+ $to_time=$now;
+ $from_time=$to_time-$period;
+ $from_time_now=$to_time-24*3600;
+
+ $count_now=array();
+ $true=array();
+ for($i=0;$i<52;$i++)
+ {
+ $year=date("Y");
+ $period_start=mktime(0,0,0,1,1,$year)+7*24*3600*$i;
+ $period_end=mktime(0,0,0,1,1,$year)+7*24*3600*($i+1);
+ $stat=calculate_service_availability($HTTP_GET_VARS["serviceid"],$period_start,$period_end);
+
+ $true[$i]=$stat["true"];
+ $false[$i]=$stat["false"];
+ $count_now[$i]=1;
+ }
+
+ for($i=0;$i<=$sizeY;$i+=$sizeY/10)
+ {
+ ImageDashedLine($im,$shiftX,$i+$shiftYup,$sizeX+$shiftX,$i+$shiftYup,$gray);
+ }
+
+ $j=0;
+ for($i=0;$i<=$sizeX;$i+=$sizeX/52)
+ {
+ ImageDashedLine($im,$i+$shiftX,$shiftYup,$i+$shiftX,$sizeY+$shiftYup,$gray);
+ $period_start=mktime(0,0,0,1,1,$year)+7*24*3600*$j;
+ ImageStringUp($im, 1,$i+$shiftX-4, $sizeY+$shiftYup+32, date("d.M",$period_start) , $black);
+ $j++;
+ }
+
+ $maxY=100;
+ $tmp=max($true);
+ if($tmp>$maxY)
+ {
+ $maxY=$tmp;
+ }
+ $minY=0;
+
+ $maxX=900;
+ $minX=0;
+
+ for($i=1;$i<52;$i++)
+ {
+ $x1=(900/52)*$sizeX*($i-$minX)/($maxX-$minX);
+ $y1=$sizeY*($true[$i]-$minY)/($maxY-$minY);
+ $x2=(900/52)*$sizeX*($i-$minX-1)/($maxX-$minX);
+ $y2=$sizeY*($true[$i-1]-$minY)/($maxY-$minY);
+ $y1=$sizeY-$y1;
+ $y2=$sizeY-$y2;
+
+ ImageLine($im,$x1+$shiftX,$y1+$shiftYup,$x2+$shiftX,$y2+$shiftYup,$darkred);
+
+ ImageRectangle($im,$x1+$shiftX-1,$y1+$shiftYup-1,$x1+$shiftX+1,$y1+$shiftYup+1,$darkred);
+ ImageRectangle($im,$x2+$shiftX-1,$y2+$shiftYup-1,$x2+$shiftX+1,$y2+$shiftYup+1,$darkred);
+
+ $x1=(900/52)*$sizeX*($i-$minX)/($maxX-$minX);
+ $y1=$sizeY*($false[$i]-$minY)/($maxY-$minY);
+ $x2=(900/52)*$sizeX*($i-$minX-1)/($maxX-$minX);
+ $y2=$sizeY*($false[$i-1]-$minY)/($maxY-$minY);
+ $y1=$sizeY-$y1;
+ $y2=$sizeY-$y2;
+
+ ImageLine($im,$x1+$shiftX,$y1+$shiftYup,$x2+$shiftX,$y2+$shiftYup,$darkgreen);
+
+ ImageRectangle($im,$x1+$shiftX-1,$y1+$shiftYup-1,$x1+$shiftX+1,$y1+$shiftYup+1,$darkgreen);
+ ImageRectangle($im,$x2+$shiftX-1,$y2+$shiftYup-1,$x2+$shiftX+1,$y2+$shiftYup+1,$darkgreen);
+
+/*
+ $x1=(900/52)*$sizeX*($i-$minX)/($maxX-$minX);
+ $y1=$sizeY*($unknown[$i]-$minY)/($maxY-$minY);
+ $x2=(900/52)*$sizeX*($i-$minX-1)/($maxX-$minX);
+ $y2=$sizeY*($unknown[$i-1]-$minY)/($maxY-$minY);
+ $y1=$sizeY-$y1;
+ $y2=$sizeY-$y2;
+
+ ImageLine($im,$x1+$shiftX,$y1+$shiftYup,$x2+$shiftX,$y2+$shiftYup,$darkyellow);
+
+ ImageRectangle($im,$x1+$shiftX-1,$y1+$shiftYup-1,$x1+$shiftX+1,$y1+$shiftYup+1,$darkyellow);
+ ImageRectangle($im,$x2+$shiftX-1,$y2+$shiftYup-1,$x2+$shiftX+1,$y2+$shiftYup+1,$darkyellow);*/
+
+# ImageStringUp($im, 1, $x1+10, $sizeY+$shiftYup+15, $i , $red);
+ }
+
+ for($i=0;$i<=$sizeY;$i+=$sizeY/10)
+ {
+ ImageString($im, 1, $sizeX+5+$shiftX, $sizeY-$i-4+$shiftYup, $i*($maxY-$minY)/$sizeY+$minY , $darkred);
+ }
+
+ ImageFilledRectangle($im,$shiftX,$sizeY+$shiftYup+39+15*0,$shiftX+5,$sizeY+$shiftYup+35+9+15*0,$darkgreen);
+ ImageRectangle($im,$shiftX,$sizeY+$shiftYup+39+15*0,$shiftX+5,$sizeY+$shiftYup+35+9+15*0,$black);
+ ImageString($im, 2,$shiftX+9,$sizeY+$shiftYup+15*0+35, "OK (%)", $black);
+
+ ImageFilledRectangle($im,$shiftX,$sizeY+$shiftYup+39+15*1,$shiftX+5,$sizeY+$shiftYup+35+9+15*1,$darkred);
+ ImageRectangle($im,$shiftX,$sizeY+$shiftYup+39+15*1,$shiftX+5,$sizeY+$shiftYup+15+9+35*1,$black);
+ ImageString($im, 2,$shiftX+9,$sizeY+$shiftYup+15*1+35, "PROBLEMS (%)", $black);
+
+// ImageFilledRectangle($im,$shiftX,$sizeY+$shiftYup+39+15*2,$shiftX+5,$sizeY+$shiftYup+35+9+15*2,$darkyellow);
+// ImageRectangle($im,$shiftX,$sizeY+$shiftYup+39+15*2,$shiftX+5,$sizeY+$shiftYup+35+9+15*2,$black);
+// ImageString($im, 2,$shiftX+9,$sizeY+$shiftYup+15*2+35, "UNKNOWN (%)", $black);
+
+ ImageStringUp($im,0,imagesx($im)-10,imagesy($im)-50, "http://zabbix.sourceforge.net", $gray);
+
+ $end_time=time(NULL);
+ ImageString($im, 0,imagesx($im)-100,imagesy($im)-12,"Generated in ".($end_time-$start_time)." sec", $gray);
+
+ ImagePng($im);
+ ImageDestroy($im);
+?>
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index d0ec02a5..5b54d2a7 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -3475,6 +3475,104 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid";
return $stat;
}
+ function calculate_service_availability($serviceid,$period_start,$period_end)
+ {
+ $sql="select count(*),min(clock),max(clock) from service_alarms where serviceid=$serviceid and clock>=$period_start and clock<=$period_end";
+
+ $result=DBselect($sql);
+ if(DBget_field($result,0,0)>0)
+ {
+ $min=DBget_field($result,0,1);
+ $max=DBget_field($result,0,2);
+ }
+ else
+ {
+ $ret["true_time"]=0;
+ $ret["false_time"]=1;
+ $ret["true"]=0;
+ $ret["false"]=100;
+ return $ret;
+ }
+
+ $sql="select clock,value from service_alarms where serviceid=$serviceid and clock>=$min and clock<=$max";
+// echo " $sql<br>";
+ $result=DBselect($sql);
+
+// echo $sql,"<br>";
+
+// -1,0,1
+ $state=-1;
+ $true_time=0;
+ $false_time=0;
+ $time=$min;
+ for($i=0;$i<DBnum_rows($result);$i++)
+ {
+ $clock=DBget_field($result,$i,0);
+ $value=DBget_field($result,$i,1);
+
+ $diff=$clock-$time;
+
+ $time=$clock;
+#state=0,1 (FALSE), >1 TRUE
+
+ if($state==-1)
+ {
+ $state=$value;
+ if($state <= 1)
+ {
+ $true_time+=$diff;
+ }
+ else
+ {
+ $false_time+=$diff;
+ }
+ }
+ else if($state<=1)
+ {
+ $true_time+=$diff;
+ $state=$value;
+ }
+ else
+ {
+ $false_time+=$diff;
+ $state=$value;
+ }
+ }
+
+ if(DBnum_rows($result)==0)
+ {
+ $false_time=$max-$min;
+ }
+ else
+ {
+ if($state<=1)
+ {
+ $false_time=$false_time+$max-$time;
+ }
+ else
+ {
+ $true_time=$true_time+$max-$time;
+ }
+ }
+
+ $total_time=$true_time+$false_time;
+ if($total_time==0)
+ {
+ $ret["true_time"]=0;
+ $ret["false_time"]=0;
+ $ret["true"]=0;
+ $ret["false"]=0;
+ }
+ else
+ {
+ $ret["true_time"]=$true_time;
+ $ret["false_time"]=$false_time;
+ $ret["true"]=(100*$true_time)/$total_time;
+ $ret["false"]=(100*$false_time)/$total_time;
+ }
+ return $ret;
+ }
+
// If $period_start=$period_end=0, then take maximum period
function calculate_availability($triggerid,$period_start,$period_end)
{
diff --git a/frontends/php/srv_status.php b/frontends/php/srv_status.php
index 000d3a78..90769ba6 100644
--- a/frontends/php/srv_status.php
+++ b/frontends/php/srv_status.php
@@ -9,6 +9,20 @@
<?
show_table_header("IT SERVICES");
+ if(isset($HTTP_GET_VARS["serviceid"])&&isset($HTTP_GET_VARS["showgraph"]))
+ {
+ echo "<TABLE BORDER=0 COLS=4 align=center WIDTH=100% BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>";
+ echo "<TR BGCOLOR=#EEEEEE>";
+ echo "<TR BGCOLOR=#DDDDDD>";
+ echo "<TD ALIGN=CENTER>";
+ echo "<IMG SRC=\"chart5.php?serviceid=".$HTTP_GET_VARS["serviceid"]."\" border=0>";
+ echo "</TD>";
+ echo "</TR>";
+ echo "</TABLE>";
+ show_footer();
+ exit;
+ }
+
$now=time();
$result=DBselect("select serviceid,name,triggerid,status from services order by name");
echo "<table border=0 width=100% bgcolor='#CCCCCC' cellspacing=1 cellpadding=3>";
@@ -17,6 +31,7 @@
echo "<td><b>Service</b></td>";
echo "<td width=10%><b>Status</b></td>";
echo "<td width=30%><b>Reason</b></td>";
+ echo "<td width=5%><b>Graph</b></td>";
echo "</tr>";
echo "\n";
$col=0;
@@ -27,6 +42,7 @@
echo "<td><b><a href=\"srv_status.php?serviceid=".$service["serviceid"]."\">".$service["name"]."</a></b></td>";
echo "<td>".get_service_status_description($service["status"])."</td>";
echo "<td>&nbsp;</td>";
+ echo "<td>-</td>";
echo "</tr>";
$col++;
}
@@ -116,6 +132,7 @@
}
echo "</td>";
}
+ echo "<td><a href=\"srv_status.php?serviceid=".$row["serviceid"]."&showgraph=1\">Show</a></td>";
echo "</tr>";
}
echo "</table>";