| 1 |
pjm2 |
1.1 |
<?php |
| 2 |
|
|
|
| 3 |
tdb |
1.37 |
# |
| 4 |
|
|
# i-scream central monitoring system |
| 5 |
tdb |
1.41 |
# http://www.i-scream.org.uk |
| 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 |
pjm2 |
1.9 |
function printLine($title) { |
| 36 |
pjm2 |
1.19 |
echo "<hr style=\"color:#9999ff;\">"; |
| 37 |
pjm2 |
1.9 |
echo "<b>$title</b>"; |
| 38 |
pjm2 |
1.6 |
} |
| 39 |
|
|
|
| 40 |
pjm2 |
1.1 |
|
| 41 |
|
|
function showStat($title, $value, $input) { |
| 42 |
pjm2 |
1.24 |
|
| 43 |
|
|
$report = $value; |
| 44 |
|
|
|
| 45 |
pjm2 |
1.28 |
$value = getPregMatch($value, $input); |
| 46 |
tdb |
1.38 |
if (!isset($value)) { |
| 47 |
pjm2 |
1.8 |
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
| 48 |
pjm2 |
1.1 |
} |
| 49 |
|
|
?> |
| 50 |
|
|
<table border="0" width="100%"> |
| 51 |
|
|
<tr> |
| 52 |
pjm2 |
1.24 |
<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 |
pjm2 |
1.1 |
</tr> |
| 61 |
|
|
</table> |
| 62 |
|
|
<? |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
pjm2 |
1.20 |
function linkToHistory($report) { |
| 67 |
|
|
global $machine; |
| 68 |
|
|
$yesterday = date("Y-m-d", time() - 86400); |
| 69 |
|
|
echo <<<EOT |
| 70 |
pjm2 |
1.23 |
<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 |
pjm2 |
1.20 |
EOT; |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
|
|
|
| 75 |
pjm2 |
1.28 |
# 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 |
pjm2 |
1.31 |
$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 |
pjm2 |
1.34 |
showBar("$name<br>($mount)", $used, $kbytes, $units, $input); |
| 87 |
pjm2 |
1.28 |
} |
| 88 |
pjm2 |
1.30 |
else { |
| 89 |
|
|
break; |
| 90 |
|
|
} |
| 91 |
pjm2 |
1.28 |
$i++; |
| 92 |
|
|
} |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
|
|
# Return a preg_match result. |
| 96 |
|
|
function getPregMatch($value, $input) { |
| 97 |
pjm2 |
1.29 |
preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches); |
| 98 |
pjm2 |
1.28 |
return $matches[1]; |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
|
|
|
| 102 |
pjm2 |
1.1 |
# show a bar-represented value. |
| 103 |
pjm2 |
1.26 |
function showBar($title, $value, $max, $units, $input, $arrange='normal') { |
| 104 |
pjm2 |
1.1 |
|
| 105 |
|
|
include("latest_config.inc.php"); |
| 106 |
|
|
|
| 107 |
pjm2 |
1.22 |
$report = $value; |
| 108 |
|
|
|
| 109 |
pjm2 |
1.28 |
$value = getPregMatch($value, $input); |
| 110 |
pjm2 |
1.1 |
if (!is_int($max)) { |
| 111 |
pjm2 |
1.28 |
$max = getPregMatch($max, $input); |
| 112 |
pjm2 |
1.1 |
} |
| 113 |
tdb |
1.40 |
if (!isset($value) || !isset($max)) { |
| 114 |
pjm2 |
1.1 |
return; |
| 115 |
|
|
} |
| 116 |
|
|
|
| 117 |
pjm2 |
1.26 |
if ($arrange == 'swap') { |
| 118 |
pjm2 |
1.27 |
$value = $max - $value; |
| 119 |
pjm2 |
1.26 |
} |
| 120 |
pjm2 |
1.27 |
|
| 121 |
tdb |
1.40 |
if(empty($max)) { |
| 122 |
pjm2 |
1.35 |
$width = 1; |
| 123 |
tdb |
1.40 |
} |
| 124 |
|
|
else { |
| 125 |
|
|
$width = intval($max_width * $value / $max); |
| 126 |
|
|
if ($width < 1) { |
| 127 |
|
|
$width = 1; |
| 128 |
|
|
} |
| 129 |
pjm2 |
1.35 |
} |
| 130 |
|
|
|
| 131 |
pjm2 |
1.1 |
?> |
| 132 |
pjm2 |
1.10 |
<table border="0" cellpadding="0" cellspacing="0" align="center"> |
| 133 |
pjm2 |
1.1 |
<tr> |
| 134 |
pjm2 |
1.23 |
<td colspan="2"><? linkToHistory($report); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
| 135 |
pjm2 |
1.1 |
</tr> |
| 136 |
|
|
<tr> |
| 137 |
|
|
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
| 138 |
|
|
</tr> |
| 139 |
|
|
<tr> |
| 140 |
|
|
<td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td> |
| 141 |
|
|
</tr> |
| 142 |
|
|
<tr> |
| 143 |
pjm2 |
1.13 |
<td align="left">0<?=$units?></td> |
| 144 |
|
|
<td align="right"><?=$max?><?=$units?></td> |
| 145 |
pjm2 |
1.1 |
</tr> |
| 146 |
pjm2 |
1.15 |
<tr> |
| 147 |
|
|
<td colspan="2"> </td> |
| 148 |
|
|
</tr> |
| 149 |
pjm2 |
1.1 |
</table> |
| 150 |
|
|
<? |
| 151 |
|
|
} |
| 152 |
|
|
|
| 153 |
|
|
|
| 154 |
|
|
?> |
| 155 |
|
|
|
| 156 |
|
|
<? include($titleHTML); ?> |
| 157 |
|
|
|
| 158 |
pjm2 |
1.12 |
<? printLine("Display the latest information received from a host"); ?> |
| 159 |
pjm2 |
1.1 |
|
| 160 |
|
|
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
| 161 |
|
|
<? |
| 162 |
|
|
|
| 163 |
pjm2 |
1.5 |
$file_array = getdirArray($latestDirectory,'asort'); |
| 164 |
pjm2 |
1.1 |
print "<select size=\"1\" name=\"machine\">"; |
| 165 |
|
|
if ($machine) { ?> |
| 166 |
|
|
<option selected value="<? echo $machine ?>"><? echo $machine ?></option> |
| 167 |
|
|
<option value="">----------------</option> |
| 168 |
|
|
<? } |
| 169 |
|
|
foreach($file_array as $file_name) { |
| 170 |
pjm2 |
1.3 |
#if (is_dir($file_name)) { |
| 171 |
pjm2 |
1.1 |
print "<option value=\"$file_name\">$file_name</option>"; |
| 172 |
pjm2 |
1.3 |
#} |
| 173 |
pjm2 |
1.1 |
} |
| 174 |
|
|
print "</select>"; |
| 175 |
|
|
|
| 176 |
|
|
?> |
| 177 |
|
|
<input type="submit" name="submit" value="Display"> |
| 178 |
|
|
</form> |
| 179 |
|
|
|
| 180 |
|
|
<? if ($machine) { |
| 181 |
|
|
|
| 182 |
pjm2 |
1.12 |
$last_modified = filemtime("$latestDirectory/$machine/$latestData"); |
| 183 |
|
|
clearstatcache(); |
| 184 |
|
|
$data_age = time() - $last_modified; |
| 185 |
|
|
|
| 186 |
pjm2 |
1.36 |
$last_modified = date("l jS F Y - g:ia", $last_modified); |
| 187 |
pjm2 |
1.12 |
|
| 188 |
|
|
if ($data_age > $warning_age) { |
| 189 |
|
|
$warning = <<<EOT |
| 190 |
|
|
<br> |
| 191 |
|
|
<font color="red"><b> |
| 192 |
|
|
Warning: |
| 193 |
|
|
</b></font> |
| 194 |
|
|
This realtime report is too old to be considered recent |
| 195 |
|
|
EOT; |
| 196 |
|
|
} |
| 197 |
|
|
|
| 198 |
|
|
echo <<<EOT |
| 199 |
pjm2 |
1.16 |
<table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1"> |
| 200 |
pjm2 |
1.12 |
<tr> |
| 201 |
|
|
<td bgcolor="#000066"> |
| 202 |
|
|
|
| 203 |
|
|
</td> |
| 204 |
|
|
<td bgcolor="#ffffcc"> |
| 205 |
|
|
<font face="arial,sans-serif" size="2"> |
| 206 |
pjm2 |
1.24 |
<b>Receipt date:</b> $last_modified |
| 207 |
pjm2 |
1.12 |
$warning |
| 208 |
|
|
</font> |
| 209 |
|
|
</td> |
| 210 |
|
|
</tr> |
| 211 |
|
|
</table> |
| 212 |
|
|
EOT; |
| 213 |
|
|
|
| 214 |
pjm2 |
1.1 |
# Read the file. |
| 215 |
pjm2 |
1.25 |
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 |
pjm2 |
1.1 |
|
| 221 |
tdb |
1.38 |
if (!isset($input)) { |
| 222 |
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."; |
| 223 |
pjm2 |
1.1 |
} |
| 224 |
|
|
else { |
| 225 |
|
|
# Display the data specified in the display include. |
| 226 |
|
|
include("latest_display.inc.php"); |
| 227 |
|
|
} |
| 228 |
pjm2 |
1.9 |
} |
| 229 |
pjm2 |
1.12 |
|
| 230 |
pjm2 |
1.1 |
?> |
| 231 |
|
|
|
| 232 |
pjm2 |
1.16 |
<? printLine(""); ?> |
| 233 |
pjm2 |
1.1 |
|
| 234 |
|
|
<? include($bottomHTML); ?> |