~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to frontends/php/report3.php

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
**/
20
20
?>
21
21
<?php
22
 
        include "include/config.inc.php";
 
22
        require_once "include/config.inc.php";
 
23
        require_once "include/services.inc.php";
 
24
 
23
25
        $page["title"] = "S_IT_SERVICES_AVAILABILITY_REPORT";
24
26
        $page["file"] = "report3.php";
25
 
        show_header($page["title"],0,0);
26
 
?>
27
 
 
28
 
<?php
29
 
        if(!check_anyright("Host","R"))
30
 
        {
31
 
                show_table_header("<font color=\"AA0000\">No permissions !</font>");
32
 
                show_page_footer();
33
 
                exit;
34
 
        }
35
 
?>
36
 
 
37
 
<?php
38
 
        if(!isset($_REQUEST["serviceid"]))
39
 
        {
40
 
                show_table_header("<font color=\"AA0000\">Undefined serviceid !</font>");
41
 
                show_page_footer();
42
 
                exit;
43
 
        }
44
 
        $service=get_service_by_serviceid($_REQUEST["serviceid"]);
45
 
?>
46
 
 
47
 
<?php
48
 
        if(!isset($_REQUEST["period"]))
49
 
        {
50
 
                $_REQUEST["period"]="weekly";
51
 
        }
52
 
 
53
 
        $h1=S_IT_SERVICES_AVAILABILITY_REPORT_BIG;
54
 
        $h1=$h1.":"."<a href=\"srv_status.php?serviceid=".$service["serviceid"]."\">".$service["name"]."</a>";
55
 
 
56
 
#       $h2=S_GROUP.SPACE;
57
 
        $h2=S_YEAR.SPACE;
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");
61
 
 
62
 
        $year=date("Y");
63
 
        for($year=date("Y")-2;$year<=date("Y");$year++)
64
 
        {
65
 
                $h2=$h2.form_select("year",$year,$year);
66
 
        }
67
 
        $h2=$h2."</select>";
68
 
 
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);
75
 
        $h2=$h2."</select>";
76
 
 
77
 
        show_header2($h1, $h2, "<form name=\"selection\" method=\"get\" action=\"report3.php\">", "</form>");
78
 
?>
79
 
 
 
27
        
 
28
include_once "include/page_header.php";
 
29
 
 
30
?>
 
31
<?php
 
32
//              VAR                     TYPE    OPTIONAL FLAGS  VALIDATION      EXCEPTION
 
33
        $fields=array(
 
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)
 
37
        );
 
38
 
 
39
        check_fields($fields);
 
40
 
 
41
        $period = get_request("period", "weekly");
 
42
        $year   = get_request("year",   date("Y"));
 
43
        
 
44
        define("YEAR_LEFT_SHIFT", 5);
 
45
?>
 
46
<?php
 
47
        $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT);
 
48
        
 
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"]
 
54
                ))))
 
55
        {
 
56
                access_deny();
 
57
        }
 
58
?>
 
59
<?php
 
60
        $form = new CForm();
 
61
        $form->AddVar("serviceid", $_REQUEST["serviceid"]);
 
62
 
 
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));
 
69
 
 
70
        $cmbYear = new CComboBox("year", $year, "submit();");
 
71
        for($y = (date("Y") - YEAR_LEFT_SHIFT); $y <= date("Y"); $y++)
 
72
        {
 
73
                $cmbYear->AddItem($y, $y);
 
74
        }
 
75
        $form->AddItem(array(SPACE.S_YEAR.SPACE, $cmbYear));
 
76
 
 
77
        show_table_header(array(
 
78
                        S_IT_SERVICES_AVAILABILITY_REPORT_BIG,
 
79
                        SPACE."\"",
 
80
                        new CLink($service["name"],"srv_status.php?serviceid=".$service["serviceid"]),
 
81
                        "\""
 
82
                ),
 
83
                $form);
 
84
?>
80
85
<?php
81
86
        $table = new CTableInfo();
82
 
        if($_REQUEST["period"]=="yearly")
83
 
        {
84
 
                $table->setHeader(array(S_YEAR,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA));
85
 
                for($year=date("Y")-5;$year<=date("Y");$year++)
86
 
                {
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);
90
 
 
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));
95
 
 
96
 
                        $ok=new CSpan($f_time,"off");
97
 
                        $problems=new CSpan($t_time,"on");
98
 
                        $percentage=new CSpan($f,"off");
99
 
 
100
 
                        if($service["showsla"]==1)
