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 |
# Navigation for the i-scream reports. |
24 |
|
|
# pjm2@ukc.ac.uk |
25 |
|
|
# |
26 |
|
|
# CONFIGURABLE CONSTANTS: - |
27 |
|
|
|
28 |
|
|
include("latest_config.inc.php"); |
29 |
|
|
|
30 |
|
|
# |
31 |
|
|
# END CONFIGURATION |
32 |
|
|
|
33 |
pjm2 |
1.18 |
include("iutils.inc.php"); |
34 |
pjm2 |
1.1 |
|
35 |
tdb |
1.46 |
if ($formMethod == "GET") { |
36 |
|
|
$machine = $_GET['machine']; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
|
40 |
pjm2 |
1.9 |
function printLine($title) { |
41 |
pjm2 |
1.19 |
echo "<hr style=\"color:#9999ff;\">"; |
42 |
pjm2 |
1.9 |
echo "<b>$title</b>"; |
43 |
pjm2 |
1.6 |
} |
44 |
|
|
|
45 |
pjm2 |
1.1 |
|
46 |
tdb |
1.46 |
function showUptime($title, $value, $input, $graph="") { |
47 |
|
|
$report = $value; |
48 |
|
|
|
49 |
|
|
$value = getPregMatch($value, $input); |
50 |
|
|
if (!isset($value)) { |
51 |
|
|
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
52 |
|
|
} |
53 |
|
|
?> |
54 |
|
|
<table border="0" width="100%"> |
55 |
|
|
<tr> |
56 |
|
|
<td width="50%" align="right" valign="top"> |
57 |
|
|
<b><?=$title?></b> |
58 |
|
|
</td> |
59 |
|
|
<td width="50%" align="left" valign="top"> |
60 |
|
|
<? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
61 |
|
|
linkToHistory($graph); |
62 |
|
|
} ?> |
63 |
|
|
<?=uptime($value)?> (<?=$value?> seconds)</td> |
64 |
|
|
</tr> |
65 |
|
|
</table> |
66 |
|
|
<? |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
|
70 |
tdb |
1.42 |
function showStat($title, $value, $input, $graph="") { |
71 |
pjm2 |
1.24 |
|
72 |
|
|
$report = $value; |
73 |
|
|
|
74 |
pjm2 |
1.28 |
$value = getPregMatch($value, $input); |
75 |
tdb |
1.38 |
if (!isset($value)) { |
76 |
pjm2 |
1.8 |
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
77 |
pjm2 |
1.1 |
} |
78 |
|
|
?> |
79 |
|
|
<table border="0" width="100%"> |
80 |
|
|
<tr> |
81 |
pjm2 |
1.24 |
<td width="50%" align="right" valign="top"> |
82 |
|
|
<b><?=$title?></b> |
83 |
|
|
</td> |
84 |
|
|
<td width="50%" align="left" valign="top"> |
85 |
|
|
<? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
86 |
tdb |
1.42 |
linkToHistory($graph); |
87 |
pjm2 |
1.24 |
} ?> |
88 |
|
|
<?=$value?></td> |
89 |
pjm2 |
1.1 |
</tr> |
90 |
|
|
</table> |
91 |
|
|
<? |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
|
95 |
tdb |
1.42 |
function linkToHistory($graph) { |
96 |
pjm2 |
1.20 |
global $machine; |
97 |
tdb |
1.42 |
if(!empty($graph)) { |
98 |
|
|
echo <<<EOT |
99 |
|
|
<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> |
100 |
pjm2 |
1.20 |
EOT; |
101 |
tdb |
1.42 |
} |
102 |
pjm2 |
1.20 |
} |
103 |
|
|
|
104 |
|
|
|
105 |
tdb |
1.46 |
# convert bytes to MB |
106 |
|
|
function b2Mb($bytes) { |
107 |
|
|
$mb = $bytes / (1024*1024); |
108 |
|
|
return (int) $mb; |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
|
112 |
|
|
# Convert seconds uptime to something readable |
113 |
|
|
function uptime($until) { |
114 |
|
|
$day = date('z', $until); |
115 |
|
|
$hour = date('G', $until); |
116 |
|
|
$hour = $hour - 1; # one too many |
117 |
|
|
$minute = date('i', $until); |
118 |
|
|
$return = ""; |
119 |
|
|
if ($day) { |
120 |
|
|
$return = "$return$day Days "; |
121 |
|
|
} |
122 |
|
|
if ($hour) { |
123 |
|
|
$return = "$return$hour Hours "; |
124 |
|
|
} |
125 |
|
|
return "$return$minute Mins"; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
|
129 |
pjm2 |
1.28 |
# show all disk information. |
130 |
|
|
function showDisks($diskRoot, $units, $input) { |
131 |
|
|
include("latest_config.inc.php"); |
132 |
|
|
|
133 |
|
|
$i = 0; |
134 |
|
|
while(1) { |
135 |
|
|
$name = getPregMatch("$diskRoot.p$i.attributes.name", $input); |
136 |
pjm2 |
1.31 |
$mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input); |
137 |
|
|
if ($name || $mount) { |
138 |
|
|
$used = "$diskRoot.p$i.attributes.used"; |
139 |
tdb |
1.44 |
$total = "$diskRoot.p$i.attributes.total"; |
140 |
tdb |
1.42 |
$graph = preg_replace("/_/", "$hex_underscore", $mount); |
141 |
|
|
$graph = preg_replace("/\//", "$hex_slash", $graph); |
142 |
tdb |
1.43 |
$totalinodes = getPregMatch("$diskRoot.p$i.attributes.totalinodes", $input); |
143 |
|
|
$freeinodes = getPregMatch("$diskRoot.p$i.attributes.freeinodes", $input); |
144 |
tdb |
1.44 |
showBar("$name ($mount)<br>space used", $used, $total, $units, $input, "disk-$graph"); |
145 |
tdb |
1.46 |
showBar("inodes used", (float) $freeinodes, (float) $totalinodes, " inodes", $input, "", "swap"); |
146 |
|
|
showStat("FS Type", "$diskRoot.p$i.attributes.fstype", $input); |
147 |
tdb |
1.43 |
print " <br><br>\n"; |
148 |
pjm2 |
1.28 |
} |
149 |
pjm2 |
1.30 |
else { |
150 |
|
|
break; |
151 |
|
|
} |
152 |
pjm2 |
1.28 |
$i++; |
153 |
|
|
} |
154 |
|
|
} |
155 |
tdb |
1.44 |
|
156 |
|
|
|
157 |
|
|
# show all disk IO information. |
158 |
|
|
function showDiskIO($diskRoot, $input) { |
159 |
|
|
include("latest_config.inc.php"); |
160 |
|
|
|
161 |
|
|
$i = 0; |
162 |
|
|
while(1) { |
163 |
|
|
$name = getPregMatch("$diskRoot.p$i.attributes.name", $input); |
164 |
|
|
if ($name) { |
165 |
|
|
print "<br><center><b>(Disk $name)</b></center>"; |
166 |
|
|
showStat("Read bytes (per sec)", "$diskRoot.p$i.attributes.rbytes", $input, "diskio-$name"); |
167 |
|
|
showStat("Write bytes (per sec)", "$diskRoot.p$i.attributes.wbytes", $input, "diskio-$name"); |
168 |
|
|
print " <br>\n"; |
169 |
|
|
} |
170 |
|
|
else { |
171 |
|
|
break; |
172 |
|
|
} |
173 |
|
|
$i++; |
174 |
|
|
} |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
|
178 |
|
|
# show all network information. |
179 |
|
|
function showNet($netRoot, $input) { |
180 |
|
|
include("latest_config.inc.php"); |
181 |
|
|
|
182 |
|
|
$i = 0; |
183 |
|
|
while(1) { |
184 |
|
|
$name = getPregMatch("$netRoot.p$i.attributes.name", $input); |
185 |
|
|
if ($name) { |
186 |
|
|
print "<br><center><b>(Network Interface $name)</b></center>"; |
187 |
|
|
showStat("Received bytes (per sec)", "$netRoot.p$i.attributes.rx", $input, "net-$name"); |
188 |
|
|
showStat("Transfered bytes (per sec)", "$netRoot.p$i.attributes.tx", $input, "net-$name"); |
189 |
|
|
print " <br>\n"; |
190 |
|
|
} |
191 |
|
|
else { |
192 |
|
|
break; |
193 |
|
|
} |
194 |
|
|
$i++; |
195 |
|
|
} |
196 |
|
|
} |
197 |
|
|
|
198 |
tdb |
1.46 |
# show all mail queue information |
199 |
|
|
function showMailQ($mailqRoot, $input) { |
200 |
|
|
include("latest_config.inc.php"); |
201 |
|
|
|
202 |
|
|
$i = 0; |
203 |
|
|
while(1) { |
204 |
|
|
$name = getPregMatch("$mailqRoot.p$i.attributes.name", $input); |
205 |
|
|
if ($name) { |
206 |
|
|
print "<br><center><b>($name)</b></center>"; |
207 |
|
|
$name = preg_replace("/\s+/", "", $name); |
208 |
|
|
showStat("Messages in queue", "$mailqRoot.p$i.attributes.size", $input, "mailq-$name"); |
209 |
|
|
print " <br>\n"; |
210 |
|
|
} |
211 |
|
|
else { |
212 |
|
|
break; |
213 |
|
|
} |
214 |
|
|
$i++; |
215 |
|
|
} |
216 |
|
|
} |
217 |
pjm2 |
1.28 |
|
218 |
|
|
# Return a preg_match result. |
219 |
|
|
function getPregMatch($value, $input) { |
220 |
pjm2 |
1.29 |
preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches); |
221 |
pjm2 |
1.28 |
return $matches[1]; |
222 |
|
|
} |
223 |
|
|
|
224 |
|
|
|
225 |
pjm2 |
1.1 |
# show a bar-represented value. |
226 |
tdb |
1.42 |
function showBar($title, $value, $max, $units, $input, $graph="", $arrange='normal') { |
227 |
pjm2 |
1.1 |
|
228 |
|
|
include("latest_config.inc.php"); |
229 |
|
|
|
230 |
pjm2 |
1.22 |
$report = $value; |
231 |
tdb |
1.43 |
if (!is_int($value)) { |
232 |
|
|
$value = getPregMatch($value, $input); |
233 |
|
|
} |
234 |
pjm2 |
1.1 |
if (!is_int($max)) { |
235 |
pjm2 |
1.28 |
$max = getPregMatch($max, $input); |
236 |
pjm2 |
1.1 |
} |
237 |
tdb |
1.40 |
if (!isset($value) || !isset($max)) { |
238 |
pjm2 |
1.1 |
return; |
239 |
|
|
} |
240 |
|
|
|
241 |
pjm2 |
1.26 |
if ($arrange == 'swap') { |
242 |
pjm2 |
1.27 |
$value = $max - $value; |
243 |
tdb |
1.46 |
} |
244 |
|
|
|
245 |
|
|
if ($units == 'MB') { |
246 |
|
|
$value = b2Mb ($value); |
247 |
|
|
$max = b2Mb ($max); |
248 |
pjm2 |
1.26 |
} |
249 |
pjm2 |
1.27 |
|
250 |
tdb |
1.40 |
if(empty($max)) { |
251 |
pjm2 |
1.35 |
$width = 1; |
252 |
tdb |
1.40 |
} |
253 |
|
|
else { |
254 |
|
|
$width = intval($max_width * $value / $max); |
255 |
|
|
if ($width < 1) { |
256 |
|
|
$width = 1; |
257 |
|
|
} |
258 |
pjm2 |
1.35 |
} |
259 |
|
|
|
260 |
pjm2 |
1.1 |
?> |
261 |
pjm2 |
1.10 |
<table border="0" cellpadding="0" cellspacing="0" align="center"> |
262 |
pjm2 |
1.1 |
<tr> |
263 |
tdb |
1.42 |
<td colspan="2"><? linkToHistory($graph); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
264 |
pjm2 |
1.1 |
</tr> |
265 |
|
|
<tr> |
266 |
|
|
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
267 |
|
|
</tr> |
268 |
|
|
<tr> |
269 |
|
|
<td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td> |
270 |
|
|
</tr> |
271 |
|
|
<tr> |
272 |
pjm2 |
1.13 |
<td align="left">0<?=$units?></td> |
273 |
|
|
<td align="right"><?=$max?><?=$units?></td> |
274 |
pjm2 |
1.15 |
</tr> |
275 |
pjm2 |
1.1 |
</table> |
276 |
|
|
<? |
277 |
|
|
} |
278 |
|
|
|
279 |
|
|
|
280 |
|
|
?> |
281 |
|
|
|
282 |
|
|
<? include($titleHTML); ?> |
283 |
|
|
|
284 |
pjm2 |
1.12 |
<? printLine("Display the latest information received from a host"); ?> |
285 |
pjm2 |
1.1 |
|
286 |
|
|
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
287 |
|
|
<? |
288 |
|
|
|
289 |
pjm2 |
1.5 |
$file_array = getdirArray($latestDirectory,'asort'); |
290 |
pjm2 |
1.1 |
print "<select size=\"1\" name=\"machine\">"; |
291 |
|
|
if ($machine) { ?> |
292 |
|
|
<option selected value="<? echo $machine ?>"><? echo $machine ?></option> |
293 |
|
|
<option value="">----------------</option> |
294 |
|
|
<? } |
295 |
|
|
foreach($file_array as $file_name) { |
296 |
pjm2 |
1.3 |
#if (is_dir($file_name)) { |
297 |
pjm2 |
1.1 |
print "<option value=\"$file_name\">$file_name</option>"; |
298 |
pjm2 |
1.3 |
#} |
299 |
pjm2 |
1.1 |
} |
300 |
|
|
print "</select>"; |
301 |
|
|
|
302 |
|
|
?> |
303 |
|
|
<input type="submit" name="submit" value="Display"> |
304 |
|
|
</form> |
305 |
|
|
|
306 |
|
|
<? if ($machine) { |
307 |
|
|
|
308 |
pjm2 |
1.12 |
$last_modified = filemtime("$latestDirectory/$machine/$latestData"); |
309 |
|
|
clearstatcache(); |
310 |
|
|
$data_age = time() - $last_modified; |
311 |
|
|
|
312 |
pjm2 |
1.36 |
$last_modified = date("l jS F Y - g:ia", $last_modified); |
313 |
pjm2 |
1.12 |
|
314 |
|
|
if ($data_age > $warning_age) { |
315 |
|
|
$warning = <<<EOT |
316 |
|
|
<br> |
317 |
|
|
<font color="red"><b> |
318 |
|
|
Warning: |
319 |
|
|
</b></font> |
320 |
|
|
This realtime report is too old to be considered recent |
321 |
|
|
EOT; |
322 |
|
|
} |
323 |
|
|
|
324 |
|
|
echo <<<EOT |
325 |
pjm2 |
1.16 |
<table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1"> |
326 |
pjm2 |
1.12 |
<tr> |
327 |
|
|
<td bgcolor="#000066"> |
328 |
|
|
|
329 |
|
|
</td> |
330 |
|
|
<td bgcolor="#ffffcc"> |
331 |
|
|
<font face="arial,sans-serif" size="2"> |
332 |
pjm2 |
1.24 |
<b>Receipt date:</b> $last_modified |
333 |
pjm2 |
1.12 |
$warning |
334 |
|
|
</font> |
335 |
|
|
</td> |
336 |
|
|
</tr> |
337 |
|
|
</table> |
338 |
|
|
EOT; |
339 |
|
|
|
340 |
pjm2 |
1.1 |
# Read the file. |
341 |
pjm2 |
1.25 |
if (file_exists("$latestDirectory/$machine/$latestData")) { |
342 |
|
|
$input = file("$latestDirectory/$machine/$latestData"); |
343 |
|
|
# All we need is the first line if there is more than one line. |
344 |
|
|
$input = $input[0]; |
345 |
|
|
} |
346 |
pjm2 |
1.1 |
|
347 |
tdb |
1.38 |
if (!isset($input)) { |
348 |
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."; |
349 |
pjm2 |
1.1 |
} |
350 |
|
|
else { |
351 |
|
|
# Display the data specified in the display include. |
352 |
|
|
include("latest_display.inc.php"); |
353 |
|
|
} |
354 |
pjm2 |
1.9 |
} |
355 |
pjm2 |
1.12 |
|
356 |
pjm2 |
1.1 |
?> |
357 |
|
|
|
358 |
pjm2 |
1.16 |
<? printLine(""); ?> |
359 |
pjm2 |
1.1 |
|
360 |
|
|
<? include($bottomHTML); ?> |