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