101
 
                        {
102
 
                                if($stat["ok"]>=$service["goodsla"])
103
 
                                {
104
 
                                        $sla=new CSpan($service["goodsla"],"off");
105
 
                                }
106
 
                                else
107
 
                                {
108
 
                                        $sla=new CSpan($service["goodsla"],"on");
109
 
                                }
110
 
                        }
111
 
                        else
112
 
                        {
113
 
                                $sla="-";
114
 
                        }
115
 
                        $table->addRow(array(
116
 
                                $year,
117
 
                                $ok,
118
 
                                $problems,
119
 
                                $percentage,
120
 
                                $sla
121
 
                                ));
122
 
                }
123
 
        }
124
 
        else if($_REQUEST["period"]=="monthly")
125
 
        {
126
 
                $table->setHeader(array(S_MONTH,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA));
127
 
                for($month=1;$month<=12;$month++)
128
 
                {
129
 
                        $start=mktime(0,0,0,$month,1,$_REQUEST["year"]);
130
 
                        $end=mktime(0,0,0,$month+1,1,$_REQUEST["year"]);
131
 
 
132
 
                        if($start>time())       break;
133
 
 
134
 
                        $stat=calculate_service_availability($service["serviceid"],$start,$end);
135
 
 
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));
140
 
 
141
 
                        $ok=new CSpan($f_time,"off");
142
 
                        $problems=new CSpan($t_time,"on");
143
 
                        $percentage=new CSpan($f,"off");
144
 
 
145
 
                        if($service["showsla"]==1)
146
 
                        {
147
 
                                if($stat["ok"]>=$service["goodsla"])
148
 
                                {
149
 
                                        $sla=new CSpan($service["goodsla"],"off");
150
 
                                }
151
 
                                else
152
 
                                {
153
 
                                        $sla=new CSpan($service["goodsla"],"on");
154
 
                                }
155
 
                        }
156
 
                        else
157
 
                        {
158
 
                                $sla="-";
159
 
                        }
160
 
                        $table->addRow(array(
161
 
                                date("M Y",$start),
162
 
                                $ok,
163
 
                                $problems,
164
 
                                $percentage,
165
 
                                $sla
166
 
                                ));
167
 
                }
168
 
        }
169
 
        else if($_REQUEST["period"]=="daily")
170
 
        {
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)
175
 
                {
176
 
                        $start=$day;
177
 
                        $end=$day+24*3600;
178
 
 
179
 
                        if($start>time())       break;
180
 
 
181
 
                        $stat=calculate_service_availability($service["serviceid"],$start,$end);
182
 
 
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));
187
 
 
188
 
                        $ok=new CSpan($f_time,"off");
189
 
                        $problems=new CSpan($t_time,"on");
190
 
                        $percentage=new CSpan($f,"off");
191
 
 
192
 
                        if($service["showsla"]==1)
193
 
                        {
194
 
                                if($stat["ok"]>=$service["goodsla"])
195
 
                                {
196
 
                                        $sla=new CSpan($service["goodsla"],"off");
197
 
                                }
198
 
                                else
199
 
                                {
200
 
                                        $sla=new CSpan($service["goodsla"],"on");
201
 
                                }
202
 
                        }
203
 
                        else
204
 
                        {
205
 
                                $sla="-";
206
 
                        }
207
 
                        $table->addRow(array(
208
 
                                date("d M Y",$start),
209
 
                                $ok,
210
 
                                $problems,
211
 
                                $percentage,
212
 
                                $sla
213
 
                                ));
214
 
                }
215
 
        }
216
 
        else
