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.39
Committed: Fri Mar 11 16:54:04 2005 UTC (19 years, 8 months ago) by tdb
Branch: MAIN
Changes since 1.38: +0 -2 lines
Log Message:
Minor fixes - thanks Skel :-)

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