1 |
|
<?php |
2 |
|
|
3 |
+ |
# |
4 |
+ |
# i-scream central monitoring system |
5 |
+ |
# http://www.i-scream.org.uk |
6 |
+ |
# 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 |
|
# Navigation for the i-scream reports. |
24 |
|
# pjm2@ukc.ac.uk |
25 |
|
# |
33 |
|
include("iutils.inc.php"); |
34 |
|
|
35 |
|
function printLine($title) { |
36 |
< |
echo "<hr color=\"#9999ff\">"; |
36 |
> |
echo "<hr style=\"color:#9999ff;\">"; |
37 |
|
echo "<b>$title</b>"; |
38 |
|
} |
39 |
|
|
40 |
|
|
41 |
< |
function showStat($title, $value, $input) { |
42 |
< |
preg_match("/$value=([^\,]*)[\,\}]/", $input, $matches); |
43 |
< |
$value = $matches[1]; |
44 |
< |
if (empty($value)) { |
41 |
> |
function showStat($title, $value, $input, $graph="") { |
42 |
> |
|
43 |
> |
$report = $value; |
44 |
> |
|
45 |
> |
$value = getPregMatch($value, $input); |
46 |
> |
if (!isset($value)) { |
47 |
|
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
48 |
|
} |
49 |
|
?> |
50 |
|
<table border="0" width="100%"> |
51 |
|
<tr> |
52 |
< |
<td width="50%" align="right" valign="top"><b><?=$title?></b></td> |
53 |
< |
<td width="50%" align="left" valign="top"><?=$value?></td> |
52 |
> |
<td width="50%" align="right" valign="top"> |
53 |
> |
<b><?=$title?></b> |
54 |
> |
</td> |
55 |
> |
<td width="50%" align="left" valign="top"> |
56 |
> |
<? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
57 |
> |
linkToHistory($graph); |
58 |
> |
} ?> |
59 |
> |
<?=$value?></td> |
60 |
|
</tr> |
61 |
|
</table> |
62 |
|
<? |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
+ |
function linkToHistory($graph) { |
67 |
+ |
global $machine; |
68 |
+ |
if(!empty($graph)) { |
69 |
+ |
echo <<<EOT |
70 |
+ |
<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> |
71 |
+ |
EOT; |
72 |
+ |
} |
73 |
+ |
} |
74 |
+ |
|
75 |
+ |
|
76 |
+ |
# show all disk information. |
77 |
+ |
function showDisks($diskRoot, $units, $input) { |
78 |
+ |
include("latest_config.inc.php"); |
79 |
+ |
|
80 |
+ |
$i = 0; |
81 |
+ |
while(1) { |
82 |
+ |
$name = getPregMatch("$diskRoot.p$i.attributes.name", $input); |
83 |
+ |
$mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input); |
84 |
+ |
if ($name || $mount) { |
85 |
+ |
$used = "$diskRoot.p$i.attributes.used"; |
86 |
+ |
$kbytes = "$diskRoot.p$i.attributes.kbytes"; |
87 |
+ |
$graph = preg_replace("/_/", "$hex_underscore", $mount); |
88 |
+ |
$graph = preg_replace("/\//", "$hex_slash", $graph); |
89 |
+ |
$totalinodes = getPregMatch("$diskRoot.p$i.attributes.totalinodes", $input); |
90 |
+ |
$freeinodes = getPregMatch("$diskRoot.p$i.attributes.freeinodes", $input); |
91 |
+ |
showBar("$name ($mount)<br>space used", $used, $kbytes, $units, $input, "disk-$graph"); |
92 |
+ |
showBar("inodes used", (int) $freeinodes, (int) $totalinodes, " inodes", $input, "", "swap"); |
93 |
+ |
print " <br><br>\n"; |
94 |
+ |
} |
95 |
+ |
else { |
96 |
+ |
break; |
97 |
+ |
} |
98 |
+ |
$i++; |
99 |
+ |
} |
100 |
+ |
} |
101 |
+ |
|
102 |
+ |
# Return a preg_match result. |
103 |
+ |
function getPregMatch($value, $input) { |
104 |
+ |
preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches); |
105 |
+ |
return $matches[1]; |
106 |
+ |
} |
107 |
+ |
|
108 |
+ |
|
109 |
|
# show a bar-represented value. |
110 |
< |
function showBar($title, $value, $max, $units, $input) { |
110 |
> |
function showBar($title, $value, $max, $units, $input, $graph="", $arrange='normal') { |
111 |
|
|
112 |
|
include("latest_config.inc.php"); |
113 |
|
|
114 |
< |
preg_match("/$value=([^\,]*)\,/", $input, $matches); |
115 |
< |
$value = $matches[1]; |
114 |
> |
$report = $value; |
115 |
> |
if (!is_int($value)) { |
116 |
> |
$value = getPregMatch($value, $input); |
117 |
> |
} |
118 |
|
if (!is_int($max)) { |
119 |
< |
preg_match("/$max=([^\,]*)\,/", $input, $matches); |
47 |
< |
$max = $matches[1]; |
119 |
> |
$max = getPregMatch($max, $input); |
120 |
|
} |
121 |
< |
if (empty($value) || empty($max)) { |
121 |
> |
if (!isset($value) || !isset($max)) { |
122 |
|
return; |
123 |
|
} |
124 |
|
|
125 |
< |
$width = intval($max_width * $value / $max); |
125 |
> |
if ($arrange == 'swap') { |
126 |
> |
$value = $max - $value; |
127 |
> |
} |
128 |
|
|
129 |
+ |
if(empty($max)) { |
130 |
+ |
$width = 1; |
131 |
+ |
} |
132 |
+ |
else { |
133 |
+ |
$width = intval($max_width * $value / $max); |
134 |
+ |
if ($width < 1) { |
135 |
+ |
$width = 1; |
136 |
+ |
} |
137 |
+ |
} |
138 |
+ |
|
139 |
|
?> |
140 |
|
<table border="0" cellpadding="0" cellspacing="0" align="center"> |
141 |
|
<tr> |
142 |
< |
<td colspan="2"><b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
142 |
> |
<td colspan="2"><? linkToHistory($graph); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
143 |
|
</tr> |
144 |
|
<tr> |
145 |
|
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
151 |
|
<td align="left">0<?=$units?></td> |
152 |
|
<td align="right"><?=$max?><?=$units?></td> |
153 |
|
</tr> |
70 |
– |
<tr> |
71 |
– |
<td colspan="2"> </td> |
72 |
– |
</tr> |
154 |
|
</table> |
155 |
|
<? |
156 |
|
} |
188 |
|
clearstatcache(); |
189 |
|
$data_age = time() - $last_modified; |
190 |
|
|
191 |
< |
$last_modified = date("l jS F - g:ia", $last_modified); |
191 |
> |
$last_modified = date("l jS F Y - g:ia", $last_modified); |
192 |
|
|
193 |
|
if ($data_age > $warning_age) { |
194 |
|
$warning = <<<EOT |
208 |
|
</td> |
209 |
|
<td bgcolor="#ffffcc"> |
210 |
|
<font face="arial,sans-serif" size="2"> |
211 |
< |
<b>Recipt date:</b> $last_modified |
211 |
> |
<b>Receipt date:</b> $last_modified |
212 |
|
$warning |
213 |
|
</font> |
214 |
|
</td> |
217 |
|
EOT; |
218 |
|
|
219 |
|
# Read the file. |
220 |
< |
#$input = "packet.attributes.machine_name=raptor.ukc.ac.uk,packet.memory.free=10,packet.memory.total=100,"; |
221 |
< |
$input = file("$latestDirectory/$machine/$latestData"); |
222 |
< |
# All we need is the first line if there is more than one line. |
223 |
< |
$input = $input[0]; |
220 |
> |
if (file_exists("$latestDirectory/$machine/$latestData")) { |
221 |
> |
$input = file("$latestDirectory/$machine/$latestData"); |
222 |
> |
# All we need is the first line if there is more than one line. |
223 |
> |
$input = $input[0]; |
224 |
> |
} |
225 |
|
|
226 |
< |
if (empty($input)) { |
227 |
< |
echo "<br><br>There was an error reading from the latest packet received. Please notify your i-scream server administrator."; |
226 |
> |
if (!isset($input)) { |
227 |
> |
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."; |
228 |
|
} |
229 |
|
else { |
230 |
|
# Display the data specified in the display include. |