17 |
|
* @author $Author$ |
18 |
|
* @version $Id$ |
19 |
|
*/ |
20 |
< |
public class EMail__Alerter implements PluginAlerter { |
20 |
> |
public class EMail__Alerter extends Thread implements PluginAlerter { |
21 |
|
|
22 |
|
//---FINAL ATTRIBUTES--- |
23 |
|
|
38 |
|
|
39 |
|
public EMail__Alerter() { |
40 |
|
_logger.write(toString(), Logger.SYSINIT, "IRC Alerter started"); |
41 |
+ |
this.start(); |
42 |
|
} |
43 |
|
|
44 |
|
//---PUBLIC METHODS--- |
57 |
|
if(((alert.getLevel() == 0) && (alert.getLastLevel() >= level)) || (alert.getLevel() >= level)) { |
58 |
|
String alertType = Alert.alertLevels[alert.getLevel()]; |
59 |
|
String thresholdType = Alert.thresholdLevels[alert.getThreshold()]; |
60 |
< |
String timeFirstSince = DateUtils.formatTime(System.currentTimeMillis() - alert.getInitialAlertTime(), "%DAYS% days, %HOURS% hours, %MINS% mins, and %SECS% secs"); |
60 |
> |
String timeFirstSince = DateUtils.formatTime((System.currentTimeMillis() - alert.getInitialAlertTime())/1000, "%DAYS% days, %HOURS% hours, %MINS% mins, and %SECS% secs"); |
61 |
|
String timeFirstOccured = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.UK).format(new Date(alert.getInitialAlertTime())); |
62 |
|
|
63 |
|
// sort out the subject |
74 |
|
subject = StringUtils.replaceText(subject, "%value%", alert.getValue()); |
75 |
|
subject = StringUtils.replaceText(subject, "%thresholdValue%", alert.getThresholdValue()); |
76 |
|
subject = StringUtils.replaceText(subject, "%attributeName%", alert.getAttributeName()); |
77 |
< |
subject = StringUtils.replaceText(subject, "%timeTillNextAlert%", getTimeString(Long.parseLong(alert.getTimeTillNextAlert()))); |
77 |
> |
subject = StringUtils.replaceText(subject, "%timeTillNextAlert%", DateUtils.getTimeString(Long.parseLong(alert.getTimeTillNextAlert()))); |
78 |
|
subject = StringUtils.replaceText(subject, "%timeSinceFirstAlert%", timeFirstSince); |
79 |
|
subject = StringUtils.replaceText(subject, "%timeOfFirstAlert%", timeFirstOccured); |
80 |
|
|
92 |
|
message = StringUtils.replaceText(message, "%value%", alert.getValue()); |
93 |
|
message = StringUtils.replaceText(message, "%thresholdValue%", alert.getThresholdValue()); |
94 |
|
message = StringUtils.replaceText(message, "%attributeName%", alert.getAttributeName()); |
95 |
< |
message = StringUtils.replaceText(message, "%timeTillNextAlert%", getTimeString(Long.parseLong(alert.getTimeTillNextAlert()))); |
95 |
> |
message = StringUtils.replaceText(message, "%timeTillNextAlert%", DateUtils.getTimeString(Long.parseLong(alert.getTimeTillNextAlert()))); |
96 |
|
message = StringUtils.replaceText(message, "%timeSinceFirstAlert%", timeFirstSince); |
97 |
|
message = StringUtils.replaceText(message, "%timeOfFirstAlert%", timeFirstOccured); |
98 |
|
|
102 |
|
// set our sender |
103 |
|
smtp.setSender(cp.getProperty(_name, "Alerter.EMail.sender")); |
104 |
|
|
105 |
< |
// get the default destination list |
105 |
< |
String destList = cp.getProperty(_name, "Alerter.EMail.defaultDestList"); |
106 |
< |
// check if the source we're alerting about has a specific destination |
107 |
< |
String sourceDestList = cp.getProperty("Host."+alert.getSource(), "Alerter.EMail.destList"); |
108 |
< |
if(sourceDestList != null) { |
109 |
< |
// if there is a source destination list, use it |
110 |
< |
destList = sourceDestList; |
111 |
< |
} |
105 |
> |
String destList = cp.getProperty("Host."+alert.getSource(), "Alerter.EMail.destList"); |
106 |
|
|
107 |
|
// set the to: list |
108 |
|
StringTokenizer st = new StringTokenizer(destList, ";"); |
154 |
|
} |
155 |
|
|
156 |
|
//---PRIVATE METHODS--- |
157 |
+ |
|
158 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
159 |
|
|
160 |
< |
private String getTimeString(long time) { |
161 |
< |
String timeString = null; |
166 |
< |
if (time >= 60) { |
167 |
< |
timeString = (time / 60) + " minutes"; |
168 |
< |
} else if (time >= 3600) { |
169 |
< |
timeString = ((time/60) / 60) + " hours"; |
170 |
< |
} else { |
171 |
< |
timeString = time + " seconds"; |
172 |
< |
} |
173 |
< |
return timeString; |
160 |
> |
protected Queue getQueue() { |
161 |
> |
return AlerterManager.getInstance().getQueue(); |
162 |
|
} |
163 |
|
|
164 |
< |
//---ACCESSOR/MUTATOR METHODS--- |
164 |
> |
protected int getQueueId() { |
165 |
> |
if (_qID == -1) { |
166 |
> |
_qID = getQueue().getQueue(); |
167 |
> |
_logger.write(toString(), Logger.DEBUG, "Assigned Queue - " + _qID); |
168 |
> |
} |
169 |
> |
return _qID; |
170 |
> |
} |
171 |
|
|
172 |
|
//---ATTRIBUTES--- |
173 |
|
|
187 |
|
* system logger that is being used. |
188 |
|
*/ |
189 |
|
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
190 |
+ |
|
191 |
+ |
/** |
192 |
+ |
* The queue id for this alerters queue in the alert queue |
193 |
+ |
*/ |
194 |
+ |
private int _qID = -1; |
195 |
+ |
|
196 |
+ |
/** |
197 |
+ |
* The running status of the alerter |
198 |
+ |
*/ |
199 |
+ |
private boolean _running = true; |
200 |
|
|
201 |
|
//---STATIC ATTRIBUTES--- |
202 |
|
|