ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/alerters/EMail__Alerter.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/alerters/EMail__Alerter.java (file contents):
Revision 1.8 by tdb, Sat Mar 3 01:09:53 2001 UTC vs.
Revision 1.9 by ajm, Sun Mar 4 02:41:16 2001 UTC

# Line 39 | Line 39 | public class EMail__Alerter implements PluginAlerter {
39  
40      public void sendAlert(Alert alert) {
41          ConfigurationProxy cp = ConfigurationProxy.getInstance();
42 <        int level = Integer.parseInt(cp.getProperty(_name, "Alerter.EMail.level"));
42 >        String levelName = cp.getProperty(_name, "Alerter.EMail.level");
43 >        int level = StringUtils.getStringPos(levelName, Alert.alertLevels);
44          // only send if it's equal (or above) our level
45          if(alert.getLevel() >= level) {
46 <            String alertType = Alert.alerts[alert.getLevel()]+"["+String.valueOf(alert.getLevel())+"]";
46 >            String alertType = Alert.alertLevels[alert.getLevel()];
47 >            String thresholdType = Alert.thresholdLevels[alert.getThreshold()];
48              // sort out the subject
49              String subject = cp.getProperty(_name, "Alerter.EMail.subject");
50              subject = StringUtils.replaceText(subject, "%level%", alertType);
51 +            subject = StringUtils.replaceText(subject, "%threshold%", thresholdType);
52              subject = StringUtils.replaceText(subject, "%source%", alert.getSource());
53              subject = StringUtils.replaceText(subject, "%value%", alert.getValue());
54              subject = StringUtils.replaceText(subject, "%thresholdValue%", alert.getThresholdValue());
55              subject = StringUtils.replaceText(subject, "%attributeName%", alert.getAttributeName());
56 <            
56 >            subject = StringUtils.replaceText(subject, "%timeTillNextAlert%",  getTimeString(Long.parseLong(alert.getTimeTillNextAlert())));
57 >                        
58              // sort out the message body
59              String message = cp.getProperty(_name, "Alerter.EMail.message");
60              message = StringUtils.replaceText(message, "%level%", alertType);
61 +            message = StringUtils.replaceText(message, "%threshold%", thresholdType);
62              message = StringUtils.replaceText(message, "%source%", alert.getSource());
63              message = StringUtils.replaceText(message, "%value%", alert.getValue());
64              message = StringUtils.replaceText(message, "%thresholdValue%", alert.getThresholdValue());
65              message = StringUtils.replaceText(message, "%attributeName%", alert.getAttributeName());
66 <            
66 >            message = StringUtils.replaceText(message, "%timeTillNextAlert%",  getTimeString(Long.parseLong(alert.getTimeTillNextAlert())));
67 >                        
68              try {
69                  // create SMTP message
70                  Smtp smtp = new Smtp(cp.getProperty(_name, "Alerter.EMail.smtpServer"));
# Line 80 | Line 86 | public class EMail__Alerter implements PluginAlerter {
86                  out.println(message);
87                  smtp.sendMessage();
88                  smtp.close();
89 <                _logger.write(toString(), Logger.DEBUG, "Sending IRC Alert at level"+String.valueOf(alert.getLevel()));
89 >                _logger.write(toString(), Logger.DEBUG, "Sending " + _name + " at "+ levelName + " level");
90              }
91              catch(IOException e) {
92                  _logger.write(toString(), Logger.ERROR, "Error whilst sending message: "+e);
# Line 113 | Line 119 | public class EMail__Alerter implements PluginAlerter {
119  
120   //---PRIVATE METHODS---
121  
122 +    private String getTimeString(long time) {
123 +        String timeString = null;
124 +        if (time >= 60) {
125 +            timeString = (time / 60) + " minutes";
126 +        } else if (time >= 3600) {
127 +            timeString = ((time/60) / 60) + " hours";
128 +        } else {
129 +            timeString = time + " seconds";
130 +        }
131 +        return timeString;
132 +    }
133 +    
134   //---ACCESSOR/MUTATOR METHODS---
135  
136   //---ATTRIBUTES---
# Line 126 | Line 144 | public class EMail__Alerter implements PluginAlerter {
144       * can be placed here.  This name could also
145       * be changed to null for utility classes.
146       */
147 <    private String _name = ClientMain.NAME;
147 >    private String _name = "EMail Alert";
148  
149      /**
150       * This holds a reference to the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines