ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/php/alerts/alerts.php
Revision: 1.37
Committed: Fri Feb 11 14:05:29 2005 UTC (19 years, 9 months ago) by tdb
Branch: MAIN
Changes since 1.36: +11 -0 lines
Log Message:
Updates from skel (Daniel Piddock):

 - Fix overflow in disk inodes on PHP page.
 - Added code to get passed in variables from the $_GET variable. Makes
   things work under a pretty default Debian apache2/php4 set up.
 - Graphs displays "Network IO" in the drop down list, not "Network usage"
   for consistency with everything else.
 - Display Swap, memory and disk usage in MB rather than bytes in latest
   view.
 - Display uptime in a pretty days/hours/minutes/seconds rather than just
   seconds, in latest view
 - Include file system type under Disks in latest view

Thanks Daniel!

File Contents

# User Rev Content
1 pjm2 1.1 <?php
2    
3 tdb 1.34 #
4     # i-scream central monitoring system
5 tdb 1.36 # http://www.i-scream.org
6 tdb 1.34 # 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 alerts.
24     # pjm2@ukc.ac.uk
25     #
26     # CONFIGURABLE CONSTANTS: -
27    
28     include("alerts_config.inc.php");
29    
30     #
31     # END CONFIGURATION
32    
33     include("iutils.inc.php");
34    
35 tdb 1.37 if ($formMethod == "GET") {
36     # in order of public.php
37     $machine = $_GET['machine'];
38     $fontsize = $_GET['fontsize'];
39     $refresh = $_GET['refresh'];
40     $hideform = $_GET['hideform'];
41     $pagewidth = $_GET['pagewidth'];
42     $small = $_GET['small'];
43     $submit = $_GET['submit'];
44     }
45    
46 pjm2 1.1 function printLine($title) {
47     echo "<hr style=\"color:#9999ff;\">";
48     echo "<b>$title</b>";
49     }
50    
51 pjm2 1.2 function getValue($value, $alert) {
52     preg_match("/$value=([^\,\}]*)[\,\}]/", $alert, $matches);
53     return $matches[1];
54     }
55    
56 pjm2 1.14 function printAlert($machine, $alert, $small="") {
57 pjm2 1.5
58 pjm2 1.26 global $fontsize;
59    
60 pjm2 1.5 include("alerts_config.inc.php");
61    
62 pjm2 1.20 $alertLevelNum = getValue("alertLevel", $alert);
63 pjm2 1.2 $lastAlert = getValue("lastAlert", $alert);
64     $thresholdLevel = getValue("thresholdLevel", $alert);
65     $source = getValue("source", $alert);
66     $thresholdValue = getValue("thresholdValue", $alert);
67     $value = getValue("value", $alert);
68     $attributeName = getValue("attributeName", $alert);
69     $timeTillNextAlert = getValue("timeTillNextAlert", $alert);
70     $initialAlertTime = getValue("initialAlertTime", $alert);
71 pjm2 1.4
72 pjm2 1.25 if ($thresholdLevel == "1") {
73     $thresholdLevel = "Lower";
74     }
75     else if ($thresholdLevel == "2") {
76     $thresholdLevel = "Upper";
77     }
78     else {
79     $thresholdLevel = "Normal";
80     }
81    
82 pjm2 1.20 $alertColour = $alertLevelColours[$alertLevelNum];
83     $alertLevel = $alertLevelNames[$alertLevelNum];
84 pjm2 1.6 $initialAlertTime = strftime("%x %X", intval($initialAlertTime / 1000));
85 pjm2 1.5
86 pjm2 1.27 if ($small == "on") {
87 pjm2 1.16 echo <<<EOT
88     <tr>
89 pjm2 1.17 <td width="50">
90     &nbsp;
91     </td>
92 pjm2 1.30 <td>
93 pjm2 1.20 <img src="level$alertLevelNum.gif" width="41" height="9" border="0" alt="$alertLevel">
94     </td>
95 pjm2 1.30 <td>
96 pjm2 1.26 <font size="$fontsize" color="$alertColour"><b>$alertLevel</b></font>
97 pjm2 1.17 </td>
98 pjm2 1.30 <td>
99 tdb 1.33 <font size="$fontsize">$attributeName (c:$value t:$thresholdValue)</font>
100 pjm2 1.17 </td>
101 pjm2 1.16 <td>
102 pjm2 1.17 &nbsp;
103 pjm2 1.16 </td>
104     </tr>
105     EOT;
106 pjm2 1.13 }
107     else {
108     echo <<<EOT
109    
110 pjm2 1.22 <table border="0" cellspacing="5" width="100%">
111 pjm2 1.13 <tr>
112 pjm2 1.23 <td align="left" width="40%">
113 pjm2 1.21 <img src="level$alertLevelNum.gif" width="41" height="9" border="0" alt="$alertLevel">
114     <font color="$alertColour" size="2"><b>$alertLevel</b></font>
115     </td>
116 pjm2 1.23 <td align="right" width="60%">
117 pjm2 1.22 <b>$attributeName</b>
118     </td>
119     </tr>
120     <tr>
121     <td align="right"><font size="2">Threshold:</font></td>
122 pjm2 1.25 <td align="left">$thresholdValue ($thresholdLevel)</td>
123 pjm2 1.13 </tr>
124     <tr>
125 pjm2 1.22 <td align="right"><font size="2">Alert value:</font></td>
126     <td align="left"><b>$value</b></td>
127 pjm2 1.13 </tr>
128     <tr>
129 pjm2 1.22 <td align="right"><font size="2">Initially raised:</font></td>
130     <td align="left">$initialAlertTime</td>
131 pjm2 1.13 </tr>
132     </table>
133    
134 pjm2 1.4 EOT;
135 pjm2 1.13 printLine("");
136     }
137 pjm2 1.4
138 pjm2 1.1 }
139    
140 pjm2 1.14 function printReports($machine, $small="") {
141 pjm2 1.26 global $fontsize;
142    
143 pjm2 1.7 # Get a list of all files in the machine's directory.
144     include("alerts_config.inc.php");
145     $alertArray = getdirArray("$alertDirectory/$machine", 'rsort');
146    
147 pjm2 1.27 if ($small == "on") {
148 pjm2 1.15 echo <<<EOT
149 pjm2 1.30 <table border="0" cellpadding="2" cellspacing="6">
150 pjm2 1.15 <tr>
151 pjm2 1.20 <td colspan="5">
152 pjm2 1.26 <font size="$fontsize"><b><a href="alerts.php?machine=$machine" style="color: black; text-decoration: none;">$machine</a></b></font>
153 pjm2 1.15 </td>
154     </tr>
155     EOT;
156 pjm2 1.14 }
157     else {
158     echo <<<EOT
159     <p>&nbsp;</p>
160     <table border="0" cellpadding="3" cellspacing="2" bgcolor="#000066" width="100%">
161 pjm2 1.30 <tr>
162 pjm2 1.14 <td>
163     <font color="white">
164     <b>
165 pjm2 1.24 Current alerts for <a href="latest.php?machine=$machine" style="color: white">$machine</a>
166 pjm2 1.14 </b>
167     <font size="2">
168     <br>Sorted by time, latest first.
169     </font>
170     </font>
171     </td>
172     </tr>
173     <tr>
174     <td bgcolor="white">
175 pjm2 1.7
176     EOT;
177    
178 pjm2 1.14 printLine("");
179     }
180 pjm2 1.7
181 pjm2 1.8 if ($alertArray != FALSE) {
182    
183     foreach($alertArray as $file_name) {
184     $input = file("$alertDirectory/$machine/$file_name");
185     $input = $input[0];
186     $alerts[] = $input;
187     }
188    
189     foreach ($alerts as $alert) {
190 pjm2 1.14 printAlert($machine, $alert, $small);
191 pjm2 1.8 }
192 pjm2 1.7 }
193 pjm2 1.8 else {
194 pjm2 1.27 if ($small != "on") {
195 pjm2 1.21 echo "There are currently no alerts held about <b>$machine</b>";
196     printLine("");
197     }
198 pjm2 1.7 }
199 pjm2 1.10
200 pjm2 1.27 if ($small == "on") {
201 pjm2 1.31 echo <<<EOT
202     <tr>
203     <td colspan="5">&nbsp;</td>
204     </tr>
205     </table>
206     EOT;
207 pjm2 1.14 }
208     else {
209     echo <<<EOT
210     </td>
211     </tr>
212     </table>
213 pjm2 1.10 EOT;
214 pjm2 1.14 }
215 pjm2 1.4 }
216    
217    
218 pjm2 1.1 ?>
219    
220     <? include($titleHTML); ?>
221    
222 pjm2 1.28 <? if ($hideform != "on") { ?>
223 pjm2 1.18
224 pjm2 1.16 <? printLine("Latest alerts for hosts"); ?>
225 pjm2 1.1
226     <form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>">
227     <?
228    
229     $file_array = getdirArray($alertDirectory,'asort');
230     print "<select size=\"1\" name=\"machine\">";
231     if ($machine) { ?>
232     <option selected value="<? echo $machine ?>"><? echo $machine ?></option>
233     <option value="">----------------</option>
234     <? }
235 pjm2 1.9 foreach ($file_array as $file_name) {
236 pjm2 1.1 #if (is_dir($file_name)) {
237     print "<option value=\"$file_name\">$file_name</option>";
238     #}
239     }
240     print "</select>";
241    
242     ?>
243 pjm2 1.14 <input type="hidden" name="small" value="<?=$small?>">
244 pjm2 1.1 <input type="submit" name="submit" value="Display">
245     </form>
246 pjm2 1.16
247     <? } ?>
248 pjm2 1.1
249     <? if ($machine) {
250 pjm2 1.3
251     printLine("");
252 pjm2 1.1
253 pjm2 1.32 $masterwidth = "";
254     if ($small != "on") {
255     $masterwidth = ' width="100%"';
256     }
257    
258     echo <<<EOT
259     <table border="0" align="center"$masterwidth>
260     <tr>
261     <td>
262     EOT;
263    
264 pjm2 1.9 if ($machine == "ALL") {
265     $machine_array = getdirArray($alertDirectory, 'asort');
266 pjm2 1.12 if ($machine_array != FALSE) {
267     foreach ($machine_array as $machine) {
268 pjm2 1.14 printReports($machine, $small);
269 pjm2 1.12 }
270 tdb 1.33 }
271     else {
272     print "<font size='$fontsize'><b>There are currently no alerts</b></font>";
273 pjm2 1.9 }
274     }
275     else {
276 pjm2 1.14 printReports($machine, $small);
277 pjm2 1.9 }
278 pjm2 1.1
279 pjm2 1.32 echo <<<EOT
280     </td>
281     </tr>
282     </table>
283     EOT;
284 pjm2 1.5 }
285     else {
286     printLine("");
287 pjm2 1.1 }
288    
289     ?>
290    
291     <? include($bottomHTML); ?>