diff -ruN zabbix-1.6.2/frontends/php/chart8.php zabbix/chart8.php --- zabbix-1.6.2/frontends/php/chart8.php 1970-01-01 01:00:00.000000000 +0100 +++ zabbix/chart8.php 2009-03-18 12:11:35.000000000 +0100 @@ -0,0 +1,192 @@ + + + array(T_ZBX_INT, O_MAND,P_SYS, DB_ID, NULL), + 'year'=> array(T_ZBX_INT, O_OPT, P_UNSET_EMPTY, null, NULL) + ); + + check_fields($fields); + $year = get_request("year", date('Y')); +?> + + time()) + break; + + // Need to determine date in + $period_tmp=mktime(0,0,0,$i,1,$year); + $period_end=mktime(0,0,0,$i+1,1,$year); + + if($period_end > time()) + $period_end = time(); + + $from = date("H:i:s d-m-Y", $period_start); + $to = date("H:i:s d-m-Y", $period_end); + + $string = "From: " . $from . " To: " . $to . "\n"; + file_put_contents('/tmp/sla.txt', $string , FILE_APPEND); + + $stat = calculate_service_availability($_REQUEST['serviceid'],$period_start,$period_end); + $problem[$i]=$stat['problem']; + $ok[$i]=$stat['ok']; + $count_now[$i]=1; + } + + # Draw dashed lines horizontal + for($i=0;$i<=$sizeY;$i+=$sizeY/10){ + DashedLine($im,$shiftX,$i+$shiftYup,$sizeX+$shiftX,$i+$shiftYup,$gray); + } + + # Draw dashed lines vertical, and labels + for($i = 0, $step=1;$i <= $sizeX;$i += $sizeX/12, $step++){ + DashedLine($im,$i+$shiftX,$shiftYup,$i+$shiftX,$sizeY+$shiftYup,$gray); + if($step<=12) + imagestringup($im, 1,$i+$shiftX+30, $sizeY+$shiftYup+26, date("M", mktime(0,0,0,$step,1,$year)) , $black); + } + + $maxY = max(max($problem), 100); + $minY = 0; + + $maxX = 900; + $minX = 0; + + for($i=1;$i<=12;$i++){ + if(!isset($ok[$i])) continue; + $x2=($sizeX/12)*($i-1-$minX)*$sizeX/($maxX-$minX); + + $y2=$sizeY*($ok[$i]-$minY)/($maxY-$minY); + $y2=$sizeY-$y2; + + imagefilledrectangle($im,$x2+$shiftX+18,$y2+$shiftYup,$x2+$shiftX+18+35,$sizeY+$shiftYup,imagecolorallocate($im,120,235,120)); + imagerectangle ($im,$x2+$shiftX+18,$y2+$shiftYup,$x2+$shiftX+18+35,$sizeY+$shiftYup,$black); + + imagefilledrectangle($im,$x2+$shiftX+18,$shiftYup,$x2+$shiftX+18+35,$y2+$shiftYup,imagecolorallocate($im,235,120,120)); + imagerectangle ($im,$x2+$shiftX+18,$shiftYup,$x2+$shiftX+18+35,$y2+$shiftYup,$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,40,40)); + } + + // GOOD SLA LINE + $goodsla=$service['goodsla']; + // Calculate Y + $slaYoffset = $sizeY-($sizeY*($goodsla/100)); + DashedLine($im, $shiftX, $shiftYup+$slaYoffset, $sizeX+$shiftX, $shiftYup+$slaYoffset, $red); + + + imagefilledrectangle($im,$shiftX,$sizeY+$shiftYup+39+15*0,$shiftX+5,$sizeY+$shiftYup+35+9+15*0,imagecolorallocate($im,120,235,120)); + 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); + + imagestringup($im,0,imagesx($im)-10,imagesy($im)-50, 'http://www.zabbix.com', $gray); + + $end_time=time(NULL); + imagestring($im, 0,imagesx($im)-100,imagesy($im)-12,'Generated in '.($end_time-$start_time).' sec', $gray); + + ImageOut($im); + imagedestroy($im); +?> + diff -ruN zabbix-1.6.2/frontends/php/chart_sla2.php zabbix/chart_sla2.php --- zabbix-1.6.2/frontends/php/chart_sla2.php 1970-01-01 01:00:00.000000000 +0100 +++ zabbix/chart_sla2.php 2009-03-18 11:30:44.000000000 +0100 @@ -0,0 +1,115 @@ + + + array(T_ZBX_INT, O_OPT, P_UNSET_EMPTY, null, NULL), + 'month'=> array(T_ZBX_INT, O_OPT, P_UNSET_EMPTY, null, NULL), + "serviceid"=> array(T_ZBX_INT, O_MAND,P_SYS, DB_ID, null) + ); + + check_fields($fields); + + /* Date/year conversion */ + $year = get_request("year", date('Y')); + $month = get_request("month",date('n')); +?> + +time()) + $period_end=time(); + + $stat=calculate_service_availability($_REQUEST["serviceid"],$period_start,$period_end); + + $problem=$stat["problem"]; + $ok=$stat["ok"]; + +// Percentage to show + $percentage = 20; + + $p=min($problem,$percentage); + $g=max($service["goodsla"]-(100 - $percentage),0); + + ImageFilledRectangle($im,$sizeX-$sizeX*$p/$percentage,1,$sizeX-2,$sizeY-2,ImageColorAllocate($im,200,120,120)); + ImageLine($im,$sizeX*$g/$percentage,1,$sizeX*$g/$percentage,$sizeY-1,$yellow); + + ImageRectangle($im,0,0,$sizeX-1,$sizeY-1,$black); + + $s=sprintf("%2.3f%%",$ok); + ImageString($im, 2,1,1, $s , $white); + $s=sprintf("%2.3f%%", $problem); + ImageString($im, 2,$sizeX-49,1, $s , $white); + ImageOut($im); + ImageDestroy($im); + +include_once "include/page_footer.php"; + +?> diff -ruN zabbix-1.6.2/frontends/php/include/page_header.php zabbix/include/page_header.php --- zabbix-1.6.2/frontends/php/include/page_header.php 2009-01-16 13:19:05.000000000 +0100 +++ zabbix/include/page_header.php 2009-03-17 17:41:05.000000000 +0100 @@ -157,6 +157,12 @@ 'forse_disable_subnodes' => true, 'sub_pages'=>array('report3.php','report7.php','chart_sla.php','chart5.php') ), + array( + 'url'=>'srv_status2.php', + 'label'=>S_IT_SERVICES. ' (new)', + 'forse_disable_subnodes' => true, + 'sub_pages'=>array('chart8.php') + ), array('url'=>'vtext.php'), array('url'=>'chart3.php') ) @@ -600,4 +606,4 @@ } show_messages(); -?> \ No newline at end of file +?> diff -ruN zabbix-1.6.2/frontends/php/srv_status2.php zabbix/srv_status2.php --- zabbix-1.6.2/frontends/php/srv_status2.php 1970-01-01 01:00:00.000000000 +0100 +++ zabbix/srv_status2.php 2009-03-19 12:40:23.000000000 +0100 @@ -0,0 +1,297 @@ + + + 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})'), + 'fullscreen'=> array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), NULL), + 'year'=> array(T_ZBX_INT, O_OPT, P_UNSET_EMPTY, null, NULL), + 'month'=> array(T_ZBX_INT, O_OPT, P_UNSET_EMPTY, null, NULL), +// ajax + 'favobj'=> array(T_ZBX_STR, O_OPT, P_ACT, IN('"hat"'), NULL), + 'favid'=> array(T_ZBX_STR, O_OPT, P_ACT, NOT_EMPTY, 'isset({favobj})'), + 'state'=> array(T_ZBX_INT, O_OPT, P_ACT, NOT_EMPTY, 'isset({favobj})'), + ); + + check_fields($fields); + + +/* Date/year conversion */ + $year = get_request("year", date('Y')); + $month = get_request("month",date('n')); + +/* Minimal year in database */ +# select min(clock) from service_alarms + $result = DBSelect("select min(clock) as minclock from service_alarms"); + $row = DBFetch($result); + $minyear= date("Y",$row['minclock']); +/* AJAX */ + if(isset($_REQUEST['favobj'])){ + if('hat' == $_REQUEST['favobj']){ + update_profile('web.srv_status.hats.'.$_REQUEST['favid'].'.state',$_REQUEST['state'],PROFILE_TYPE_INT); + } + } + + if((PAGE_TYPE_JS == $page['type']) || (PAGE_TYPE_HTML_BLOCK == $page['type'])){ + exit(); + } + + + + $text = "Year"; + $form = new CForm(); + $form->SetMethod('get'); + + $form->AddVar("fullscreen",$_REQUEST["fullscreen"]); + + $cmbYear = new CComboBox("year",$year,"submit()"); + for($i=$minyear;$i<=date('Y');$i++) + { + $cmbYear->AddItem($i, $i); + } + + $cmbMonth = new CComboBox("month",$month,"submit()"); + if($yearAddItem($i, date('F',mktime(1,1,1,$i,1,$year))); + } + + + $form->AddItem($cmbYear); + $form->AddItem($cmbMonth); + + $from='1/'.$month.'/'.$year; + $to =date('t',mktime(1,1,1,$month,1,$year)).'/'.$month.'/'.$year; + $HeaderTitle=S_TIME_PERIOD . " (" . $from . " - " . $to . ")"; + $menu = get_table_header($HeaderTitle,$form); + +//-------- + + if(isset($_REQUEST['serviceid']) && + ($_REQUEST['serviceid']>0) && + !DBfetch(DBselect('select serviceid from services where serviceid='.$_REQUEST['serviceid']))) + { + unset($_REQUEST['serviceid']); + } + + $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY); + $available_triggers = get_accessible_triggers(PERM_READ_ONLY,PERM_RES_IDS_ARRAY); + + if(isset($_REQUEST["serviceid"]) && $_REQUEST["serviceid"] > 0){ + $sql = 'SELECT s.serviceid '. + ' FROM services s '. + ' WHERE (s.triggerid is NULL OR '.DBcondition('s.triggerid',$available_triggers).') '. + ' AND s.serviceid='.$_REQUEST['serviceid']; + + if(!$service = DBfetch(DBselect($sql,1))){ + access_deny(); + } + } + unset($_REQUEST['serviceid']); + +// show_table_header(S_IT_SERVICES_BIG); + if(isset($service)&&isset($_REQUEST['showgraph'])){ + $table = new CTable(null,'chart'); + $table->AddRow(new CImg('chart8.php?serviceid='.$service['serviceid'].'&year='.$year.url_param('path'))); + $table->Show(); + } + else { + $query = 'SELECT DISTINCT s.serviceid, sl.servicedownid, sl_p.serviceupid as serviceupid, s.triggerid, '. + ' s.name as caption, s.algorithm, t.description, t.expression, s.sortorder, sl.linkid, s.showsla, s.goodsla, s.status '. + ' FROM services s '. + ' LEFT JOIN triggers t ON s.triggerid = t.triggerid '. + ' LEFT JOIN services_links sl ON s.serviceid = sl.serviceupid and NOT(sl.soft=0) '. + ' LEFT JOIN services_links sl_p ON s.serviceid = sl_p.servicedownid and sl_p.soft=0 '. + ' WHERE '.DBin_node('s.serviceid'). + ' AND (t.triggerid IS NULL OR '.DBcondition('t.triggerid',$available_triggers).') '. + ' ORDER BY s.sortorder, sl_p.serviceupid, s.serviceid'; + + $result=DBSelect($query); + + $services = array(); + $row = array( + 'id' => 0, + 'serviceid' => 0, + 'serviceupid' => 0, + 'caption' => S_ROOT_SMALL, + 'status' => SPACE, + 'reason' => SPACE, + 'sla' => SPACE, + 'sla2' => SPACE, + 'graph' => SPACE, + 'linkid'=>'' + ); + + $services[0]=$row; + $now=time(); + + while($row = DBFetch($result)){ + $row['id'] = $row['serviceid']; + + (empty($row['serviceupid']))?($row['serviceupid']='0'):(''); + (empty($row['description']))?($row['description']='None'):(''); + # Graph link + $row['graph'] = new CLink(S_SHOW,"srv_status2.php?serviceid=".$row["serviceid"]."&showgraph=1&year=".$year.url_param('path'),"action"); + + if(isset($row["triggerid"]) && !empty($row["triggerid"])){ + + $url = new CLink(expand_trigger_description($row['triggerid']),'events.php?triggerid='.$row['triggerid']); + $row['caption'] = array($row['caption'].' [',$url,']'); + + } + + if($row["status"]==0 || (isset($service) && (bccomp($service["serviceid"] , $row["serviceid"]) == 0))){ + $row['reason']='-'; + } + else { + $row['reason']='-'; + $result2=DBselect('SELECT s.triggerid,s.serviceid '. + ' FROM services s, triggers t '. + ' WHERE s.status>0 '. + ' AND s.triggerid is not NULL '. + ' AND t.triggerid=s.triggerid '. + ' AND '.DBcondition('t.triggerid',$available_triggers). + ' AND '.DBin_node('s.serviceid'). + ' ORDER BY s.status DESC, t.description'); + + while($row2=DBfetch($result2)){ + if(is_string($row['reason']) && ($row['reason'] == '-')) + $row['reason'] = new CList(null,"itservices"); + if(does_service_depend_on_the_service($row["serviceid"],$row2["serviceid"])){ + $row['reason']->AddItem(new CLink( + expand_trigger_description($row2["triggerid"]), + "events.php?triggerid=".$row2["triggerid"])); + } + } + } + + if($row["showsla"]==1){ + # SLA Bar + $row['sla'] = new CLink(new CImg("chart_sla2.php?serviceid=".$row["serviceid"]."&year=" . $year . "&month=" . $month), + "report3.php?serviceid=".$row["serviceid"]."&period=monthly&year=".$year); + + #$now = time(NULL); + #$period_start = $now-7*24*3600; + #$period_end = $now; + #$period_start=$now-7*86400; + #$period_end=$now; + // Start is: first day of the month + $period_start=mktime(0,0,0,$month,1,$year); + // Stop is last day of the month + $period_end=mktime(0,0,0,$month+1,1,$year); + + if($period_end>time()) + $period_end=time(); + $stat = calculate_service_availability($row["serviceid"],$period_start,$period_end); + + if($row["goodsla"] > $stat["ok"]){ + $sla_style='red'; + } + else { + $sla_style='green'; + } + + $row['sla2'] = array(new CSpan(round($row["goodsla"],3),'green'),'/', new CSpan(round($stat["ok"],3),$sla_style)); + } + else { + $row['sla']= "-"; + $row['sla2']= "-"; + } + + if(isset($services[$row['serviceid']])){ + $services[$row['serviceid']] = array_merge($services[$row['serviceid']],$row); + } + else { + $services[$row['serviceid']] = $row; + } + + if(isset($row['serviceupid'])) + $services[$row['serviceupid']]['childs'][] = array('id' => $row['serviceid'], 'soft' => 0, 'linkid' => 0); + + if(isset($row['servicedownid'])) + $services[$row['serviceid']]['childs'][] = array('id' => $row['servicedownid'], 'soft' => 1, 'linkid' => $row['linkid']); + } + + $treeServ = array(); + createShowServiceTree($services,$treeServ); //return into $treeServ parametr + + //permission issue + $treeServ = del_empty_nodes($treeServ); + + $tree = new CTree($treeServ,array('caption' => bold(S_SERVICE), + 'status' => bold(S_STATUS), + 'reason' => bold(S_REASON), + 'sla' => bold(S_SLA_LAST_7_DAYS), + 'sla' => bold('SLA (this month)'), + 'sla2' => bold(nbsp(S_SLA)), + 'graph' => bold(S_GRAPH))); + + if($tree){ + $url = '?fullscreen='.($_REQUEST['fullscreen']?'0':'1'); + + $fs_icon = new CDiv(SPACE,'fullscreen'); + $fs_icon->AddOption('title',$_REQUEST['fullscreen']?S_NORMAL.' '.S_VIEW:S_FULLSCREEN); + $fs_icon->AddAction('onclick',new CScript("javascript: document.location = '".$url."';")); + + $tab = create_hat( + S_IT_SERVICES_BIG.' (NEW)', + array($menu,$tree->getHTML()), + $fs_icon, + 'hat_services', + get_profile('web.srv_status.hats.hat_services.state',1) + ); + + $tab->Show(); + unset($tab); + } + else { + error('Can not format Tree. Check logik structure in service links'); + } + } +?> +