1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.client.monitors; |
2 |
> |
package uk.ac.ukc.iscream.client; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.util.HashMap; |
26 |
|
|
27 |
|
public abstract void analysePacket(XMLPacket packet); |
28 |
|
|
29 |
< |
public void processAlert(int newThreshold, int attributeNum, String attributeName, Register reg, String source, String currentValue) { |
29 |
> |
public void processAlert(int newThreshold, String attributeName, Register reg, String source, String currentValue) { |
30 |
|
// decide what threshold level we're on, if we've changed, record that |
31 |
< |
if (newThreshold != reg.getLastThresholdLevel(attributeNum)) { |
32 |
< |
reg.setLastThresholdLevel(attributeNum, newThreshold); |
31 |
> |
if (newThreshold != reg.getLastThresholdLevel()) { |
32 |
> |
reg.setLastThresholdLevel(newThreshold); |
33 |
|
} |
34 |
|
// as long as this isn't a normal level |
35 |
< |
if(reg.getLastThresholdLevel(attributeNum) != Alert.thresholdNORMAL) { |
35 |
> |
if(reg.getLastThresholdLevel() != Alert.thresholdNORMAL) { |
36 |
|
// if the time since the last alert is more than the time for |
37 |
|
// its timeout, fire an alert, escalate the alert |
38 |
< |
long timeout = reg.getLastAlertTimeout(attributeNum); |
39 |
< |
if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) { |
40 |
< |
if((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) { |
41 |
< |
int lastAlert = reg.getLastAlertLevel(attributeNum); |
42 |
< |
reg.escalateAlert(attributeNum); |
43 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
44 |
< |
reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum)); |
45 |
< |
fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName); |
38 |
> |
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 |
|
} |
47 |
|
// if we don't have a timeout configured...we got STRAIGHT to the next level |
48 |
|
} else { |
49 |
< |
int lastAlert = reg.getLastAlertLevel(attributeNum); |
50 |
< |
reg.escalateAlert(attributeNum); |
51 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
52 |
< |
reg.setLastAlertTimeout(attributeNum, reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum)); |
53 |
< |
fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName); |
49 |
> |
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 |
|
} |
55 |
|
|
56 |
|
// we must be on ok, check the timeout value for this |
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 |
< |
if (reg.getLastAlertLevel(attributeNum) != Alert.alertOK) { |
62 |
< |
long timeout = reg.getLastAlertTimeout(attributeNum); |
63 |
< |
if ((timeout > 0) && (reg.getTimeLastSent(attributeNum) > 0)) { |
64 |
< |
if ((System.currentTimeMillis() - reg.getTimeLastSent(attributeNum)) > timeout) { |
65 |
< |
int lastAlert = reg.getLastAlertLevel(attributeNum); |
66 |
< |
reg.setLastAlertLevel(attributeNum, Alert.alertOK); |
67 |
< |
reg.setTimeLastSent(attributeNum, System.currentTimeMillis()); |
68 |
< |
reg.setLastAlertTimeout(attributeNum, timeout); |
69 |
< |
fireAlert(reg, lastAlert, attributeNum, source, currentValue, attributeName); |
61 |
> |
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 |
|
} |
71 |
|
} |
72 |
|
} |
81 |
|
|
82 |
|
//---PRIVATE METHODS--- |
83 |
|
|
84 |
< |
protected void fireAlert(Register reg, int lastAlert, int attributeNum, String source, String currentValue, String attributeName) { |
85 |
< |
int alertLevel = reg.getLastAlertLevel(attributeNum); |
86 |
< |
int thresholdLevel = reg.getLastThresholdLevel(attributeNum); |
84 |
> |
protected void fireAlert(Register reg, int lastAlert, String source, String currentValue, String attributeName) { |
85 |
> |
int alertLevel = reg.getLastAlertLevel(); |
86 |
> |
int thresholdLevel = reg.getLastThresholdLevel(); |
87 |
|
String thresholdValue = String.valueOf(reg.getThreshold(thresholdLevel)); |
88 |
< |
String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel(attributeNum), attributeNum) / 1000); |
88 |
> |
String timeout = String.valueOf(reg.getAlertTimeout(reg.getLastAlertLevel()) / 1000); |
89 |
|
if (thresholdLevel == Alert.thresholdNORMAL) { |
90 |
|
thresholdValue = "-"; |
91 |
|
} |
92 |
|
if (alertLevel == Alert.alertOK) { |
93 |
|
timeout = "0"; |
94 |
|
} |
95 |
< |
Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime(attributeNum)); |
95 |
> |
Alert alert = new Alert(alertLevel, lastAlert, thresholdLevel, source, thresholdValue, currentValue, attributeName, timeout, reg.getInitialAlertTime()); |
96 |
|
_alerterQueue.add(alert); |
97 |
|
_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"); |
98 |
|
} |