1 |
tdb |
1.17 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
|
|
* Copyright (C) 2000-2002 i-scream |
4 |
|
|
* |
5 |
|
|
* This program is free software; you can redistribute it and/or |
6 |
|
|
* modify it under the terms of the GNU General Public License |
7 |
|
|
* as published by the Free Software Foundation; either version 2 |
8 |
|
|
* of the License, or (at your option) any later version. |
9 |
|
|
* |
10 |
|
|
* This program is distributed in the hope that it will be useful, |
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
* GNU General Public License for more details. |
14 |
|
|
* |
15 |
|
|
* You should have received a copy of the GNU General Public License |
16 |
|
|
* along with this program; if not, write to the Free Software |
17 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
|
|
*/ |
19 |
|
|
|
20 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
21 |
tdb |
1.16 |
package uk.org.iscream.cms.server.client; |
22 |
tdb |
1.1 |
|
23 |
|
|
//---IMPORTS--- |
24 |
tdb |
1.16 |
import uk.org.iscream.cms.server.util.*; |
25 |
tdb |
1.1 |
|
26 |
|
|
/** |
27 |
ajm |
1.15 |
* An object to hold the state of an Alert. |
28 |
|
|
* |
29 |
|
|
* When an alert is generated, it has lots of information about |
30 |
|
|
* the cirscumstances and source of the alert. This object holds |
31 |
|
|
* the information. It is created by Monitors (specifically in the |
32 |
|
|
* fireAlert method of MonitorSkeleton). It then places the alert |
33 |
|
|
* in the alert queue for Alerters to read and process. |
34 |
tdb |
1.1 |
* |
35 |
tdb |
1.17 |
* @author $Author: tdb $ |
36 |
|
|
* @version $Id: Alert.java,v 1.16 2001/05/29 17:02:34 tdb Exp $ |
37 |
tdb |
1.1 |
*/ |
38 |
ajm |
1.3 |
public class Alert { |
39 |
tdb |
1.1 |
|
40 |
|
|
//---FINAL ATTRIBUTES--- |
41 |
|
|
|
42 |
|
|
/** |
43 |
|
|
* The current CVS revision of this class |
44 |
|
|
*/ |
45 |
tdb |
1.17 |
public static final String REVISION = "$Revision: 1.16 $"; |
46 |
tdb |
1.4 |
|
47 |
ajm |
1.15 |
/** |
48 |
|
|
* An internal representation of a NORMAL threshold |
49 |
|
|
*/ |
50 |
ajm |
1.8 |
public static final int thresholdNORMAL = 0; |
51 |
ajm |
1.15 |
|
52 |
|
|
/** |
53 |
|
|
* An internal representation of a LOWER threshold |
54 |
|
|
*/ |
55 |
ajm |
1.8 |
public static final int thresholdLOWER = 1; |
56 |
ajm |
1.15 |
|
57 |
|
|
/** |
58 |
|
|
* An internal representation of an UPPER threshold |
59 |
|
|
*/ |
60 |
ajm |
1.8 |
public static final int thresholdUPPER = 2; |
61 |
ajm |
1.3 |
|
62 |
ajm |
1.15 |
/** |
63 |
|
|
* The textual names of the threshold levels. The position |
64 |
|
|
* of the names in this array correspond to the internal |
65 |
|
|
* integer representation constants. |
66 |
|
|
*/ |
67 |
ajm |
1.8 |
public static final String[] thresholdLevels = {"NORMAL", "LOWER", "UPPER"}; |
68 |
|
|
|
69 |
ajm |
1.15 |
// note OK and FINAL MUST be present...at the beginning and the end |
70 |
ajm |
1.11 |
|
71 |
ajm |
1.15 |
/** |
72 |
|
|
* An internal representation of the OK alert |
73 |
|
|
* This must ALWAYS be 0. |
74 |
|
|
*/ |
75 |
ajm |
1.8 |
public static final int alertOK = 0; |
76 |
ajm |
1.15 |
|
77 |
|
|
/** |
78 |
|
|
* An internal representation of the NOTICE alert |
79 |
|
|
*/ |
80 |
ajm |
1.8 |
public static final int alertNOTICE = 1; |
81 |
ajm |
1.15 |
|
82 |
|
|
/** |
83 |
|
|
* An internal representation of the WARNING alert |
84 |
|
|
*/ |
85 |
ajm |
1.8 |
public static final int alertWARNING = 2; |
86 |
ajm |
1.15 |
|
87 |
|
|
/** |
88 |
|
|
* An internal representation of the CAUTION alert |
89 |
|
|
*/ |
90 |
ajm |
1.8 |
public static final int alertCAUTION = 3; |
91 |
ajm |
1.15 |
|
92 |
|
|
/** |
93 |
|
|
* An internal representation of the CRITICAL alert |
94 |
|
|
*/ |
95 |
ajm |
1.8 |
public static final int alertCRITICAL = 4; |
96 |
ajm |
1.15 |
|
97 |
|
|
/** |
98 |
|
|
* An internal representation of the FINAL alert |
99 |
|
|
* This must ALWAYS be the highest. |
100 |
|
|
*/ |
101 |
ajm |
1.10 |
public static final int alertFINAL = 5; |
102 |
ajm |
1.8 |
|
103 |
ajm |
1.15 |
/** |
104 |
|
|
* The textual names of the alert levels. The position |
105 |
|
|
* of the names in this array correspond to the internal |
106 |
|
|
* integer representation constants. |
107 |
|
|
*/ |
108 |
ajm |
1.10 |
public static final String[] alertLevels = {"OK", "NOTICE", "WARNING", "CAUTION", "CRITICAL", "FINAL"}; |
109 |
tdb |
1.1 |
|
110 |
|
|
//---STATIC METHODS--- |
111 |
|
|
|
112 |
|
|
//---CONSTRUCTORS--- |
113 |
|
|
|
114 |
|
|
/** |
115 |
ajm |
1.15 |
* Construct an Alert object with the appropriate data |
116 |
tdb |
1.1 |
* |
117 |
ajm |
1.15 |
* @param alertLevel the alert level for this Alert object |
118 |
|
|
* @param lastAlert the last alert level before this one |
119 |
|
|
* @param thresholdLevel the threshold level that was broken to raise the alert |
120 |
|
|
* @param source the source of the alert eg, hostname |
121 |
|
|
* @param thresholdValue the configured value of the treshold level that was broken |
122 |
|
|
* @param value the value of the attribute that raised the alert |
123 |
|
|
* @param attributeName the textual representation of the attribute that has raised the alert |
124 |
|
|
* @param timeTillNextAlert the time until the next alert will be sent concerning this attribute (in seconds) |
125 |
|
|
* @param initialAlertTime the time the problem with this attribute first occured |
126 |
tdb |
1.1 |
*/ |
127 |
ajm |
1.11 |
public Alert(int alertLevel, int lastAlert, int thresholdLevel, String source, String thresholdValue, String value, String attributeName, String timeTillNextAlert, long initialAlertTime) { |
128 |
ajm |
1.8 |
_alertLevel = alertLevel; |
129 |
ajm |
1.9 |
_lastAlert = lastAlert; |
130 |
ajm |
1.8 |
_thresholdLevel = thresholdLevel; |
131 |
tdb |
1.5 |
_source = source; |
132 |
ajm |
1.3 |
_thresholdValue = thresholdValue; |
133 |
|
|
_value = value; |
134 |
|
|
_attributeName = attributeName; |
135 |
ajm |
1.8 |
_timeTillNextAlert = timeTillNextAlert; |
136 |
ajm |
1.11 |
_initialAlertTime = initialAlertTime; |
137 |
tdb |
1.1 |
} |
138 |
|
|
|
139 |
|
|
//---PUBLIC METHODS--- |
140 |
tdb |
1.12 |
|
141 |
|
|
/** |
142 |
|
|
* Prints a String representation of the Alert object. It |
143 |
|
|
* is designed to resemble a HashMap.toString(), such that |
144 |
|
|
* it is similar to the XMLPacket.printAll() method. |
145 |
|
|
* |
146 |
ajm |
1.15 |
* This method is used by the WebFeeder specifically. |
147 |
|
|
* |
148 |
tdb |
1.12 |
* @return a String representation of this Alert object. |
149 |
|
|
*/ |
150 |
|
|
public String printAll() { |
151 |
|
|
String result = "{"; |
152 |
|
|
result += "alertLevel="+_alertLevel+", "; |
153 |
|
|
result += "lastAlert="+_lastAlert+", "; |
154 |
|
|
result += "thresholdLevel="+_thresholdLevel+", "; |
155 |
|
|
result += "source="+_source+", "; |
156 |
|
|
result += "thresholdValue="+_thresholdValue+", "; |
157 |
|
|
result += "value="+_value+", "; |
158 |
|
|
result += "attributeName="+_attributeName+", "; |
159 |
|
|
result += "timeTillNextAlert="+_timeTillNextAlert+", "; |
160 |
|
|
result += "initialAlertTime="+_initialAlertTime; |
161 |
|
|
result += "}"; |
162 |
|
|
return result; |
163 |
|
|
} |
164 |
tdb |
1.1 |
|
165 |
|
|
/** |
166 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
167 |
|
|
* method to provide clean logging (every class should have this). |
168 |
|
|
* |
169 |
tdb |
1.16 |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
170 |
tdb |
1.1 |
* to format the toString() |
171 |
|
|
* |
172 |
|
|
* @return the name of this class and its CVS revision |
173 |
|
|
*/ |
174 |
|
|
public String toString() { |
175 |
|
|
return FormatName.getName( |
176 |
|
|
_name, |
177 |
|
|
getClass().getName(), |
178 |
|
|
REVISION); |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
//---PRIVATE METHODS--- |
182 |
|
|
|
183 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
184 |
tdb |
1.2 |
|
185 |
|
|
/** |
186 |
ajm |
1.15 |
* Returns the alert level of this Alert object |
187 |
|
|
* |
188 |
|
|
* @return the level |
189 |
tdb |
1.2 |
*/ |
190 |
|
|
public int getLevel() { |
191 |
ajm |
1.8 |
return _alertLevel; |
192 |
|
|
} |
193 |
|
|
|
194 |
ajm |
1.15 |
/** |
195 |
|
|
* Returns the previous alert level for the attribute |
196 |
|
|
* |
197 |
|
|
* @return the previous level |
198 |
|
|
*/ |
199 |
ajm |
1.9 |
public int getLastLevel() { |
200 |
|
|
return _lastAlert; |
201 |
|
|
} |
202 |
|
|
|
203 |
ajm |
1.15 |
/** |
204 |
|
|
* Returns the threshold level that was broken |
205 |
|
|
* |
206 |
|
|
* @return the threshold level |
207 |
|
|
*/ |
208 |
ajm |
1.8 |
public int getThreshold() { |
209 |
|
|
return _thresholdLevel; |
210 |
tdb |
1.2 |
} |
211 |
ajm |
1.3 |
|
212 |
ajm |
1.15 |
/** |
213 |
|
|
* Returns the source of the alert |
214 |
|
|
* |
215 |
|
|
* @return the alerts source eg, hostname |
216 |
|
|
*/ |
217 |
tdb |
1.5 |
public String getSource() { |
218 |
|
|
return _source; |
219 |
|
|
} |
220 |
|
|
|
221 |
ajm |
1.15 |
/** |
222 |
|
|
* Returns the value that the alert level was caused by |
223 |
|
|
* |
224 |
|
|
* @return the value |
225 |
|
|
*/ |
226 |
ajm |
1.3 |
public String getValue() { |
227 |
|
|
return _value; |
228 |
|
|
} |
229 |
|
|
|
230 |
ajm |
1.15 |
/** |
231 |
|
|
* Returns the value of the threshold level this alert broke |
232 |
|
|
* |
233 |
|
|
* @return the value |
234 |
|
|
*/ |
235 |
ajm |
1.3 |
public String getThresholdValue() { |
236 |
|
|
return _thresholdValue; |
237 |
|
|
} |
238 |
|
|
|
239 |
ajm |
1.15 |
/** |
240 |
|
|
* Returns the textual representation of the name of |
241 |
|
|
* the attribute that caused the alert. |
242 |
|
|
* |
243 |
|
|
* @return the attribute name |
244 |
|
|
*/ |
245 |
ajm |
1.3 |
public String getAttributeName() { |
246 |
|
|
return _attributeName; |
247 |
|
|
} |
248 |
ajm |
1.8 |
|
249 |
ajm |
1.15 |
/** |
250 |
|
|
* Returns the time in seconds till the next |
251 |
|
|
* alert will be sent |
252 |
|
|
* |
253 |
|
|
* @return the time till the next alert |
254 |
|
|
*/ |
255 |
ajm |
1.8 |
public String getTimeTillNextAlert() { |
256 |
|
|
return _timeTillNextAlert; |
257 |
|
|
} |
258 |
ajm |
1.11 |
|
259 |
ajm |
1.15 |
/** |
260 |
|
|
* Returns the time in milliseconds when |
261 |
|
|
* the initial alert for this problem with the attribute |
262 |
|
|
* occured. |
263 |
|
|
* |
264 |
|
|
* @return the initial alert time |
265 |
|
|
*/ |
266 |
tdb |
1.13 |
public long getInitialAlertTime() { |
267 |
ajm |
1.11 |
return _initialAlertTime; |
268 |
|
|
} |
269 |
tdb |
1.1 |
|
270 |
|
|
//---ATTRIBUTES--- |
271 |
|
|
|
272 |
|
|
/** |
273 |
|
|
* This is the friendly identifier of the |
274 |
|
|
* component this class is running in. |
275 |
|
|
* eg, a Filter may be called "filter1", |
276 |
|
|
* If this class does not have an owning |
277 |
|
|
* component, a name from the configuration |
278 |
|
|
* can be placed here. This name could also |
279 |
|
|
* be changed to null for utility classes. |
280 |
|
|
*/ |
281 |
|
|
private String _name = ClientMain.NAME; |
282 |
|
|
|
283 |
|
|
/** |
284 |
ajm |
1.15 |
* The alert level of this Alert object |
285 |
tdb |
1.1 |
*/ |
286 |
ajm |
1.8 |
private int _alertLevel; |
287 |
ajm |
1.9 |
|
288 |
ajm |
1.15 |
/** |
289 |
|
|
* The last alert level for this attribute |
290 |
|
|
*/ |
291 |
ajm |
1.9 |
private int _lastAlert; |
292 |
ajm |
1.8 |
|
293 |
ajm |
1.15 |
/** |
294 |
|
|
* The threshold level that was broken |
295 |
|
|
*/ |
296 |
ajm |
1.8 |
private int _thresholdLevel; |
297 |
ajm |
1.3 |
|
298 |
ajm |
1.15 |
/** |
299 |
|
|
* The source of the alert, eg hostname |
300 |
|
|
*/ |
301 |
tdb |
1.5 |
private String _source; |
302 |
ajm |
1.15 |
|
303 |
|
|
/** |
304 |
|
|
* The attribute value that caused the alert |
305 |
|
|
*/ |
306 |
ajm |
1.3 |
private String _value; |
307 |
ajm |
1.15 |
|
308 |
|
|
/** |
309 |
|
|
* The threshold value that was broken |
310 |
|
|
*/ |
311 |
ajm |
1.3 |
private String _thresholdValue; |
312 |
ajm |
1.15 |
|
313 |
|
|
/** |
314 |
|
|
* The textual representation of the attribute |
315 |
|
|
* that caused the alert. |
316 |
|
|
*/ |
317 |
ajm |
1.3 |
private String _attributeName; |
318 |
ajm |
1.15 |
|
319 |
|
|
/** |
320 |
|
|
* The time in seconds till the next alert |
321 |
|
|
* for this attribute will occur. |
322 |
|
|
*/ |
323 |
ajm |
1.8 |
private String _timeTillNextAlert; |
324 |
ajm |
1.11 |
|
325 |
ajm |
1.15 |
/** |
326 |
|
|
* The time in milliseconds that this |
327 |
|
|
* alert first occured. |
328 |
|
|
*/ |
329 |
ajm |
1.11 |
private long _initialAlertTime; |
330 |
tdb |
1.1 |
|
331 |
|
|
//---STATIC ATTRIBUTES--- |
332 |
|
|
|
333 |
|
|
} |