ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/php/latest/latest.php
Revision: 1.41
Committed: Tue May 21 16:47:15 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.40: +1 -0 lines
Log Message:
Added URL to GPL headers.

File Contents

# Content
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 #
26 # CONFIGURABLE CONSTANTS: -
27
28 include("latest_config.inc.php");
29
30 #
31 # END CONFIGURATION
32
33 include("iutils.inc.php");
34
35 function printLine($title) {
36 echo "<hr style=\"color:#9999ff;\">";
37 echo "<b>$title</b>";
38 }
39
40
41 function showStat($title, $value, $input) {
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">
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 <?
63 }
64
65
66 function linkToHistory($report) {
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" 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, $arrange='normal') {
104
105 include("latest_config.inc.php");
106
107 $report = $value;
108
109 $value = getPregMatch($value, $input);
110 if (!is_int($max)) {
111 $max = getPregMatch($max, $input);
112 }
113 if (!isset($value) || !isset($max)) {
114 return;
115 }
116
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"><? 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>
138 </tr>
139 <tr>
140 <td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td>
141 </tr>
142 <tr>
143 <td align="left">0<?=$units?></td>
144 <td align="right"><?=$max?><?=$units?></td>
145 </tr>
146 <tr>
147 <td colspan="2">&nbsp;</td>
148 </tr>
149 </table>
150 <?
151 }
152
153
154 ?>
155
156 <? include($titleHTML); ?>
157
158 <? printLine("Display the latest information received from a host"); ?>
159
160 <form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>">
161 <?
162
163 $file_array = getdirArray($latestDirectory,'asort');
164 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 #if (is_dir($file_name)) {
171 print "<option value=\"$file_name\">$file_name</option>";
172 #}
173 }
174 print "</select>";
175
176 ?>
177 <input type="submit" name="submit" value="Display">
178 </form>
179
180 <? if ($machine) {
181
182 $last_modified = filemtime("$latestDirectory/$machine/$latestData");
183 clearstatcache();
184 $data_age = time() - $last_modified;
185
186 $last_modified = date("l jS F Y - g:ia", $last_modified);
187
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 <table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1">
200 <tr>
201 <td bgcolor="#000066">
202 &nbsp;
203 </td>
204 <td bgcolor="#ffffcc">
205 <font face="arial,sans-serif" size="2">
206 <b>Receipt date:</b> $last_modified
207 $warning
208 </font>
209 </td>
210 </tr>
211 </table>
212 EOT;
213
214 # Read the file.
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 (!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.
226 include("latest_display.inc.php");
227 }
228 }
229
230 ?>
231
232 <? printLine(""); ?>
233
234 <? include($bottomHTML); ?>