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