1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.client; |
2 |
> |
package uk.org.iscream.client; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.util.HashMap; |
6 |
< |
import uk.ac.ukc.iscream.client.*; |
7 |
< |
import uk.ac.ukc.iscream.core.*; |
8 |
< |
import uk.ac.ukc.iscream.util.*; |
9 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
6 |
> |
import uk.org.iscream.client.*; |
7 |
> |
import uk.org.iscream.core.*; |
8 |
> |
import uk.org.iscream.util.*; |
9 |
> |
import uk.org.iscream.componentmanager.*; |
10 |
|
|
11 |
|
/** |
12 |
|
* Skeleton class for Monitors |
14 |
|
* @author $Author$ |
15 |
|
* @version $Id$ |
16 |
|
*/ |
17 |
< |
public abstract class MonitorSkeleton implements PluginMonitor { |
17 |
> |
public abstract class MonitorSkeleton extends Thread implements PluginMonitor { |
18 |
|
|
19 |
|
//---FINAL ATTRIBUTES--- |
20 |
|
|
22 |
|
|
23 |
|
//---CONSTRUCTORS--- |
24 |
|
|
25 |
+ |
public MonitorSkeleton() { |
26 |
+ |
_logger.write(toString(), Logger.SYSINIT, "started."); |
27 |
+ |
this.start(); |
28 |
+ |
} |
29 |
+ |
|
30 |
|
//---PUBLIC METHODS--- |
31 |
|
|
32 |
< |
public abstract void analysePacket(XMLPacket packet); |
32 |
> |
public void run() { |
33 |
> |
while(_running) { |
34 |
> |
try { |
35 |
> |
analysePacket((XMLPacket) getQueue().get(getQueueId())); |
36 |
> |
} catch (InvalidQueueException e) { |
37 |
> |
_logger.write(this.toString(), Logger.ERROR, "Unable to get queue."); |
38 |
> |
} |
39 |
> |
} |
40 |
> |
} |
41 |
> |
|
42 |
> |
protected abstract void analysePacket(XMLPacket packet); |
43 |
|
|
44 |
< |
public void processAlert(int newThreshold, int attributeNum, String attributeName, Register reg, String source, String currentValue) { |
44 |
> |
protected void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) { |
45 |
|
// decide what threshold level we're on, if we've changed, record that |
46 |
< |
if (newThreshold != reg.getLastThresholdLevel(attributeNum)) { |
47 |
< |
reg.setLastThresholdLevel(attributeNum, newThreshold); |
46 |
> |
if (newThreshold != reg.getLastThresholdLevel()) { |
47 |
> |
reg.setLastThresholdLevel(newThreshold); |
48 |
|
} |
49 |
|
// as long as this isn't a normal level |
50 |
< |
if(reg.getLastThresholdLevel(attributeNum) != Alert.thresholdNORMAL) { |
50 |
> |
if(reg.getLastThresholdLevel() != Alert.thresholdNORMAL) { |
51 |
|
// if the time since the last alert is more than the time for |
52 |
|
// its timeout, fire an alert, escalate the alert |
53 |
< |
long timeout = reg.getLastAlertTimeout(attributeNum); |
54 |
< |
if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) { |
55 |
< |
if((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) { |
56 |
< |
int lastAlert = reg.getLastAlertLevel(attributeNum); |
57 |
< |
reg.escalateAlert(attributeNum); |
58 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
59 |
< |
reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum)); |
60 |
< |
fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName); |
53 |
> |
long timeout = reg.getLastAlertTimeout(); |
54 |
> |
if ((timeout > 0) && (reg.getTimeLastSent() > 0)) { |
55 |
> |
if((System.currentTimeMillis() - reg.getTimeLastSent()) > timeout) { |
56 |
> |
int lastAlert = reg.getLastAlertLevel(); |
57 |
> |
reg.escalateAlert(); |
58 |
> |
reg.setTimeLastSent( System.currentTimeMillis()); |
59 |
> |
reg.setLastAlertTimeout(reg.getAlertTimeout(reg.getLastAlertLevel())); |
60 |
> |
fireAlert(reg, lastAlert, source, currentValue, attributeName); |
61 |
|
} |
62 |
|
// if we don't have a timeout configured...we got STRAIGHT to the next level |
63 |
|
} else { |
64 |
< |
int lastAlert = reg.getLastAlertLevel(attributeNum); |
65 |
< |
reg.escalateAlert(attributeNum); |
66 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
67 |
< |
reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum)); |
68 |
< |
fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName); |
64 |
> |
int lastAlert = reg.getLastAlertLevel(); |
65 |
> |
reg.escalateAlert(); |
66 |
> |
reg.setTimeLastSent( System.currentTimeMillis()); |
67 |
> |
reg.setLastAlertTimeout(reg.getAlertTimeout(reg.getLastAlertLevel())); |
68 |
> |
fireAlert(reg, lastAlert, source, currentValue, attributeName); |
69 |
|
} |
70 |
|
|
71 |
|
// we must be on ok, check the timeout value for this |
73 |
|
// if we were on an OK alert before, then we don't do anything |
74 |
|
// but if we weren't we only set OK, once the timout of the last |
75 |
|
// alert has occourd |
76 |
< |
if (reg.getLastAlertLevel(attributeNum) != Alert.alertOK) { |
77 |
< |
long timeout = reg.getLastAlertTimeout(attributeNum); |
78 |
< |
if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) { |
79 |
< |
if ((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) { |
80 |
< |
int lastAlert = reg.getLastAlertLevel(attributeNum); |
81 |
< |
reg.setLastAlertLevel(attributeNum, Alert.alertOK); |
82 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
83 |
< |
reg.setLastAlertTimeout(attributeNum, timeout); |
84 |
< |
fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName); |
76 |
> |
if (reg.getLastAlertLevel() != Alert.alertOK) { |
77 |
> |
long timeout = reg.getLastAlertTimeout(); |
78 |
> |
if ((timeout > 0) && (reg.getTimeLastSent() > 0)) { |
79 |
> |
if ((System.currentTimeMillis() - reg.getTimeLastSent()) > timeout) { |
80 |
> |
int lastAlert = reg.getLastAlertLevel(); |
81 |
> |
reg.setLastAlertLevel(Alert.alertOK); |
82 |
> |
reg.setTimeLastSent(System.currentTimeMillis()); |
83 |
> |
reg.setLastAlertTimeout(timeout); |
84 |
> |
fireAlert(reg, lastAlert, source, currentValue, attributeName); |
85 |
|
} |
86 |
|
} |
87 |
|
} |
96 |
|
|
97 |
|
//---PRIVATE METHODS--- |
98 |
|
|
99 |
< |
protected void fireAlert(Register reg, int lastAlert, int attributeNum, String source, String currentValue, String attributeName) { |
100 |
< |
int alertLevel = reg.getLastAlertLevel(attributeNum); |
101 |
< |
int thresholdLevel = reg.getLastThresholdLevel(attributeNum); |
99 |
> |
protected void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) { |
100 |
> |
int alertLevel = reg.getLastAlertLevel(); |
101 |
> |
int thresholdLevel = reg.getLastThresholdLevel(); |
102 |
|
String thresholdValue = String.valueOf(reg.getThreshold(thresholdLevel)); |
103 |
< |
String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum) / 1000); |
104 |
< |
if (thresholdLevel == Alert.thresholdNORMAL) { |
103 |
> |
String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel()) / 1000); |
104 |
> |
// ensures we display a nice thing if its -1.0 |
105 |
> |
if (thresholdValue.equals("-1.0")) { |
106 |
|
thresholdValue = "-"; |
107 |
|
} |
108 |
|
if (alertLevel == Alert.alertOK) { |
109 |
|
timeout = "0"; |
110 |
|
} |
111 |
< |
Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime(attributeNum)); |
111 |
> |
Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime()); |
112 |
|
_alerterQueue.add(alert); |
113 |
|
_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"); |
114 |
|
} |
115 |
|
|
116 |
|
//---ACCESSOR/MUTATOR METHODS--- |
117 |
|
|
118 |
+ |
protected abstract Queue getQueue(); |
119 |
+ |
|
120 |
+ |
protected int getQueueId() { |
121 |
+ |
if (_qID == -1) { |
122 |
+ |
_qID = getQueue().getQueue(); |
123 |
+ |
_logger.write(toString(), Logger.DEBUG, "Assigned Queue - " + _qID); |
124 |
+ |
} |
125 |
+ |
return _qID; |
126 |
+ |
} |
127 |
+ |
|
128 |
|
//---ATTRIBUTES--- |
129 |
|
|
130 |
|
protected Logger _logger = ReferenceManager.getInstance().getLogger(); |
131 |
|
|
132 |
|
protected Queue _alerterQueue = ClientMain._alerterQueue; |
133 |
+ |
|
134 |
+ |
protected int _qID = -1; |
135 |
+ |
|
136 |
+ |
protected boolean _running = true; |
137 |
|
|
138 |
|
//---STATIC ATTRIBUTES--- |
139 |
|
|