1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.org.iscream.client; |
2 |
> |
package uk.org.iscream.cms.server.client; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.org.iscream.util.*; |
5 |
> |
import uk.org.iscream.cms.server.util.*; |
6 |
|
|
7 |
|
/** |
8 |
< |
* Alert Object |
8 |
> |
* An object to hold the state of an Alert. |
9 |
|
* |
10 |
+ |
* When an alert is generated, it has lots of information about |
11 |
+ |
* the cirscumstances and source of the alert. This object holds |
12 |
+ |
* the information. It is created by Monitors (specifically in the |
13 |
+ |
* fireAlert method of MonitorSkeleton). It then places the alert |
14 |
+ |
* in the alert queue for Alerters to read and process. |
15 |
+ |
* |
16 |
|
* @author $Author$ |
17 |
|
* @version $Id$ |
18 |
|
*/ |
25 |
|
*/ |
26 |
|
public static final String REVISION = "$Revision$"; |
27 |
|
|
28 |
+ |
/** |
29 |
+ |
* An internal representation of a NORMAL threshold |
30 |
+ |
*/ |
31 |
|
public static final int thresholdNORMAL = 0; |
32 |
+ |
|
33 |
+ |
/** |
34 |
+ |
* An internal representation of a LOWER threshold |
35 |
+ |
*/ |
36 |
|
public static final int thresholdLOWER = 1; |
37 |
+ |
|
38 |
+ |
/** |
39 |
+ |
* An internal representation of an UPPER threshold |
40 |
+ |
*/ |
41 |
|
public static final int thresholdUPPER = 2; |
42 |
|
|
43 |
+ |
/** |
44 |
+ |
* The textual names of the threshold levels. The position |
45 |
+ |
* of the names in this array correspond to the internal |
46 |
+ |
* integer representation constants. |
47 |
+ |
*/ |
48 |
|
public static final String[] thresholdLevels = {"NORMAL", "LOWER", "UPPER"}; |
49 |
|
|
50 |
< |
// not OK and FINAL MUST be present...at the beginning and the end |
50 |
> |
// note OK and FINAL MUST be present...at the beginning and the end |
51 |
|
|
52 |
+ |
/** |
53 |
+ |
* An internal representation of the OK alert |
54 |
+ |
* This must ALWAYS be 0. |
55 |
+ |
*/ |
56 |
|
public static final int alertOK = 0; |
57 |
+ |
|
58 |
+ |
/** |
59 |
+ |
* An internal representation of the NOTICE alert |
60 |
+ |
*/ |
61 |
|
public static final int alertNOTICE = 1; |
62 |
+ |
|
63 |
+ |
/** |
64 |
+ |
* An internal representation of the WARNING alert |
65 |
+ |
*/ |
66 |
|
public static final int alertWARNING = 2; |
67 |
+ |
|
68 |
+ |
/** |
69 |
+ |
* An internal representation of the CAUTION alert |
70 |
+ |
*/ |
71 |
|
public static final int alertCAUTION = 3; |
72 |
+ |
|
73 |
+ |
/** |
74 |
+ |
* An internal representation of the CRITICAL alert |
75 |
+ |
*/ |
76 |
|
public static final int alertCRITICAL = 4; |
77 |
< |
// note FINAL should be the highest alert |
77 |
> |
|
78 |
> |
/** |
79 |
> |
* An internal representation of the FINAL alert |
80 |
> |
* This must ALWAYS be the highest. |
81 |
> |
*/ |
82 |
|
public static final int alertFINAL = 5; |
83 |
|
|
84 |
< |
// note FINAL should be last in this list |
84 |
> |
/** |
85 |
> |
* The textual names of the alert levels. The position |
86 |
> |
* of the names in this array correspond to the internal |
87 |
> |
* integer representation constants. |
88 |
> |
*/ |
89 |
|
public static final String[] alertLevels = {"OK", "NOTICE", "WARNING", "CAUTION", "CRITICAL", "FINAL"}; |
90 |
|
|
91 |
|
//---STATIC METHODS--- |
93 |
|
//---CONSTRUCTORS--- |
94 |
|
|
95 |
|
/** |
96 |
< |
* Construct an Alert packet at a set level. |
96 |
> |
* Construct an Alert object with the appropriate data |
97 |
|
* |
98 |
< |
* @param level the level of the alert |
98 |
> |
* @param alertLevel the alert level for this Alert object |
99 |
> |
* @param lastAlert the last alert level before this one |
100 |
> |
* @param thresholdLevel the threshold level that was broken to raise the alert |
101 |
> |
* @param source the source of the alert eg, hostname |
102 |
> |
* @param thresholdValue the configured value of the treshold level that was broken |
103 |
> |
* @param value the value of the attribute that raised the alert |
104 |
> |
* @param attributeName the textual representation of the attribute that has raised the alert |
105 |
> |
* @param timeTillNextAlert the time until the next alert will be sent concerning this attribute (in seconds) |
106 |
> |
* @param initialAlertTime the time the problem with this attribute first occured |
107 |
|
*/ |
108 |
|
public Alert(int alertLevel, int lastAlert, int thresholdLevel, String source, String thresholdValue, String value, String attributeName, String timeTillNextAlert, long initialAlertTime) { |
109 |
|
_alertLevel = alertLevel; |
124 |
|
* is designed to resemble a HashMap.toString(), such that |
125 |
|
* it is similar to the XMLPacket.printAll() method. |
126 |
|
* |
127 |
+ |
* This method is used by the WebFeeder specifically. |
128 |
+ |
* |
129 |
|
* @return a String representation of this Alert object. |
130 |
|
*/ |
131 |
|
public String printAll() { |
147 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
148 |
|
* method to provide clean logging (every class should have this). |
149 |
|
* |
150 |
< |
* This uses the uk.org.iscream.util.FormatName class |
150 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
151 |
|
* to format the toString() |
152 |
|
* |
153 |
|
* @return the name of this class and its CVS revision |
164 |
|
//---ACCESSOR/MUTATOR METHODS--- |
165 |
|
|
166 |
|
/** |
167 |
< |
* Returns the level of this packet |
167 |
> |
* Returns the alert level of this Alert object |
168 |
> |
* |
169 |
> |
* @return the level |
170 |
|
*/ |
171 |
|
public int getLevel() { |
172 |
|
return _alertLevel; |
173 |
|
} |
174 |
|
|
175 |
+ |
/** |
176 |
+ |
* Returns the previous alert level for the attribute |
177 |
+ |
* |
178 |
+ |
* @return the previous level |
179 |
+ |
*/ |
180 |
|
public int getLastLevel() { |
181 |
|
return _lastAlert; |
182 |
|
} |
183 |
|
|
184 |
+ |
/** |
185 |
+ |
* Returns the threshold level that was broken |
186 |
+ |
* |
187 |
+ |
* @return the threshold level |
188 |
+ |
*/ |
189 |
|
public int getThreshold() { |
190 |
|
return _thresholdLevel; |
191 |
|
} |
192 |
|
|
193 |
+ |
/** |
194 |
+ |
* Returns the source of the alert |
195 |
+ |
* |
196 |
+ |
* @return the alerts source eg, hostname |
197 |
+ |
*/ |
198 |
|
public String getSource() { |
199 |
|
return _source; |
200 |
|
} |
201 |
|
|
202 |
+ |
/** |
203 |
+ |
* Returns the value that the alert level was caused by |
204 |
+ |
* |
205 |
+ |
* @return the value |
206 |
+ |
*/ |
207 |
|
public String getValue() { |
208 |
|
return _value; |
209 |
|
} |
210 |
|
|
211 |
+ |
/** |
212 |
+ |
* Returns the value of the threshold level this alert broke |
213 |
+ |
* |
214 |
+ |
* @return the value |
215 |
+ |
*/ |
216 |
|
public String getThresholdValue() { |
217 |
|
return _thresholdValue; |
218 |
|
} |
219 |
|
|
220 |
+ |
/** |
221 |
+ |
* Returns the textual representation of the name of |
222 |
+ |
* the attribute that caused the alert. |
223 |
+ |
* |
224 |
+ |
* @return the attribute name |
225 |
+ |
*/ |
226 |
|
public String getAttributeName() { |
227 |
|
return _attributeName; |
228 |
|
} |
229 |
|
|
230 |
+ |
/** |
231 |
+ |
* Returns the time in seconds till the next |
232 |
+ |
* alert will be sent |
233 |
+ |
* |
234 |
+ |
* @return the time till the next alert |
235 |
+ |
*/ |
236 |
|
public String getTimeTillNextAlert() { |
237 |
|
return _timeTillNextAlert; |
238 |
|
} |
239 |
|
|
240 |
+ |
/** |
241 |
+ |
* Returns the time in milliseconds when |
242 |
+ |
* the initial alert for this problem with the attribute |
243 |
+ |
* occured. |
244 |
+ |
* |
245 |
+ |
* @return the initial alert time |
246 |
+ |
*/ |
247 |
|
public long getInitialAlertTime() { |
248 |
|
return _initialAlertTime; |
249 |
|
} |
262 |
|
private String _name = ClientMain.NAME; |
263 |
|
|
264 |
|
/** |
265 |
< |
* The alert level of this packet |
265 |
> |
* The alert level of this Alert object |
266 |
|
*/ |
267 |
|
private int _alertLevel; |
268 |
|
|
269 |
+ |
/** |
270 |
+ |
* The last alert level for this attribute |
271 |
+ |
*/ |
272 |
|
private int _lastAlert; |
273 |
|
|
274 |
+ |
/** |
275 |
+ |
* The threshold level that was broken |
276 |
+ |
*/ |
277 |
|
private int _thresholdLevel; |
278 |
|
|
279 |
+ |
/** |
280 |
+ |
* The source of the alert, eg hostname |
281 |
+ |
*/ |
282 |
|
private String _source; |
283 |
+ |
|
284 |
+ |
/** |
285 |
+ |
* The attribute value that caused the alert |
286 |
+ |
*/ |
287 |
|
private String _value; |
288 |
+ |
|
289 |
+ |
/** |
290 |
+ |
* The threshold value that was broken |
291 |
+ |
*/ |
292 |
|
private String _thresholdValue; |
293 |
+ |
|
294 |
+ |
/** |
295 |
+ |
* The textual representation of the attribute |
296 |
+ |
* that caused the alert. |
297 |
+ |
*/ |
298 |
|
private String _attributeName; |
299 |
+ |
|
300 |
+ |
/** |
301 |
+ |
* The time in seconds till the next alert |
302 |
+ |
* for this attribute will occur. |
303 |
+ |
*/ |
304 |
|
private String _timeTillNextAlert; |
305 |
|
|
306 |
+ |
/** |
307 |
+ |
* The time in milliseconds that this |
308 |
+ |
* alert first occured. |
309 |
+ |
*/ |
310 |
|
private long _initialAlertTime; |
311 |
|
|
312 |
|
//---STATIC ATTRIBUTES--- |