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