ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/php/latest/latest.php
Revision: 1.52
Committed: Sat Jun 30 11:24:40 2007 UTC (17 years, 4 months ago) by tdb
Branch: MAIN
Changes since 1.51: +23 -23 lines
Log Message:
Tidy up PHP short tags.

File Contents

# User Rev Content
1 pjm2 1.1 <?php
2    
3 tdb 1.37 #
4     # i-scream central monitoring system
5 tdb 1.45 # http://www.i-scream.org
6 tdb 1.37 # Copyright (C) 2000-2002 i-scream
7     #
8     # This program is free software; you can redistribute it and/or
9     # modify it under the terms of the GNU General Public License
10     # as published by the Free Software Foundation; either version 2
11     # of the License, or (at your option) any later version.
12     #
13     # This program is distributed in the hope that it will be useful,
14     # but WITHOUT ANY WARRANTY; without even the implied warranty of
15     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     # GNU General Public License for more details.
17     #
18     # You should have received a copy of the GNU General Public License
19     # along with this program; if not, write to the Free Software
20     # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21     #
22    
23 pjm2 1.1 # CONFIGURABLE CONSTANTS: -
24    
25     include("latest_config.inc.php");
26    
27     #
28     # END CONFIGURATION
29    
30 pjm2 1.18 include("iutils.inc.php");
31 pjm2 1.1
32 tdb 1.46 if ($formMethod == "GET") {
33 tdb 1.47 $machine = isset($_GET['machine']) ? $_GET['machine'] : "";
34 tdb 1.46 }
35    
36    
37 pjm2 1.9 function printLine($title) {
38 pjm2 1.19 echo "<hr style=\"color:#9999ff;\">";
39 pjm2 1.9 echo "<b>$title</b>";
40 pjm2 1.6 }
41    
42 pjm2 1.1
43 tdb 1.46 function showUptime($title, $value, $input, $graph="") {
44     $report = $value;
45    
46     $value = getPregMatch($value, $input);
47     if (!isset($value)) {
48     $value = "<i><font color=\"#999999\">not sent</font></i>";
49     }
50     ?>
51     <table border="0" width="100%">
52     <tr>
53     <td width="50%" align="right" valign="top">
54 tdb 1.52 <b><?php=$title?></b>
55 tdb 1.46 </td>
56     <td width="50%" align="left" valign="top">
57 tdb 1.52 <?php if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) {
58 tdb 1.46 linkToHistory($graph);
59     } ?>
60 tdb 1.52 <?php=uptime($value)?> (<?php=$value?> seconds)</td>
61 tdb 1.46 </tr>
62     </table>
63 tdb 1.52 <?php
64 tdb 1.46 }
65    
66    
67 tdb 1.42 function showStat($title, $value, $input, $graph="") {
68 pjm2 1.24
69     $report = $value;
70    
71 pjm2 1.28 $value = getPregMatch($value, $input);
72 tdb 1.38 if (!isset($value)) {
73 pjm2 1.8 $value = "<i><font color=\"#999999\">not sent</font></i>";
74 pjm2 1.1 }
75     ?>
76     <table border="0" width="100%">
77     <tr>
78 pjm2 1.24 <td width="50%" align="right" valign="top">
79 tdb 1.52 <b><?php=$title?></b>
80 pjm2 1.24 </td>
81     <td width="50%" align="left" valign="top">
82 tdb 1.52 <?php if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) {
83 tdb 1.42 linkToHistory($graph);
84 pjm2 1.24 } ?>
85 tdb 1.52 <?php=$value?></td>
86 pjm2 1.1 </tr>
87     </table>
88 tdb 1.52 <?php
89 pjm2 1.1 }
90    
91    
92 tdb 1.42 function linkToHistory($graph) {
93 pjm2 1.20 global $machine;
94 tdb 1.42 if(!empty($graph)) {
95     echo <<<EOT
96     <a href="graphs.php?machine_name=$machine&graph=$graph&submit=Show"><img src="minichart.gif" alt="View historical graphs of this data" width="20" height="20" border="0"></a>
97 pjm2 1.20 EOT;
98 tdb 1.42 }
99 pjm2 1.20 }
100    
101    
102 tdb 1.46 # convert bytes to MB
103     function b2Mb($bytes) {
104     $mb = $bytes / (1024*1024);
105     return (int) $mb;
106     }
107    
108    
109     # Convert seconds uptime to something readable
110     function uptime($until) {
111     $day = date('z', $until);
112     $hour = date('G', $until);
113 tdb 1.49 if ($hour == 0) { # everything's an hour ahead, so roll back
114     $hour = 23;
115     $day = $day - 1;
116     } else {
117     $hour = $hour - 1;
118     }
119 tdb 1.46 $minute = date('i', $until);
120     $return = "";
121     if ($day) {
122 tdb 1.49 $return = "$return$day";
123     if ($day == 1) {
124     $return = "$return Day ";
125     } else {
126     $return = "$return Days ";
127     }
128 tdb 1.46 }
129     if ($hour) {
130 tdb 1.49 $return = "$return$hour";
131     if ($hour == 1) {
132     $return = "$return Hour ";
133     } else {
134     $return = "$return Hours ";
135     }
136     }
137     $return = "$return$minute";
138     if ($minute == 1) {
139     $return = "$return Min";
140     } else {
141     $return = "$return Mins";
142 tdb 1.46 }
143 tdb 1.49 return $return;
144 tdb 1.46 }
145    
146    
147 pjm2 1.28 # show all disk information.
148     function showDisks($diskRoot, $units, $input) {
149     include("latest_config.inc.php");
150    
151     $i = 0;
152     while(1) {
153     $name = getPregMatch("$diskRoot.p$i.attributes.name", $input);
154 pjm2 1.31 $mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input);
155     if ($name || $mount) {
156     $used = "$diskRoot.p$i.attributes.used";
157 tdb 1.44 $total = "$diskRoot.p$i.attributes.total";
158 tdb 1.42 $graph = preg_replace("/_/", "$hex_underscore", $mount);
159     $graph = preg_replace("/\//", "$hex_slash", $graph);
160 tdb 1.50 $graph = preg_replace("/\\\\/", "$hex_bslash", $graph);
161     $graph = preg_replace("/ /", "$hex_space", $graph);
162     $graph = preg_replace("/:/", "$hex_colon", $graph);
163 tdb 1.43 $totalinodes = getPregMatch("$diskRoot.p$i.attributes.totalinodes", $input);
164     $freeinodes = getPregMatch("$diskRoot.p$i.attributes.freeinodes", $input);
165 tdb 1.44 showBar("$name ($mount)<br>space used", $used, $total, $units, $input, "disk-$graph");
166 tdb 1.46 showBar("inodes used", (float) $freeinodes, (float) $totalinodes, " inodes", $input, "", "swap");
167     showStat("FS Type", "$diskRoot.p$i.attributes.fstype", $input);
168 tdb 1.43 print " <br><br>\n";
169 pjm2 1.28 }
170 pjm2 1.30 else {
171     break;
172     }
173 pjm2 1.28 $i++;
174     }
175     }
176 tdb 1.44
177    
178     # show all disk IO information.
179     function showDiskIO($diskRoot, $input) {
180     include("latest_config.inc.php");
181    
182     $i = 0;
183     while(1) {
184     $name = getPregMatch("$diskRoot.p$i.attributes.name", $input);
185     if ($name) {
186 tdb 1.51 $graph = preg_replace("/_/", "$hex_underscore", $name);
187     $graph = preg_replace("/\//", "$hex_slash", $graph);
188 tdb 1.50 $graph = preg_replace("/\\\\/", "$hex_bslash", $graph);
189     $graph = preg_replace("/ /", "$hex_space", $graph);
190     $graph = preg_replace("/:/", "$hex_colon", $graph);
191 tdb 1.44 print "<br><center><b>(Disk $name)</b></center>";
192 tdb 1.50 showStat("Read bytes (per sec)", "$diskRoot.p$i.attributes.rbytes", $input, "diskio-$graph");
193     showStat("Write bytes (per sec)", "$diskRoot.p$i.attributes.wbytes", $input, "diskio-$graph");
194 tdb 1.44 print " <br>\n";
195     }
196     else {
197     break;
198     }
199     $i++;
200     }
201     }
202    
203    
204     # show all network information.
205     function showNet($netRoot, $input) {
206     include("latest_config.inc.php");
207 tdb 1.47
208 tdb 1.44 $i = 0;
209     while(1) {
210     $name = getPregMatch("$netRoot.p$i.attributes.name", $input);
211     if ($name) {
212 tdb 1.51 $graph = preg_replace("/_/", "$hex_underscore", $name);
213     $graph = preg_replace("/\//", "$hex_slash", $graph);
214 tdb 1.50 $graph = preg_replace("/\\\\/", "$hex_bslash", $graph);
215     $graph = preg_replace("/ /", "$hex_space", $graph);
216     $graph = preg_replace("/:/", "$hex_colon", $graph);
217     $graph = preg_replace("/\(/", "$hex_lbracket", $graph);
218     $graph = preg_replace("/\)/", "$hex_rbracket", $graph);
219     $graph = preg_replace("/\+/", "$hex_plus", $graph);
220     $graph = preg_replace("/#/", "$hex_hash", $graph);
221 tdb 1.44 print "<br><center><b>(Network Interface $name)</b></center>";
222 tdb 1.50 showStat("Received bytes (per sec)", "$netRoot.p$i.attributes.rx", $input, "net-$graph");
223     showStat("Transfered bytes (per sec)", "$netRoot.p$i.attributes.tx", $input, "net-$graph");
224 tdb 1.44 print " <br>\n";
225     }
226     else {
227     break;
228     }
229     $i++;
230     }
231     }
232    
233 tdb 1.47
234 tdb 1.46 # show all mail queue information
235     function showMailQ($mailqRoot, $input) {
236     include("latest_config.inc.php");
237    
238     $i = 0;
239     while(1) {
240     $name = getPregMatch("$mailqRoot.p$i.attributes.name", $input);
241     if ($name) {
242     print "<br><center><b>($name)</b></center>";
243     $name = preg_replace("/\s+/", "", $name);
244     showStat("Messages in queue", "$mailqRoot.p$i.attributes.size", $input, "mailq-$name");
245     print " <br>\n";
246     }
247     else {
248     break;
249     }
250     $i++;
251     }
252     }
253 pjm2 1.28
254 tdb 1.47
255 pjm2 1.28 # Return a preg_match result.
256     function getPregMatch($value, $input) {
257 pjm2 1.29 preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches);
258 tdb 1.48 if(!isset($matches[1])) {
259     return;
260     }
261 pjm2 1.28 return $matches[1];
262     }
263    
264    
265 pjm2 1.1 # show a bar-represented value.
266 tdb 1.42 function showBar($title, $value, $max, $units, $input, $graph="", $arrange='normal') {
267 pjm2 1.1
268     include("latest_config.inc.php");
269    
270 pjm2 1.22 $report = $value;
271 tdb 1.43 if (!is_int($value)) {
272     $value = getPregMatch($value, $input);
273     }
274 pjm2 1.1 if (!is_int($max)) {
275 pjm2 1.28 $max = getPregMatch($max, $input);
276 pjm2 1.1 }
277 tdb 1.40 if (!isset($value) || !isset($max)) {
278 pjm2 1.1 return;
279     }
280    
281 pjm2 1.26 if ($arrange == 'swap') {
282 pjm2 1.27 $value = $max - $value;
283 tdb 1.46 }
284    
285     if ($units == 'MB') {
286     $value = b2Mb ($value);
287     $max = b2Mb ($max);
288 pjm2 1.26 }
289 pjm2 1.27
290 tdb 1.40 if(empty($max)) {
291 pjm2 1.35 $width = 1;
292 tdb 1.40 }
293     else {
294     $width = intval($max_width * $value / $max);
295     if ($width < 1) {
296     $width = 1;
297     }
298 pjm2 1.35 }
299    
300 pjm2 1.1 ?>
301 pjm2 1.10 <table border="0" cellpadding="0" cellspacing="0" align="center">
302 pjm2 1.1 <tr>
303 tdb 1.52 <td colspan="2"><?php linkToHistory($graph); ?> <b><?php=$title?></b> <font size="2">(<?php=$value?><?php=$units?>)</font></td>
304 pjm2 1.1 </tr>
305     <tr>
306 tdb 1.52 <td colspan="2" bgcolor="#eeeeff"><img src="<?php=$barImage?>" border="0" height="20" width="<?php=$width?>"></td>
307 pjm2 1.1 </tr>
308     <tr>
309 tdb 1.52 <td colspan="2"><img src="<?php=$scaleImage?>" border="0" height="11" width="<?php=$max_width?>"></td>
310 pjm2 1.1 </tr>
311     <tr>
312 tdb 1.52 <td align="left">0<?php=$units?></td>
313     <td align="right"><?php=$max?><?php=$units?></td>
314 pjm2 1.15 </tr>
315 pjm2 1.1 </table>
316 tdb 1.52 <?php
317 pjm2 1.1 }
318    
319    
320     ?>
321    
322 tdb 1.52 <?php include($titleHTML); ?>
323 pjm2 1.1
324 tdb 1.52 <?php printLine("Display the latest information received from a host"); ?>
325 pjm2 1.1
326 tdb 1.52 <form method="<?php echo $formMethod ?>" action="<?php echo $thisPage ?>">
327     <?php
328 pjm2 1.1
329 pjm2 1.5 $file_array = getdirArray($latestDirectory,'asort');
330 pjm2 1.1 print "<select size=\"1\" name=\"machine\">";
331     if ($machine) { ?>
332 tdb 1.52 <option selected value="<?php echo $machine ?>"><?php echo $machine ?></option>
333 pjm2 1.1 <option value="">----------------</option>
334 tdb 1.52 <?php }
335 pjm2 1.1 foreach($file_array as $file_name) {
336 pjm2 1.3 #if (is_dir($file_name)) {
337 pjm2 1.1 print "<option value=\"$file_name\">$file_name</option>";
338 pjm2 1.3 #}
339 pjm2 1.1 }
340     print "</select>";
341    
342     ?>
343     <input type="submit" name="submit" value="Display">
344     </form>
345    
346 tdb 1.52 <?php if ($machine) {
347 pjm2 1.1
348 pjm2 1.12 $last_modified = filemtime("$latestDirectory/$machine/$latestData");
349     clearstatcache();
350     $data_age = time() - $last_modified;
351    
352 pjm2 1.36 $last_modified = date("l jS F Y - g:ia", $last_modified);
353 pjm2 1.12
354     if ($data_age > $warning_age) {
355     $warning = <<<EOT
356     <br>
357     <font color="red"><b>
358     Warning:
359     </b></font>
360     This realtime report is too old to be considered recent
361     EOT;
362 tdb 1.47 }
363     else {
364     $warning = "";
365 pjm2 1.12 }
366    
367     echo <<<EOT
368 pjm2 1.16 <table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1">
369 pjm2 1.12 <tr>
370     <td bgcolor="#000066">
371     &nbsp;
372     </td>
373     <td bgcolor="#ffffcc">
374     <font face="arial,sans-serif" size="2">
375 pjm2 1.24 <b>Receipt date:</b> $last_modified
376 pjm2 1.12 $warning
377     </font>
378     </td>
379     </tr>
380     </table>
381     EOT;
382    
383 pjm2 1.1 # Read the file.
384 pjm2 1.25 if (file_exists("$latestDirectory/$machine/$latestData")) {
385     $input = file("$latestDirectory/$machine/$latestData");
386     # All we need is the first line if there is more than one line.
387     $input = $input[0];
388     }
389 pjm2 1.1
390 tdb 1.38 if (!isset($input)) {
391 pjm2 1.25 echo "<br><br>There are currently no latest details about <b>$machine</b>. Please notify your i-scream server administrator if you believe this to be incorrect.";
392 pjm2 1.1 }
393     else {
394     # Display the data specified in the display include.
395     include("latest_display.inc.php");
396     }
397 pjm2 1.9 }
398 pjm2 1.12
399 pjm2 1.1 ?>
400    
401 tdb 1.52 <?php printLine(""); ?>
402 pjm2 1.1
403 tdb 1.52 <?php include($bottomHTML); ?>