217
 
        {
218
 
        //--------Weekly-------------
219
 
        $table->setHeader(array(S_FROM,S_TILL,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA));
220
 
        $year=date("Y");
221
 
        for($year=date("Y")-2;$year<=date("Y");$year++)
222
 
        {
223
 
                if( isset($_REQUEST["year"]) && ($_REQUEST["year"] != $year) )
224
 
                {
225
 
                        continue;
226
 
                }
227
 
                $start=mktime(0,0,0,1,1,$year);
228
 
 
229
 
                $wday=date("w",$start);
230
 
                if($wday==0) $wday=7;
231
 
                $start=$start-($wday-1)*24*3600;
232
 
 
233
 
                for($i=0;$i<53;$i++)
234
 
                {
235
 
                        $period_start=$start+7*24*3600*$i;
236
 
                        $period_end=$start+7*24*3600*($i+1);
237
 
                        if($period_start>time())
238
 
                        {
239
 
                                break;
240
 
                        }
241
 
                        $stat=calculate_service_availability($service["serviceid"],$period_start,$period_end);
242
 
 
243
 
                        $from=date(S_DATE_FORMAT_YMD,$period_start);
244
 
                        $till=date(S_DATE_FORMAT_YMD,$period_end);
245
87
        
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));
250
 
 
251
 
                        $ok=new CSpan($f_time,"off");
252
 
                        $problems=new CSpan($t_time,"on");
253
 
                        $percentage=new CSpan($f,"off");
254
 
 
255
 
                        if($service["showsla"]==1)
256
 
                        {
257
 
                                if($stat["ok"]>=$service["goodsla"])
258
 
                                {
259
 
                                        $sla=new CSpan($service["goodsla"],"off");
260
 
                                }
261
 
                                else
262
 
                                {
263
 
                                        $sla=new CSpan($service["goodsla"],"on");
264
 
                                }
265
 
                        }
266
 
                        else
267
 
                        {
268
 
                                $sla="-";
269
 
                        }
270
 
                
271
 
                        $table->addRow(array(
272
 
                                $from,
273
 
                                $till,
274
 
                                $ok,
275
 
                                $problems,
276
 
                                $percentage,
277
 
                                $sla
278
 
                                ));
279
 
                }
280
 
        }
281
 
        //--------Weekly-------------
282
 
        }
283
 
        $table->show();
284
 
 
285
 
        show_page_footer();
 
88
        $header = array(S_OK,S_PROBLEMS,S_DOWNTIME,S_PERCENTAGE,S_SLA);
 
89
 
 
90
        switch($period)
 
91
        {
 
92
                case "yearly":
 
93
                        $from   = (date("Y") - YEAR_LEFT_SHIFT);
 
94
                        $to     = date("Y");
 
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; };
 
99
                        break;
 
100
                case "monthly":
 
101
                        $from   = 1;
 
102
                        $to     = 12;
 
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; };
 
107
                        break;
 
108
                case "dayly":
 
109
                        $from   = 1;
 
110
                        $to     = 365;
 
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; };
 
115
                        break;
 
116
                case "weekly":
 
117
                default:
 
118
                        $from   = 0;
 
119
                        $to     = 52;
 
120
                        array_unshift($header,new CCol(S_FROM,"center"),new CCol(S_TILL,"center"));
 
121
                        function get_time($w)   {
 
122
                                global $year;   
 
123
 
 
124
                                $time   = mktime(0,0,0,1, 1, $year);
 
125
                                $wd     = date("w", $time);
 
126
                                $wd     = $wd == 0 ? 6 : $wd - 1;
 
127
 
 
128
                                return ($time + ($w*7 - $wd)*24*3600);
 
129
                        }
 
130
                        function format_time($t){       return date("d M Y H:i",$t);    }
 
131
                        function format_time2($t){      return format_time($t); };
 
132
                        break;
 
133
 
 
134
        }
 
135
 
 
136
        $table->SetHeader($header);
 
137
 
 
138
        for($t = $from; $t <= $to; $t++)
 
139
        {       
 
140
                if(($start = get_time($t)) > time())
 
141
                        break;
 
142
                
 
143
                if(($end = get_time($t+1)) > time())
 
144
                        $end = time();
 
145
                
 
146
                $stat = calculate_service_availability($service["serviceid"],$start,$end);
 
147
 
 
148
                $ok             = new CSpan(
 
149
                                        sprintf("%dd %dh %dm",
 
150
                                                $stat["ok_time"]/(24*3600),
 
151
                                                ($stat["ok_time"]%(24*3600))/3600,
 
152
                                                ($stat["ok_time"]%(3600))/(60)),
 
153
                                        "off");
 
154
                
 
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)),
 
160
                                        "on");
 
161
 
 
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));
 
166
                
 
167
                $percentage     = new CSpan(sprintf("%2.2f%%",$stat["ok"]) , "off");
 
168
 
 
169
                $table->AddRow(array(
 
170
                        format_time($start),
 
171
                        format_time2($end),
 
172
                        $ok,
 
173
                        $problems,
 
174
                        $downtime,
 
175
                        $percentage,
 
176
                        ($service["showsla"]==1) ?
 
177
                                new CSpan($service["goodsla"], ($stat["ok"] >= $service["goodsla"]) ? "off" : "on") :
 
178
                                "-"
 
179
                                
 
180
                        ));
 
181
        }
 
182
 
 
183
        $table->Show();
 
184
?>
 
185
<?php
 
186
 
 
187
include_once "include/page_footer.php";
 
188
 
286
189
?>