22
include "include/config.inc.php";
22
require_once "include/config.inc.php";
23
require_once "include/services.inc.php";
23
25
$page["title"] = "S_IT_SERVICES_AVAILABILITY_REPORT";
24
26
$page["file"] = "report3.php";
25
show_header($page["title"],0,0);
29
if(!check_anyright("Host","R"))
31
show_table_header("<font color=\"AA0000\">No permissions !</font>");
38
if(!isset($_REQUEST["serviceid"]))
40
show_table_header("<font color=\"AA0000\">Undefined serviceid !</font>");
44
$service=get_service_by_serviceid($_REQUEST["serviceid"]);
48
if(!isset($_REQUEST["period"]))
50
$_REQUEST["period"]="weekly";
53
$h1=S_IT_SERVICES_AVAILABILITY_REPORT_BIG;
54
$h1=$h1.":"."<a href=\"srv_status.php?serviceid=".$service["serviceid"]."\">".$service["name"]."</a>";
58
$h2=$h2."<input name=\"serviceid\" type=\"hidden\" value=".$_REQUEST["serviceid"].">";
59
$h2=$h2."<select class=\"biginput\" name=\"year\" onChange=\"submit()\">";
60
$result=DBselect("select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host");
63
for($year=date("Y")-2;$year<=date("Y");$year++)
65
$h2=$h2.form_select("year",$year,$year);
69
$h2=$h2.SPACE.S_PERIOD.SPACE;
70
$h2=$h2."<select class=\"biginput\" name=\"period\" onChange=\"submit()\">";
71
$h2=$h2.form_select("period","daily",S_DAILY);
72
$h2=$h2.form_select("period","weekly",S_WEEKLY);
73
$h2=$h2.form_select("period","monthly",S_MONTHLY);
74
$h2=$h2.form_select("period","yearly",S_YEARLY);
77
show_header2($h1, $h2, "<form name=\"selection\" method=\"get\" action=\"report3.php\">", "</form>");
28
include_once "include/page_header.php";
32
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
34
"serviceid"=> array(T_ZBX_INT, O_MAND,P_SYS, DB_ID, NULL),
35
"period"=> array(T_ZBX_STR, O_OPT, null, IN('"dayly","weekly","monthly","yearly"'), NULL),
36
"year"=> array(T_ZBX_INT, O_OPT, null, null, NULL)
39
check_fields($fields);
41
$period = get_request("period", "weekly");
42
$year = get_request("year", date("Y"));
44
define("YEAR_LEFT_SHIFT", 5);
47
$denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT);
49
if( !($service = DBfetch(DBselect("select s.* from services s left join triggers t on s.triggerid=t.triggerid ".
50
" left join functions f on t.triggerid=f.triggerid left join items i on f.itemid=i.itemid ".
51
" where (i.hostid is NULL or i.hostid not in (".$denyed_hosts.")) ".
52
" and ".DBid2nodeid("s.serviceid")."=".$ZBX_CURNODEID.
53
" and s.serviceid=".$_REQUEST["serviceid"]
61
$form->AddVar("serviceid", $_REQUEST["serviceid"]);
63
$cmbPeriod = new CComboBox("period", $period, "submit();");
64
$cmbPeriod->AddItem("dayly",S_DAILY);
65
$cmbPeriod->AddItem("weekly",S_WEEKLY);
66
$cmbPeriod->AddItem("monthly",S_MONTHLY);
67
$cmbPeriod->AddItem("yearly",S_YEARLY);
68
$form->AddItem(array(SPACE.S_PERIOD.SPACE, $cmbPeriod));
70
$cmbYear = new CComboBox("year", $year, "submit();");
71
for($y = (date("Y") - YEAR_LEFT_SHIFT); $y <= date("Y"); $y++)
73
$cmbYear->AddItem($y, $y);
75
$form->AddItem(array(SPACE.S_YEAR.SPACE, $cmbYear));
77
show_table_header(array(
78
S_IT_SERVICES_AVAILABILITY_REPORT_BIG,
80
new CLink($service["name"],"srv_status.php?serviceid=".$service["serviceid"]),
81
86
$table = new CTableInfo();
82
if($_REQUEST["period"]=="yearly")
84
$table->setHeader(array(S_YEAR,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA));
85
for($year=date("Y")-5;$year<=date("Y");$year++)
87
$start=mktime(0,0,0,1,1,$year);
88
$end=mktime(0,0,0,1,1,$year+1);
89
$stat=calculate_service_availability($service["serviceid"],$start,$end);
91
$t=sprintf("%2.2f%%",$stat["problem"]);
92
$t_time=sprintf("%dd %dh %dm",$stat["problem_time"]/(24*3600),($stat["problem_time"]%(24*3600))/3600,($stat["problem_time"]%(3600))/(60));
93
$f=sprintf("%2.2f%%",$stat["ok"]);
94
$f_time=sprintf("%dd %dh %dm",$stat["ok_time"]/(24*3600),($stat["ok_time"]%(24*3600))/3600,($stat["ok_time"]%(3600))/(60));
96
$ok=new CSpan($f_time,"off");
97
$problems=new CSpan($t_time,"on");
98
$percentage=new CSpan($f,"off");
100
if($service["showsla"]==1)
102
if($stat["ok"]>=$service["goodsla"])
104
$sla=new CSpan($service["goodsla"],"off");
108
$sla=new CSpan($service["goodsla"],"on");
115
$table->addRow(array(
124
else if($_REQUEST["period"]=="monthly")
126
$table->setHeader(array(S_MONTH,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA));
127
for($month=1;$month<=12;$month++)
129
$start=mktime(0,0,0,$month,1,$_REQUEST["year"]);
130
$end=mktime(0,0,0,$month+1,1,$_REQUEST["year"]);
132
if($start>time()) break;
134
$stat=calculate_service_availability($service["serviceid"],$start,$end);
136
$t=sprintf("%2.2f%%",$stat["problem"]);
137
$t_time=sprintf("%dd %dh %dm",$stat["problem_time"]/(24*3600),($stat["problem_time"]%(24*3600))/3600,($stat["problem_time"]%(3600))/(60));
138
$f=sprintf("%2.2f%%",$stat["ok"]);
139
$f_time=sprintf("%dd %dh %dm",$stat["ok_time"]/(24*3600),($stat["ok_time"]%(24*3600))/3600,($stat["ok_time"]%(3600))/(60));
141
$ok=new CSpan($f_time,"off");
142
$problems=new CSpan($t_time,"on");
143
$percentage=new CSpan($f,"off");
145
if($service["showsla"]==1)
147
if($stat["ok"]>=$service["goodsla"])
149
$sla=new CSpan($service["goodsla"],"off");
153
$sla=new CSpan($service["goodsla"],"on");
160
$table->addRow(array(
169
else if($_REQUEST["period"]=="daily")
171
$table->setHeader(array(S_DAY,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA));
172
$s=mktime(0,0,0,1,1,$_REQUEST["year"]);
173
$e=mktime(0,0,0,1,1,$_REQUEST["year"]+1);
174
for($day=$s;$day<$e;$day+=24*3600)
179
if($start>time()) break;
181
$stat=calculate_service_availability($service["serviceid"],$start,$end);
183
$t=sprintf("%2.2f%%",$stat["problem"]);
184
$t_time=sprintf("%dd %dh %dm",$stat["problem_time"]/(24*3600),($stat["problem_time"]%(24*3600))/3600,($stat["problem_time"]%(3600))/(60));
185
$f=sprintf("%2.2f%%",$stat["ok"]);
186
$f_time=sprintf("%dd %dh %dm",$stat["ok_time"]/(24*3600),($stat["ok_time"]%(24*3600))/3600,($stat["ok_time"]%(3600))/(60));
188
$ok=new CSpan($f_time,"off");
189
$problems=new CSpan($t_time,"on");
190
$percentage=new CSpan($f,"off");
192
if($service["showsla"]==1)
194
if($stat["ok"]>=$service["goodsla"])
196
$sla=new CSpan($service["goodsla"],"off");
200
$sla=new CSpan($service["goodsla"],"on");
207
$table->addRow(array(
208
date("d M Y",$start),
218
//--------Weekly-------------
219
$table->setHeader(array(S_FROM,S_TILL,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA));
221
for($year=date("Y")-2;$year<=date("Y");$year++)
223
if( isset($_REQUEST["year"]) && ($_REQUEST["year"] != $year) )
227
$start=mktime(0,0,0,1,1,$year);
229
$wday=date("w",$start);
230
if($wday==0) $wday=7;
231
$start=$start-($wday-1)*24*3600;
235
$period_start=$start+7*24*3600*$i;
236
$period_end=$start+7*24*3600*($i+1);
237
if($period_start>time())
241
$stat=calculate_service_availability($service["serviceid"],$period_start,$period_end);
243
$from=date(S_DATE_FORMAT_YMD,$period_start);
244
$till=date(S_DATE_FORMAT_YMD,$period_end);
246
$t=sprintf("%2.2f%%",$stat["problem"]);
247
$t_time=sprintf("%dd %dh %dm",$stat["problem_time"]/(24*3600),($stat["problem_time"]%(24*3600))/3600,($stat["problem_time"]%(3600))/(60));
248
$f=sprintf("%2.2f%%",$stat["ok"]);
249
$f_time=sprintf("%dd %dh %dm",$stat["ok_time"]/(24*3600),($stat["ok_time"]%(24*3600))/3600,($stat["ok_time"]%(3600))/(60));
251
$ok=new CSpan($f_time,"off");
252
$problems=new CSpan($t_time,"on");
253
$percentage=new CSpan($f,"off");
255
if($service["showsla"]==1)
257
if($stat["ok"]>=$service["goodsla"])
259
$sla=new CSpan($service["goodsla"],"off");
263
$sla=new CSpan($service["goodsla"],"on");
271
$table->addRow(array(
281
//--------Weekly-------------
88
$header = array(S_OK,S_PROBLEMS,S_DOWNTIME,S_PERCENTAGE,S_SLA);
93
$from = (date("Y") - YEAR_LEFT_SHIFT);
95
array_unshift($header, new CCol(S_YEAR,"center"));
96
function get_time($y) { return mktime(0,0,0,1,1,$y); }
97
function format_time($t){ return date("Y", $t); }
98
function format_time2($t){ return null; };
103
array_unshift($header, new CCol(S_MONTH,"center"));
104
function get_time($m) { global $year; return mktime(0,0,0,$m,1,$year); }
105
function format_time($t){ return date("M Y",$t); }
106
function format_time2($t){ return null; };
111
array_unshift($header, new CCol(S_DAY,"center"));
112
function get_time($d) { global $year; return mktime(0,0,0,1,$d,$year); }
113
function format_time($t){ return date("d M Y",$t); }
114
function format_time2($t){ return null; };
120
array_unshift($header,new CCol(S_FROM,"center"),new CCol(S_TILL,"center"));
121
function get_time($w) {
124
$time = mktime(0,0,0,1, 1, $year);
125
$wd = date("w", $time);
126
$wd = $wd == 0 ? 6 : $wd - 1;
128
return ($time + ($w*7 - $wd)*24*3600);
130
function format_time($t){ return date("d M Y H:i",$t); }
131
function format_time2($t){ return format_time($t); };
136
$table->SetHeader($header);
138
for($t = $from; $t <= $to; $t++)
140
if(($start = get_time($t)) > time())
143
if(($end = get_time($t+1)) > time())
146
$stat = calculate_service_availability($service["serviceid"],$start,$end);
149
sprintf("%dd %dh %dm",
150
$stat["ok_time"]/(24*3600),
151
($stat["ok_time"]%(24*3600))/3600,
152
($stat["ok_time"]%(3600))/(60)),
155
$problems = new CSpan(
156
sprintf("%dd %dh %dm",
157
$stat["problem_time"]/(24*3600),
158
($stat["problem_time"]%(24*3600))/3600,
159
($stat["problem_time"]%(3600))/(60)),
162
$downtime = sprintf("%dd %dh %dm",
163
$stat["downtime_time"]/(24*3600),
164
($stat["downtime_time"]%(24*3600))/3600,
165
($stat["downtime_time"]%(3600))/(60));
167
$percentage = new CSpan(sprintf("%2.2f%%",$stat["ok"]) , "off");
169
$table->AddRow(array(
176
($service["showsla"]==1) ?
177
new CSpan($service["goodsla"], ($stat["ok"] >= $service["goodsla"]) ? "off" : "on") :
187
include_once "include/page_footer.php";