1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
tdb |
1.5 |
package uk.org.iscream.client; |
3 |
tdb |
1.1 |
|
4 |
|
|
//---IMPORTS--- |
5 |
|
|
import java.util.HashMap; |
6 |
tdb |
1.5 |
import uk.org.iscream.client.*; |
7 |
|
|
import uk.org.iscream.core.*; |
8 |
|
|
import uk.org.iscream.util.*; |
9 |
|
|
import uk.org.iscream.componentmanager.*; |
10 |
tdb |
1.1 |
|
11 |
|
|
/** |
12 |
|
|
* Skeleton class for Monitors |
13 |
|
|
* |
14 |
tdb |
1.6 |
* @author $Author: tdb1 $ |
15 |
|
|
* @version $Id: MonitorSkeleton.java,v 1.5 2001/03/14 23:25:29 tdb1 Exp $ |
16 |
tdb |
1.1 |
*/ |
17 |
|
|
public abstract class MonitorSkeleton implements PluginMonitor { |
18 |
|
|
|
19 |
|
|
//---FINAL ATTRIBUTES--- |
20 |
|
|
|
21 |
|
|
//---STATIC METHODS--- |
22 |
|
|
|
23 |
|
|
//---CONSTRUCTORS--- |
24 |
|
|
|
25 |
|
|
//---PUBLIC METHODS--- |
26 |
|
|
|
27 |
|
|
public abstract void analysePacket(XMLPacket packet); |
28 |
|
|
|
29 |
ajm |
1.3 |
public void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) { |
30 |
tdb |
1.1 |
// decide what threshold level we're on, if we've changed, record that |
31 |
ajm |
1.3 |
if (newThreshold != reg.getLastThresholdLevel()) { |
32 |
|
|
reg.setLastThresholdLevel(newThreshold); |
33 |
tdb |
1.1 |
} |
34 |
|
|
// as long as this isn't a normal level |
35 |
ajm |
1.3 |
if(reg.getLastThresholdLevel() != Alert.thresholdNORMAL) { |
36 |
tdb |
1.1 |
// if the time since the last alert is more than the time for |
37 |
|
|
// its timeout, fire an alert, escalate the alert |
38 |
ajm |
1.3 |
long timeout = reg.getLastAlertTimeout(); |
39 |
|
|
if ((timeout > 0) && (reg.getTimeLastSent() > 0)) { |
40 |
|
|
if((System.currentTimeMillis() - reg.getTimeLastSent()) > timeout) { |
41 |
|
|
int lastAlert = reg.getLastAlertLevel(); |
42 |
|
|
reg.escalateAlert(); |
43 |
|
|
reg.setTimeLastSent( System.currentTimeMillis()); |
44 |
|
|
reg.setLastAlertTimeout(reg.getAlertTimeout(reg.getLastAlertLevel())); |
45 |
|
|
fireAlert(reg, lastAlert, source, currentValue, attributeName); |
46 |
tdb |
1.1 |
} |
47 |
|
|
// if we don't have a timeout configured...we got STRAIGHT to the next level |
48 |
|
|
} else { |
49 |
ajm |
1.3 |
int lastAlert = reg.getLastAlertLevel(); |
50 |
|
|
reg.escalateAlert(); |
51 |
|
|
reg.setTimeLastSent( System.currentTimeMillis()); |
52 |
|
|
reg.setLastAlertTimeout(reg.getAlertTimeout(reg.getLastAlertLevel())); |
53 |
|
|
fireAlert(reg, lastAlert, source, currentValue, attributeName); |
54 |
tdb |
1.1 |
} |
55 |
|
|
|
56 |
|
|
// we must be on ok, check the timeout value for this |
57 |
|
|
} else { |
58 |
|
|
// if we were on an OK alert before, then we don't do anything |
59 |
|
|
// but if we weren't we only set OK, once the timout of the last |
60 |
|
|
// alert has occourd |
61 |
ajm |
1.3 |
if (reg.getLastAlertLevel() != Alert.alertOK) { |
62 |
|
|
long timeout = reg.getLastAlertTimeout(); |
63 |
|
|
if ((timeout > 0) && (reg.getTimeLastSent() > 0)) { |
64 |
|
|
if ((System.currentTimeMillis() - reg.getTimeLastSent()) > timeout) { |
65 |
|
|
int lastAlert = reg.getLastAlertLevel(); |
66 |
|
|
reg.setLastAlertLevel(Alert.alertOK); |
67 |
|
|
reg.setTimeLastSent(System.currentTimeMillis()); |
68 |
|
|
reg.setLastAlertTimeout(timeout); |
69 |
|
|
fireAlert(reg, lastAlert, source, currentValue, attributeName); |
70 |
tdb |
1.1 |
} |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
} |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
/** |
77 |
|
|
* return the String representation of what the monitor does |
78 |
|
|
*/ |
79 |
|
|
public abstract String getDescription(); |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
//---PRIVATE METHODS--- |
83 |
|
|
|
84 |
ajm |
1.3 |
protected void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) { |
85 |
|
|
int alertLevel = reg.getLastAlertLevel(); |
86 |
|
|
int thresholdLevel = reg.getLastThresholdLevel(); |
87 |
tdb |
1.1 |
String thresholdValue = String.valueOf(reg.getThreshold(thresholdLevel)); |
88 |
ajm |
1.3 |
String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel()) / 1000); |
89 |
ajm |
1.4 |
// ensures we display a nice thing if its -1.0 |
90 |
tdb |
1.6 |
if (thresholdValue.equals("-1.0")) { |
91 |
tdb |
1.1 |
thresholdValue = "-"; |
92 |
|
|
} |
93 |
|
|
if (alertLevel == Alert.alertOK) { |
94 |
|
|
timeout = "0"; |
95 |
|
|
} |
96 |
ajm |
1.3 |
Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime()); |
97 |
tdb |
1.1 |
_alerterQueue.add(alert); |
98 |
|
|
_logger.write(toString(), Logger.DEBUG, "Fired alert for source:" + source + " at alert level:" + Alert.alertLevels[alertLevel] + " on:" + attributeName + " for threshold level:" + Alert.thresholdLevels[thresholdLevel] + " at:" + currentValue + " exceeding threshold of:" +thresholdValue + " next alert sent in:" + timeout + "secs"); |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
102 |
|
|
|
103 |
|
|
//---ATTRIBUTES--- |
104 |
|
|
|
105 |
|
|
protected Logger _logger = ReferenceManager.getInstance().getLogger(); |
106 |
|
|
|
107 |
|
|
protected Queue _alerterQueue = ClientMain._alerterQueue; |
108 |
|
|
|
109 |
|
|
//---STATIC ATTRIBUTES--- |
110 |
|
|
|
111 |
|
|
} |