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.33
Committed: Wed Feb 13 16:28:27 2002 UTC (22 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.32: +4 -1 lines
Log Message:
Just a few changes I've made to the live copy of the the php reports. About
time they were put back into CVS.

File Contents

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