eblevins
26-07-2007, 17:23
I created two patches for 1.4.1 that allow me to select weekly or monthly SLA graphs, this is my first edit to the zabbix code so hopefully there are no bugs :)
diff -uNr zabbix-1.4.1.orig/frontends/php/srv_status.php zabbix-1.4.1/frontends/php/srv_status.php
--- zabbix-1.4.1.orig/frontends/php/srv_status.php 2007-07-26 10:17:33.000000000 -0400
+++ zabbix-1.4.1/frontends/php/srv_status.php 2007-07-26 10:17:20.000000000 -0400
@@ -34,10 +34,18 @@
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields=array(
"serviceid"=> array(T_ZBX_INT, O_OPT, P_SYS|P_NZERO, DB_ID, NULL),
- "showgraph"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("1")."isset({serviceid})",NULL)
+ "showgraph"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("1")."isset({serviceid})",NULL),
+ "period"=> array(T_ZBX_STR, O_OPT, null, IN('"dayly","weekly","monthly","yearly"'), NULL),
+ "year"=> array(T_ZBX_INT, O_OPT, null, null, NULL)
+
);
check_fields($fields);
+ $period = get_request("period", "weekly");
+ $year = get_request("year", date("Y"));
+ $serviceid=get_request("serviceid");
+ define("YEAR_LEFT_SHIFT", 5);
+
?>
<?php
$denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_RE AD_ONLY,PERM_MODE_LT);
@@ -57,13 +65,35 @@
unset($_REQUEST["serviceid"]);
?>
<?php
- show_table_header(S_IT_SERVICES_BIG);
+ $form = new CForm();
+ $form->AddVar("serviceid", $serviceid);
+ $form->AddVar("showgraph",1);
+ $cmbPeriod = new CComboBox("period", $period, "submit();");
+ $cmbPeriod->AddItem("weekly",S_WEEKLY);
+ $cmbPeriod->AddItem("monthly",S_MONTHLY);
+ $form->AddItem(array(SPACE.S_PERIOD.SPACE, $cmbPeriod));
+
+ $cmbYear = new CComboBox("year", $year, "submit();");
+ for($y = (date("Y") - YEAR_LEFT_SHIFT); $y <= date("Y"); $y++)
+ {
+ $cmbYear->AddItem($y, $y);
+ }
+ $form->AddItem(array(SPACE.S_YEAR.SPACE, $cmbYear));
+
if(isset($service)&&isset($_REQUEST["showgraph"])){
+ show_table_header(array(S_IT_SERVICES_BIG,
+ SPACE."\"",
+ new CLink($service["name"],"srv_status.php?serviceid=".$service["serviceid"]),
+ "\""
+ ),
+ $form);
+
$table = new CTable(null,'chart');
- $table->AddRow(new CImg("chart5.php?serviceid=".$service["serviceid"].url_param('path')));
+ $table->AddRow(new CImg("chart5.php?serviceid=".$service["serviceid"].url_param('path')."&period=".$period."&year=".$year));
$table->Show();
} else {
+ show_table_header(S_IT_SERVICES_BIG);
$query = 'SELECT DISTINCT s.serviceid, sl.servicedownid, sl_p.serviceupid as serviceupid, s.triggerid, '.
' s.name as caption, s.algorithm, t.description, s.sortorder, sl.linkid, s.showsla, s.goodsla, s.status '.
diff -uNr zabbix-1.4.1.orig/frontends/php/chart5.php zabbix-1.4.1/frontends/php/chart5.php
--- zabbix-1.4.1.orig/frontends/php/chart5.php 2007-07-26 10:17:33.000000000 -0400
+++ zabbix-1.4.1/frontends/php/chart5.php 2007-07-26 10:17:20.000000000 -0400
@@ -19,6 +19,9 @@
**/
?>
<?php
+ //Start output buffer so we do not do chunked encoding
+ ob_start();
+
require_once "include/config.inc.php";
require_once "include/services.inc.php";
@@ -32,10 +35,18 @@
<?php
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields=array(
- "serviceid"=> array(T_ZBX_INT, O_MAND,P_SYS, DB_ID, NULL)
+ "serviceid"=> array(T_ZBX_INT, O_MAND,P_SYS, DB_ID, NULL),
+ "period"=> array(T_ZBX_STR, O_OPT, null, IN('"dayly","weekly","monthly","yearly"'), NULL),
+ "year"=> array(T_ZBX_INT, O_OPT, null, null, NULL)
+
);
check_fields($fields);
+ $period = get_request("period", "weekly");
+ $year = get_request("year", date("Y"));
+
+ define("YEAR_LEFT_SHIFT", 5);
+
?>
<?php
$denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_RE AD_ONLY,PERM_MODE_LT);
@@ -52,6 +63,36 @@
?>
<?php
$start_time = time(NULL);
+ switch($period)
+ {
+ case "monthly":
+ $from = 0;
+ $to = 13;
+ array_unshift($header, new CCol(S_MONTH,"center"));
+ function get_time($m) { global $year; return mktime(0,0,0,$m,1,$year); }
+ function format_time($t){ return date("M Y",$t); }
+ function format_time2($t){ return null; };
+ break;
+ case "weekly":
+ default:
+ $from = 0;
+ $to = 52;
+ array_unshift($header,new CCol(S_FROM,"center"),new CCol(S_TILL,"center"));
+ function get_time($w) {
+ global $year;
+
+ $time = mktime(0,0,0,1, 1, $year);
+ $wd = date("w", $time);
+ $wd = $wd == 0 ? 6 : $wd - 1;
+
+ return ($time + ($w*7 - $wd)*24*3600);
+ }
+ function format_time($t){ return date("d M Y H:i",$t); }
+ function format_time2($t){ return format_time($t); };
+ break;
+
+ }
+
$sizeX=900;
$sizeY=300;
@@ -82,7 +123,7 @@
ImageFilledRectangle($im,0,0,$x,$y,$white);
ImageRectangle($im,0,0,$x-1,$y-1,$black);
- $str=$service["name"]." (year ".date("Y").")";
+ $str=$service["name"]." (year ".date($year).")";
$x=imagesx($im)/2-ImageFontWidth(4)*strlen($str)/2;
ImageString($im, 4,$x,1, $str , $darkred);
@@ -92,64 +133,74 @@
$count_now=array();
$problem=array();
- $year=date("Y");
- $start=mktime(0,0,0,1,1,$year);
-
- $wday=date("w",$start);
- if($wday==0) $wday=7;
- $start=$start-($wday-1)*24*3600;
-
- for($i=0;$i<52;$i++)
+ for($i = $from; $i <= $to; $i++)
{
- if(($period_start=$start+7*24*3600*$i) > time())
- break;
-
- if(($period_end=$start+7*24*3600*($i+1)) > time())
- $period_end = time();
+ if(($start = get_time($i)) > time())
+ break;
- $stat = calculate_service_availability($_REQUEST["serviceid"],$period_start,$period_end);
+ if(($end = get_time($i+1)) > time())
+ $end = time();
+
+ $stat = calculate_service_availability($_REQUEST["serviceid"],$start,$end);
$problem[$i]=$stat["problem"];
$ok[$i]=$stat["ok"];
$count_now[$i]=1;
}
-
for($i=0;$i<=$sizeY;$i+=$sizeY/10)
{
DashedLine($im,$shiftX,$i+$shiftYup,$sizeX+$shiftX ,$i+$shiftYup,$gray);
}
for(
- $i = 0, $period_start = $start;
+ $i = 0;
$i <= $sizeX;
- $i += $sizeX/52, $period_start += 7*24*3600
+ $i += $sizeX/$to
)
{
DashedLine($im,$i+$shiftX,$shiftYup,$i+$shiftX,$si zeY+$shiftYup,$gray);
- ImageStringUp($im, 1,$i+$shiftX-4, $sizeY+$shiftYup+32, date("d.M",$period_start) , $black);
+ switch($period)
+ {
+ case "monthly":
+ ImageStringUp($im, 1,$i+$shiftX-4, $sizeY+$shiftYup+32, date("M y",get_time($i/($sizeX/$to))) , $black);
+ break;
+ case "weekly":
+ default:
+ ImageStringUp($im, 1,$i+$shiftX-4, $sizeY+$shiftYup+32, date("d.M",get_time($i/($sizeX/$to))) , $black);
+ break;
+ }
+
}
+
+
+
$maxY = max(max($problem), 100);
$minY = 0;
$maxX = 900;
$minX = 0;
- for($i=1;$i<=52;$i++)
+ for($i = $from ; $i <= $to; $i++)
{
if(!isset($ok[$i-1])) continue;
- $x2=(900/52)*$sizeX*($i-$minX-1)/($maxX-$minX);
+ $x2=(900/$to)*$sizeX*($i-$minX-1)/($maxX-$minX);
$y2=$sizeY*($ok[$i-1]-$minY)/($maxY-$minY);
$y2=$sizeY-$y2;
ImageFilledRectangle($im,$x2+$shiftX,$y2+$shiftYup ,$x2+$shiftX+8,$sizeY+$shiftYup,ImageColorAllocate ($im,120,200,120));
ImageRectangle($im,$x2+$shiftX,$y2+$shiftYup,$x2+$ shiftX+8,$sizeY+$shiftYup,$black);
-// Doesn't work for some reason
+ // Doesn't work for some reason
ImageFilledRectangle($im,$x2+$shiftX,$shiftYup,$x2 +$shiftX+8,$y2+$shiftYup,ImageColorAllocate($im,20 0,120,120));
ImageRectangle($im,$x2+$shiftX,$shiftYup,$x2+$shif tX+8,$y2+$shiftYup,$black);
+ #Add uptime percentage to the graph
+ $text = number_format($ok[$i-1],2,'.','')."% uptime";
+ if (strlen($text) < 14) {
+ $text = " ".$text;
+ }
+ ImageStringUp($im, 1,$x2+$shiftX,$y2+$sizeY, $text, $black);
}
-
for($i=0;$i<=$sizeY;$i+=$sizeY/10)
{
ImageString($im, 1, $sizeX+5+$shiftX, $sizeY-$i-4+$shiftYup, ($i*($maxY-$minY)/$sizeY+$minY)."%" , ImageColorAllocate($im,200,120,120));
@@ -170,6 +221,10 @@
ImageOut($im);
ImageDestroy($im);
+ //Set header content-length before flushing the output buffer
+ header('Content-Length: '.strlen(ob_get_contents()));
+ //Flush the output buffer
+ ob_end_flush();
?>
<?php