| 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 |
|
# |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
function showStat($title, $value, $input) { |
| 42 |
< |
preg_match("/$value=([^\,]*)[\,\}]/", $input, $matches); |
| 43 |
< |
$value = $matches[1]; |
| 44 |
< |
if (empty($value)) { |
| 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($report); |
| 58 |
> |
} ?> |
| 59 |
> |
<?=$value?></td> |
| 60 |
|
</tr> |
| 61 |
|
</table> |
| 62 |
|
<? |
| 67 |
|
global $machine; |
| 68 |
|
$yesterday = date("Y-m-d", time() - 86400); |
| 69 |
|
echo <<<EOT |
| 70 |
< |
<a href="browser.php?machine_name=$machine&report=$report&day=$yesterday&submit=Show"><img src="minichart.gif" width="20" height="20" border="0"></a> |
| 70 |
> |
<a href="browser.php?machine_name=$machine&report=$report&day=$yesterday&submit=Show"><img src="minichart.gif" alt="View yesterday's 24-hour chart" width="20" height="20" border="0"></a> |
| 71 |
|
EOT; |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
+ |
# show all disk information. |
| 76 |
+ |
function showDisks($diskRoot, $units, $input) { |
| 77 |
+ |
include("latest_config.inc.php"); |
| 78 |
+ |
|
| 79 |
+ |
$i = 0; |
| 80 |
+ |
while(1) { |
| 81 |
+ |
$name = getPregMatch("$diskRoot.p$i.attributes.name", $input); |
| 82 |
+ |
$mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input); |
| 83 |
+ |
if ($name || $mount) { |
| 84 |
+ |
$used = "$diskRoot.p$i.attributes.used"; |
| 85 |
+ |
$kbytes = "$diskRoot.p$i.attributes.kbytes"; |
| 86 |
+ |
showBar("$name<br>($mount)", $used, $kbytes, $units, $input); |
| 87 |
+ |
} |
| 88 |
+ |
else { |
| 89 |
+ |
break; |
| 90 |
+ |
} |
| 91 |
+ |
$i++; |
| 92 |
+ |
} |
| 93 |
+ |
} |
| 94 |
+ |
|
| 95 |
+ |
# Return a preg_match result. |
| 96 |
+ |
function getPregMatch($value, $input) { |
| 97 |
+ |
preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches); |
| 98 |
+ |
return $matches[1]; |
| 99 |
+ |
} |
| 100 |
+ |
|
| 101 |
+ |
|
| 102 |
|
# show a bar-represented value. |
| 103 |
< |
function showBar($title, $value, $max, $units, $input) { |
| 103 |
> |
function showBar($title, $value, $max, $units, $input, $arrange='normal') { |
| 104 |
|
|
| 105 |
|
include("latest_config.inc.php"); |
| 106 |
|
|
| 107 |
< |
preg_match("/$value=([^\,]*)\,/", $input, $matches); |
| 108 |
< |
$value = $matches[1]; |
| 107 |
> |
$report = $value; |
| 108 |
> |
|
| 109 |
> |
$value = getPregMatch($value, $input); |
| 110 |
|
if (!is_int($max)) { |
| 111 |
< |
preg_match("/$max=([^\,]*)\,/", $input, $matches); |
| 56 |
< |
$max = $matches[1]; |
| 111 |
> |
$max = getPregMatch($max, $input); |
| 112 |
|
} |
| 113 |
< |
if (empty($value) || empty($max)) { |
| 113 |
> |
if (!isset($value) || !isset($max)) { |
| 114 |
|
return; |
| 115 |
|
} |
| 116 |
|
|
| 117 |
< |
$width = intval($max_width * $value / $max); |
| 117 |
> |
if ($arrange == 'swap') { |
| 118 |
> |
$value = $max - $value; |
| 119 |
> |
} |
| 120 |
|
|
| 121 |
+ |
if(empty($max)) { |
| 122 |
+ |
$width = 1; |
| 123 |
+ |
} |
| 124 |
+ |
else { |
| 125 |
+ |
$width = intval($max_width * $value / $max); |
| 126 |
+ |
if ($width < 1) { |
| 127 |
+ |
$width = 1; |
| 128 |
+ |
} |
| 129 |
+ |
} |
| 130 |
+ |
|
| 131 |
|
?> |
| 132 |
|
<table border="0" cellpadding="0" cellspacing="0" align="center"> |
| 133 |
|
<tr> |
| 134 |
< |
<td colspan="2"><b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
| 134 |
> |
<td colspan="2"><? linkToHistory($report); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
| 135 |
|
</tr> |
| 136 |
|
<tr> |
| 137 |
|
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
| 144 |
|
<td align="right"><?=$max?><?=$units?></td> |
| 145 |
|
</tr> |
| 146 |
|
<tr> |
| 80 |
– |
<td colspan="2"><? linkToHistory($value); ?> View yesterday's graph</td> |
| 81 |
– |
</tr> |
| 82 |
– |
<tr> |
| 147 |
|
<td colspan="2"> </td> |
| 148 |
|
</tr> |
| 149 |
|
</table> |
| 183 |
|
clearstatcache(); |
| 184 |
|
$data_age = time() - $last_modified; |
| 185 |
|
|
| 186 |
< |
$last_modified = date("l jS F - g:ia", $last_modified); |
| 186 |
> |
$last_modified = date("l jS F Y - g:ia", $last_modified); |
| 187 |
|
|
| 188 |
|
if ($data_age > $warning_age) { |
| 189 |
|
$warning = <<<EOT |
| 203 |
|
</td> |
| 204 |
|
<td bgcolor="#ffffcc"> |
| 205 |
|
<font face="arial,sans-serif" size="2"> |
| 206 |
< |
<b>Recipt date:</b> $last_modified |
| 206 |
> |
<b>Receipt date:</b> $last_modified |
| 207 |
|
$warning |
| 208 |
|
</font> |
| 209 |
|
</td> |
| 212 |
|
EOT; |
| 213 |
|
|
| 214 |
|
# Read the file. |
| 215 |
< |
#$input = "packet.attributes.machine_name=raptor.ukc.ac.uk,packet.memory.free=10,packet.memory.total=100,"; |
| 216 |
< |
$input = file("$latestDirectory/$machine/$latestData"); |
| 217 |
< |
# All we need is the first line if there is more than one line. |
| 218 |
< |
$input = $input[0]; |
| 215 |
> |
if (file_exists("$latestDirectory/$machine/$latestData")) { |
| 216 |
> |
$input = file("$latestDirectory/$machine/$latestData"); |
| 217 |
> |
# All we need is the first line if there is more than one line. |
| 218 |
> |
$input = $input[0]; |
| 219 |
> |
} |
| 220 |
|
|
| 221 |
< |
if (empty($input)) { |
| 222 |
< |
echo "<br><br>There was an error reading from the latest packet received. Please notify your i-scream server administrator."; |
| 221 |
> |
if (!isset($input)) { |
| 222 |
> |
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."; |
| 223 |
|
} |
| 224 |
|
else { |
| 225 |
|
# Display the data specified in the display include. |