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.20
Committed: Wed Mar 21 17:32:24 2001 UTC (23 years, 8 months ago) by pjm2
Branch: MAIN
Changes since 1.19: +7 -4 lines
Log Message:
Added level graphs to the small reports pages.
These work quite nicely!

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