ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/Alert.java
Revision: 1.17
Committed: Sat May 18 18:16:00 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.16: +22 -3 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# Content
1 /*
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 //---PACKAGE DECLARATION---
21 package uk.org.iscream.cms.server.client;
22
23 //---IMPORTS---
24 import uk.org.iscream.cms.server.util.*;
25
26 /**
27 * 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 *
35 * @author $Author: tdb $
36 * @version $Id: Alert.java,v 1.16 2001/05/29 17:02:34 tdb Exp $
37 */
38 public class Alert {
39
40 //---FINAL ATTRIBUTES---
41
42 /**
43 * The current CVS revision of this class
44 */
45 public static final String REVISION = "$Revision: 1.16 $";
46
47 /**
48 * An internal representation of a NORMAL threshold
49 */
50 public static final int thresholdNORMAL = 0;
51
52 /**
53 * An internal representation of a LOWER threshold
54 */
55 public static final int thresholdLOWER = 1;
56
57 /**
58 * An internal representation of an UPPER threshold
59 */
60 public static final int thresholdUPPER = 2;
61
62 /**
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 public static final String[] thresholdLevels = {"NORMAL", "LOWER", "UPPER"};
68
69 // note OK and FINAL MUST be present...at the beginning and the end
70
71 /**
72 * An internal representation of the OK alert
73 * This must ALWAYS be 0.
74 */
75 public static final int alertOK = 0;
76
77 /**
78 * An internal representation of the NOTICE alert
79 */
80 public static final int alertNOTICE = 1;
81
82 /**
83 * An internal representation of the WARNING alert
84 */
85 public static final int alertWARNING = 2;
86
87 /**
88 * An internal representation of the CAUTION alert
89 */
90 public static final int alertCAUTION = 3;
91
92 /**
93 * An internal representation of the CRITICAL alert
94 */
95 public static final int alertCRITICAL = 4;
96
97 /**
98 * An internal representation of the FINAL alert
99 * This must ALWAYS be the highest.
100 */
101 public static final int alertFINAL = 5;
102
103 /**
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 public static final String[] alertLevels = {"OK", "NOTICE", "WARNING", "CAUTION", "CRITICAL", "FINAL"};
109
110 //---STATIC METHODS---
111
112 //---CONSTRUCTORS---
113
114 /**
115 * Construct an Alert object with the appropriate data
116 *
117 * @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 */
127 public Alert(int alertLevel, int lastAlert, int thresholdLevel, String source, String thresholdValue, String value, String attributeName, String timeTillNextAlert, long initialAlertTime) {
128 _alertLevel = alertLevel;
129 _lastAlert = lastAlert;
130 _thresholdLevel = thresholdLevel;
131 _source = source;
132 _thresholdValue = thresholdValue;
133 _value = value;
134 _attributeName = attributeName;
135 _timeTillNextAlert = timeTillNextAlert;
136 _initialAlertTime = initialAlertTime;
137 }
138
139 //---PUBLIC METHODS---
140
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 * This method is used by the WebFeeder specifically.
147 *
148 * @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
165 /**
166 * Overrides the {@link java.lang.Object#toString() Object.toString()}
167 * method to provide clean logging (every class should have this).
168 *
169 * This uses the uk.org.iscream.cms.server.util.FormatName class
170 * 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
185 /**
186 * Returns the alert level of this Alert object
187 *
188 * @return the level
189 */
190 public int getLevel() {
191 return _alertLevel;
192 }
193
194 /**
195 * Returns the previous alert level for the attribute
196 *
197 * @return the previous level
198 */
199 public int getLastLevel() {
200 return _lastAlert;
201 }
202
203 /**
204 * Returns the threshold level that was broken
205 *
206 * @return the threshold level
207 */
208 public int getThreshold() {
209 return _thresholdLevel;
210 }
211
212 /**
213 * Returns the source of the alert
214 *
215 * @return the alerts source eg, hostname
216 */
217 public String getSource() {
218 return _source;
219 }
220
221 /**
222 * Returns the value that the alert level was caused by
223 *
224 * @return the value
225 */
226 public String getValue() {
227 return _value;
228 }
229
230 /**
231 * Returns the value of the threshold level this alert broke
232 *
233 * @return the value
234 */
235 public String getThresholdValue() {
236 return _thresholdValue;
237 }
238
239 /**
240 * Returns the textual representation of the name of
241 * the attribute that caused the alert.
242 *
243 * @return the attribute name
244 */
245 public String getAttributeName() {
246 return _attributeName;
247 }
248
249 /**
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 public String getTimeTillNextAlert() {
256 return _timeTillNextAlert;
257 }
258
259 /**
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 public long getInitialAlertTime() {
267 return _initialAlertTime;
268 }
269
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 * The alert level of this Alert object
285 */
286 private int _alertLevel;
287
288 /**
289 * The last alert level for this attribute
290 */
291 private int _lastAlert;
292
293 /**
294 * The threshold level that was broken
295 */
296 private int _thresholdLevel;
297
298 /**
299 * The source of the alert, eg hostname
300 */
301 private String _source;
302
303 /**
304 * The attribute value that caused the alert
305 */
306 private String _value;
307
308 /**
309 * The threshold value that was broken
310 */
311 private String _thresholdValue;
312
313 /**
314 * The textual representation of the attribute
315 * that caused the alert.
316 */
317 private String _attributeName;
318
319 /**
320 * The time in seconds till the next alert
321 * for this attribute will occur.
322 */
323 private String _timeTillNextAlert;
324
325 /**
326 * The time in milliseconds that this
327 * alert first occured.
328 */
329 private long _initialAlertTime;
330
331 //---STATIC ATTRIBUTES---
332
333 }