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.38
Committed: Fri Mar 11 12:23:31 2005 UTC (19 years, 7 months ago) by tdb
Branch: MAIN
Changes since 1.37: +7 -10 lines
Log Message:
Updates from skel (Daniel Piddock):

 - Fix undefined variable warnings
 - Comment out auto-scroll code since it doesn't really work
 - Fix some minor formatting problems

Also various other updates to the main page and comments.

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