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.20 by ajm, Thu Mar 22 23:35:22 2001 UTC vs.
Revision 1.25 by tdb, Sat May 18 18:16:00 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 < package uk.org.iscream.client.alerters;
21 > package uk.org.iscream.cms.server.client.alerters;
22  
23   //---IMPORTS---
24 < import uk.org.iscream.client.*;
25 < import uk.org.iscream.core.*;
26 < import uk.org.iscream.util.*;
27 < import uk.org.iscream.componentmanager.*;
24 > import uk.org.iscream.cms.server.client.*;
25 > import uk.org.iscream.cms.server.core.*;
26 > import uk.org.iscream.cms.server.util.*;
27 > import uk.org.iscream.cms.server.componentmanager.*;
28   import java.io.*;
29   import java.util.StringTokenizer;
30  
# Line 25 | Line 44 | public class EMail__Alerter extends AlerterSkeleton {
44       */
45      public final String REVISION = "$Revision$";
46      
47 +    /**
48 +     * A description of this alerter
49 +     */
50      public final String DESC = "Sends alerts over e-mail.";
51      
30    public final String NOT_CONFIGURED = "<NOT CONFIGURED>";
31    
52   //---STATIC METHODS---
53  
54   //---CONSTRUCTORS---
55  
56   //---PUBLIC METHODS---
57  
58 +    /**
59 +     * Implements the abstract method from the skeleton class.
60 +     * This method will attempt to send an alert
61 +     * message using the configured email configuration.
62 +     *
63 +     * @param alert the alert to send
64 +     */
65      public void sendAlert(Alert alert) {
66 <        String alertType = Alert.alertLevels[alert.getLevel()];
40 <        // sort out the subject
66 >        // get the subject and replace fields
67          String subject;
68          try {
69              subject = _cp.getProperty(_name, "Alerter.EMail.subject");
# Line 47 | Line 73 | public class EMail__Alerter extends AlerterSkeleton {
73          }
74          subject = processAlertMessage(subject, alert);
75                      
76 <        // sort out the message body
76 >        // get the message body and replace fields
77          String message;
78          try {
79              message = _cp.getProperty(_name, "Alerter.EMail.message");
# Line 56 | Line 82 | public class EMail__Alerter extends AlerterSkeleton {
82              _logger.write(toString(), Logger.WARNING, "Alerter.EMail.message value unavailable using default of " + message);
83          }
84          message = processAlertMessage(message, alert);
85 <                    
85 >        
86 >        // attempt to send the actual message
87          try {
88              // create SMTP message
89              Smtp smtp = new Smtp(_cp.getProperty(_name, "Alerter.EMail.smtpServer"));
90              // set our sender
91              smtp.setSender(_cp.getProperty(_name, "Alerter.EMail.sender"));
92              
93 +            // list of destination addresses
94              String destList = _cp.getProperty("Host."+alert.getSource(), "Alerter.EMail.destList");
95              
96              // set the to: list
# Line 73 | Line 101 | public class EMail__Alerter extends AlerterSkeleton {
101  
102              // prepare to print the message            
103              PrintWriter out = smtp.getOutputStream();
104 <            out.println("Subject: "+subject);
77 <            out.println();
104 >            out.println("Subject: "+subject+"\n");
105              
106              // send the message
107              out.println(message);
108              smtp.sendMessage();
109              smtp.close();
110 <            _logger.write(toString(), Logger.DEBUG, "Sending " + _name + " at "+ alertType + " level");
110 >            _logger.write(toString(), Logger.DEBUG, "Sending " + _name + " at "+ Alert.alertLevels[alert.getLevel()] + " level");
111          }
112          catch(IOException e) {
113              _logger.write(toString(), Logger.ERROR, "Error whilst sending message: "+e);
# Line 94 | Line 121 | public class EMail__Alerter extends AlerterSkeleton {
121       * Overrides the {@link java.lang.Object#toString() Object.toString()}
122       * method to provide clean logging (every class should have this).
123       *
124 <     * This uses the uk.org.iscream.util.NameFormat class
124 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
125       * to format the toString()
126       *
127       * @return the name of this class and its CVS revision
# Line 107 | Line 134 | public class EMail__Alerter extends AlerterSkeleton {
134      }
135  
136      /**
137 <     * return the String representation of what the alerter does
137 >     * Return the String representation of what the alerter does
138 >     *
139 >     * @return the description
140       */
141      public String getDescription(){
142          return DESC;
# Line 116 | Line 145 | public class EMail__Alerter extends AlerterSkeleton {
145   //---PRIVATE METHODS---
146      
147   //---ACCESSOR/MUTATOR METHODS---
148 +    
149 +    /**
150 +     * Returns the "friendly" name of this class. This
151 +     * is simply an accessor for _name, required due to
152 +     * inheritance issues with extending AlerterSkeleton.
153 +     *
154 +     * @return the friendly name
155 +     */
156 +    protected String getFName() {
157 +        return _name;
158 +    }
159  
160   //---ATTRIBUTES---
161      
# Line 129 | Line 169 | public class EMail__Alerter extends AlerterSkeleton {
169       * be changed to null for utility classes.
170       */
171      protected String _name = "EMail";
132
133    /**
134     * This holds a reference to the
135     * system logger that is being used.
136     */
137    private Logger _logger = ReferenceManager.getInstance().getLogger();
172      
173   //---STATIC ATTRIBUTES---
174  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines