1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
4 |
+ |
* 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 |
|
//---PACKAGE DECLARATION--- |
22 |
< |
package uk.org.iscream.client; |
22 |
> |
package uk.org.iscream.cms.server.client; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
|
import java.util.HashMap; |
26 |
< |
import uk.org.iscream.client.*; |
27 |
< |
import uk.org.iscream.core.*; |
28 |
< |
import uk.org.iscream.util.*; |
29 |
< |
import uk.org.iscream.componentmanager.*; |
26 |
> |
import uk.org.iscream.cms.server.client.*; |
27 |
> |
import uk.org.iscream.cms.server.core.*; |
28 |
> |
import uk.org.iscream.cms.server.util.*; |
29 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
30 |
|
|
31 |
|
/** |
32 |
|
* Skeleton class for Monitors |
33 |
+ |
* This skeleton reads packets from a queue designated |
34 |
+ |
* by the extending class, it then feeds the data to the analysePacket |
35 |
+ |
* method, which the extending class should implement. The class |
36 |
+ |
* should then handle the monitoring for that packet. |
37 |
|
* |
38 |
|
* @author $Author$ |
39 |
|
* @version $Id$ |
41 |
|
public abstract class MonitorSkeleton extends Thread implements PluginMonitor { |
42 |
|
|
43 |
|
//---FINAL ATTRIBUTES--- |
44 |
+ |
|
45 |
+ |
/** |
46 |
+ |
* The current CVS revision of this class |
47 |
+ |
*/ |
48 |
+ |
public final String REVISION = "$Revision$"; |
49 |
|
|
50 |
|
//---STATIC METHODS--- |
51 |
|
|
52 |
|
//---CONSTRUCTORS--- |
53 |
|
|
54 |
+ |
/** |
55 |
+ |
* Constructs and start the monitor reading its data |
56 |
+ |
*/ |
57 |
|
public MonitorSkeleton() { |
58 |
|
_logger.write(toString(), Logger.SYSINIT, "started."); |
59 |
|
this.start(); |
61 |
|
|
62 |
|
//---PUBLIC METHODS--- |
63 |
|
|
64 |
+ |
/** |
65 |
+ |
* Obtains data from the monitors data queue and |
66 |
+ |
* passes the packet to the analysePacket method. |
67 |
+ |
*/ |
68 |
|
public void run() { |
69 |
|
while(_running) { |
70 |
|
try { |
75 |
|
} |
76 |
|
} |
77 |
|
|
78 |
+ |
/** |
79 |
+ |
* Extending classes should override this method to |
80 |
+ |
* analyse the given packet for the attribute |
81 |
+ |
* they are responsible for. |
82 |
+ |
*/ |
83 |
|
protected abstract void analysePacket(XMLPacket packet); |
84 |
|
|
85 |
+ |
/** |
86 |
+ |
* Once a Monitor has determined which threshold the given data packet |
87 |
+ |
* is at, it should then call this method. This method handles ALL |
88 |
+ |
* the alerting logic to determine escalation of alerts. |
89 |
+ |
* If it decides an alert needs to be send, it will send one using fireAlert. |
90 |
+ |
* |
91 |
+ |
* @param newThreshold the threshold that has been determined by the monitor |
92 |
+ |
* @param attributeName the textual name of the attribute the monitor is responsible for |
93 |
+ |
* @param reg the register that holds the current alert state for the machine/attribute |
94 |
+ |
* @param source the source of the alert eg, hostname |
95 |
+ |
* @param currentValue the data value for the attribute |
96 |
+ |
*/ |
97 |
|
protected void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) { |
98 |
|
// decide what threshold level we're on, if we've changed, record that |
99 |
|
if (newThreshold != reg.getLastThresholdLevel()) { |
142 |
|
} |
143 |
|
|
144 |
|
/** |
145 |
< |
* return the String representation of what the monitor does |
145 |
> |
* Return the String representation of what the alerter does |
146 |
> |
* |
147 |
> |
* @return the description |
148 |
|
*/ |
149 |
|
public abstract String getDescription(); |
150 |
|
|
151 |
|
|
152 |
|
//---PRIVATE METHODS--- |
153 |
|
|
154 |
< |
protected void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) { |
154 |
> |
/** |
155 |
> |
* Fires an alert. This creates a new Alert object |
156 |
> |
* and populates it with the given alert information. |
157 |
> |
* It then adds the alert to the Alerter queue. |
158 |
> |
* |
159 |
> |
* This method should only be called by the processAlert method. |
160 |
> |
* |
161 |
> |
* @param reg the register holding the state values for the alert |
162 |
> |
* @param source the source of the alert eg, hostname |
163 |
> |
* @param currentValue the data value for the attribute |
164 |
> |
* @param attributeName the textual name of the attribute the alert is for |
165 |
> |
*/ |
166 |
> |
private void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) { |
167 |
|
int alertLevel = reg.getLastAlertLevel(); |
168 |
|
int thresholdLevel = reg.getLastThresholdLevel(); |
169 |
|
String thresholdValue = String.valueOf(reg.getThreshold(thresholdLevel)); |
182 |
|
|
183 |
|
//---ACCESSOR/MUTATOR METHODS--- |
184 |
|
|
185 |
+ |
/** |
186 |
+ |
* Obtain the queue which contains the data |
187 |
+ |
* the Monitor is reading. |
188 |
+ |
* eg, MonitorManager.getInstance().getHeartbeatQueue() |
189 |
+ |
*/ |
190 |
|
protected abstract Queue getQueue(); |
191 |
|
|
192 |
+ |
/** |
193 |
+ |
* Create a queue ID on the feeding |
194 |
+ |
* data queue |
195 |
+ |
*/ |
196 |
|
protected int getQueueId() { |
197 |
|
if (_qID == -1) { |
198 |
|
_qID = getQueue().getQueue(); |
203 |
|
|
204 |
|
//---ATTRIBUTES--- |
205 |
|
|
206 |
+ |
/** |
207 |
+ |
* This holds a reference to the |
208 |
+ |
* system logger that is being used. |
209 |
+ |
*/ |
210 |
|
protected Logger _logger = ReferenceManager.getInstance().getLogger(); |
211 |
|
|
212 |
< |
protected Queue _alerterQueue = ClientMain._alerterQueue; |
212 |
> |
/** |
213 |
> |
* A reference to the Alerter queue, into which |
214 |
> |
* all new alerts will be placed. |
215 |
> |
*/ |
216 |
> |
protected Queue _alerterQueue = AlerterManager.getInstance().getQueue(); |
217 |
|
|
218 |
+ |
/** |
219 |
+ |
* The ID of the queue the monitor will use. |
220 |
+ |
* Initially -1, but initialised on first use. |
221 |
+ |
*/ |
222 |
|
protected int _qID = -1; |
223 |
|
|
224 |
+ |
/** |
225 |
+ |
* The state of the alerter thread |
226 |
+ |
*/ |
227 |
|
protected boolean _running = true; |
228 |
|
|
229 |
|
//---STATIC ATTRIBUTES--- |