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.18
Committed: Tue May 21 16:47:16 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.17: +3 -2 lines
Log Message:
Added URL to GPL headers.

File Contents

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