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.16
Committed: Wed Mar 21 12:22:16 2001 UTC (23 years, 7 months ago) by pjm2
Branch: MAIN
Changes since 1.15: +13 -3 lines
Log Message:
Small versions of the reports now also have the alert level shown, and
also in the approprite colour

File Contents

# User Rev Content
1 pjm2 1.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 pjm2 1.2 function getValue($value, $alert) {
21     preg_match("/$value=([^\,\}]*)[\,\}]/", $alert, $matches);
22     return $matches[1];
23     }
24    
25 pjm2 1.14 function printAlert($machine, $alert, $small="") {
26 pjm2 1.5
27     include("alerts_config.inc.php");
28    
29 pjm2 1.2 $alertLevel = getValue("alertLevel", $alert);
30     $lastAlert = getValue("lastAlert", $alert);
31     $thresholdLevel = getValue("thresholdLevel", $alert);
32     $source = getValue("source", $alert);
33     $thresholdValue = getValue("thresholdValue", $alert);
34     $value = getValue("value", $alert);
35     $attributeName = getValue("attributeName", $alert);
36     $timeTillNextAlert = getValue("timeTillNextAlert", $alert);
37     $initialAlertTime = getValue("initialAlertTime", $alert);
38 pjm2 1.4
39 pjm2 1.5 $alertColour = $alertLevelColours[$alertLevel];
40     $alertLevel = $alertLevelNames[$alertLevel];
41 pjm2 1.6 $initialAlertTime = strftime("%x %X", intval($initialAlertTime / 1000));
42 pjm2 1.5
43 pjm2 1.14 if ($small == "true") {
44 pjm2 1.16 echo <<<EOT
45     <tr>
46     <td>
47     <font size="2">$attributeName <font color="$alertColour"><b>$alertLevel</b></font></font>
48     </td>
49     </tr>
50     EOT;
51 pjm2 1.13 }
52     else {
53     echo <<<EOT
54    
55     <table border="0" cellspacing="5">
56     <tr>
57     <td><b>$attributeName</b></td>
58     <td>&nbsp;</td>
59     <td><font color="$alertColour" size="2"><b>$alertLevel</b></font></td>
60     <td>&nbsp;</td>
61     </tr>
62     <tr>
63     <td><font size="2">Threshold:</font></td>
64     <td>$thresholdValue</td>
65     <td><font size="2">Initially raised:</font></td>
66     <td>$initialAlertTime</td>
67     </tr>
68     <tr>
69     <td><font size="2">Alert value:</font></td>
70     <td><b>$value</b></td>
71     <td><!--Next alert time:--> </td>
72     <td><!--$timeTillNextAlert--> </td>
73     </tr>
74     </table>
75    
76 pjm2 1.4 EOT;
77 pjm2 1.13 printLine("");
78     }
79 pjm2 1.4
80 pjm2 1.1 }
81    
82 pjm2 1.14 function printReports($machine, $small="") {
83 pjm2 1.7 # Get a list of all files in the machine's directory.
84     include("alerts_config.inc.php");
85     $alertArray = getdirArray("$alertDirectory/$machine", 'rsort');
86    
87 pjm2 1.14 if ($small == "true") {
88 pjm2 1.15 echo <<<EOT
89 pjm2 1.16 <table border="0" cellpadding="2" cellspacing="0" bgcolor="#ffffff" width="100%">
90 pjm2 1.15 <tr>
91     <td bgcolor="#000066">
92     <font color="white"><b>$machine</b></font>
93     </td>
94     </tr>
95     EOT;
96 pjm2 1.14 }
97     else {
98     echo <<<EOT
99     <p>&nbsp;</p>
100     <table border="0" cellpadding="3" cellspacing="2" bgcolor="#000066" width="100%">
101     <tr>
102     <td>
103     <font color="white">
104     <b>
105     Current alerts for $machine
106     </b>
107     <font size="2">
108     <br>Sorted by time, latest first.
109     </font>
110     </font>
111     </td>
112     </tr>
113     <tr>
114     <td bgcolor="white">
115 pjm2 1.7
116     EOT;
117    
118 pjm2 1.14 printLine("");
119     }
120 pjm2 1.7
121 pjm2 1.8 if ($alertArray != FALSE) {
122    
123     foreach($alertArray as $file_name) {
124     $input = file("$alertDirectory/$machine/$file_name");
125     $input = $input[0];
126     $alerts[] = $input;
127     }
128    
129     foreach ($alerts as $alert) {
130 pjm2 1.14 printAlert($machine, $alert, $small);
131 pjm2 1.8 }
132 pjm2 1.7 }
133 pjm2 1.8 else {
134     echo "There are currently no alerts held about <b>$machine</b>";
135 pjm2 1.11 printLine("");
136 pjm2 1.7 }
137 pjm2 1.10
138 pjm2 1.14 if ($small == "true") {
139 pjm2 1.15 echo "</table>";
140 pjm2 1.14 }
141     else {
142     echo <<<EOT
143     </td>
144     </tr>
145     </table>
146 pjm2 1.10 EOT;
147 pjm2 1.14 }
148 pjm2 1.4 }
149    
150    
151 pjm2 1.1 ?>
152    
153     <? include($titleHTML); ?>
154    
155 pjm2 1.16 <? printLine("Latest alerts for hosts"); ?>
156    
157     <? if (!$hideform) { ?>
158 pjm2 1.1
159     <form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>">
160     <?
161    
162     $file_array = getdirArray($alertDirectory,'asort');
163     print "<select size=\"1\" name=\"machine\">";
164     if ($machine) { ?>
165     <option selected value="<? echo $machine ?>"><? echo $machine ?></option>
166     <option value="">----------------</option>
167     <? }
168 pjm2 1.9 foreach ($file_array as $file_name) {
169 pjm2 1.1 #if (is_dir($file_name)) {
170     print "<option value=\"$file_name\">$file_name</option>";
171     #}
172     }
173     print "</select>";
174    
175     ?>
176 pjm2 1.14 <input type="hidden" name="small" value="<?=$small?>">
177 pjm2 1.1 <input type="submit" name="submit" value="Display">
178     </form>
179 pjm2 1.16
180     <? } ?>
181 pjm2 1.1
182     <? if ($machine) {
183 pjm2 1.3
184     printLine("");
185 pjm2 1.1
186 pjm2 1.9 if ($machine == "ALL") {
187     $machine_array = getdirArray($alertDirectory, 'asort');
188 pjm2 1.12 if ($machine_array != FALSE) {
189     foreach ($machine_array as $machine) {
190 pjm2 1.14 printReports($machine, $small);
191 pjm2 1.12 }
192 pjm2 1.9 }
193     }
194     else {
195 pjm2 1.14 printReports($machine, $small);
196 pjm2 1.9 }
197 pjm2 1.1
198 pjm2 1.5 }
199     else {
200     printLine("");
201 pjm2 1.1 }
202    
203     ?>
204    
205     <? include($bottomHTML); ?>