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