--- projects/cms/source/server/uk/org/iscream/cms/server/client/alerters/IRC__Alerter.java 2001/03/02 02:46:56 1.6 +++ projects/cms/source/server/uk/org/iscream/cms/server/client/alerters/IRC__Alerter.java 2001/03/03 01:09:53 1.7 @@ -14,7 +14,7 @@ import java.net.*; * This Alert sends an IRC message. * * @author $Author: tdb $ - * @version $Id: IRC__Alerter.java,v 1.6 2001/03/02 02:46:56 tdb Exp $ + * @version $Id: IRC__Alerter.java,v 1.7 2001/03/03 01:09:53 tdb Exp $ */ public class IRC__Alerter implements PluginAlerter { @@ -23,7 +23,7 @@ public class IRC__Alerter implements PluginAlerter { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.6 $"; + public final String REVISION = "$Revision: 1.7 $"; public final String DESC = "Sends alerts on an IRC channel"; @@ -32,28 +32,13 @@ public class IRC__Alerter implements PluginAlerter { //---CONSTRUCTORS--- public IRC__Alerter() { - // get the configuration for this alerter - Configuration config = ReferenceManager.getInstance().getCM().getConfiguration(_name); - - // an integer value - _level = Integer.parseInt(config.getProperty("Alerter.IRC.level")); - // the hostname of the IRC server - _IRCServer = config.getProperty("Alerter.IRC.IRCServer"); - // the port number of the IRC server - _IRCPort = Integer.parseInt(config.getProperty("Alerter.IRC.IRCPort")); - // the nickname to use - _nick = config.getProperty("Alerter.IRC.nick"); - // the channel to join - _channel = config.getProperty("Alerter.IRC.channel"); - // a message with the following: %level% and %message% - _message = config.getProperty("Alerter.IRC.message"); - + // connect to the IRC server _ircbot = null; try { _ircbot = new IRCBot(); _ircbot.connect(); - _ircbot.sendNotice("iscreamBot activated"); + _ircbot.sendNotice("i-scream alerting bot activated"); } catch(IOException e) { _logger.write(toString(), Logger.ERROR, "Error starting IRCBot: "+e); } @@ -64,11 +49,13 @@ public class IRC__Alerter implements PluginAlerter { //---PUBLIC METHODS--- public void sendAlert(Alert alert) { + ConfigurationProxy cp = ConfigurationProxy.getInstance(); + int level = Integer.parseInt(cp.getProperty(_name, "Alerter.IRC.level")); // only send if it's equal (or above) our level - if(alert.getLevel() >= _level) { + if(alert.getLevel() >= level) { String alertType = Alert.alerts[alert.getLevel()]+"["+String.valueOf(alert.getLevel())+"]"; // sort out the message - String message = _message; + String message = cp.getProperty(_name, "Alerter.IRC.message"); message = StringUtils.replaceText(message, "%level%", alertType); message = StringUtils.replaceText(message, "%source%", alert.getSource()); message = StringUtils.replaceText(message, "%value%", alert.getValue()); @@ -109,28 +96,12 @@ public class IRC__Alerter implements PluginAlerter { //---ACCESSOR/MUTATOR METHODS--- //---ATTRIBUTES--- - - // an integer value - private int _level; - // the hostname of the IRC server - private String _IRCServer; - - // the port number of the IRC server - private int _IRCPort; - - // the nickname to use - private String _nick; - - // the channel to join - private String _channel; - - // the ircbot + /** + * A reference to the IRCBot + */ private IRCBot _ircbot; - // a message with the following: %level% and %message% - private String _message; - /** * This is the friendly identifier of the * component this class is running in. @@ -209,15 +180,19 @@ public class IRC__Alerter implements PluginAlerter { * @throws IOException if the connection fails */ public void connect() throws IOException { + ConfigurationProxy cp = ConfigurationProxy.getInstance(); // setup the socket, reader and writer - _socket = new Socket(_IRCServer, _IRCPort); + String server = cp.getProperty(_name, "Alerter.IRC.IRCServer"); + int port = Integer.parseInt(cp.getProperty(_name, "Alerter.IRC.IRCPort")); + _socket = new Socket(server, port); _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream())); _socketOut = new PrintWriter(_socket.getOutputStream(), true); // send the various log in messages _socketOut.println("PASS"); - _socketOut.println("NICK "+_nick); - _socketOut.println("USER iscream 8 * :i-scream Bot"); + _socketOut.println("NICK "+cp.getProperty(_name, "Alerter.IRC.nick")); + _socketOut.println("USER i-scream 8 * :i-scream alerter bot"); // join the channel + _channel = cp.getProperty(_name, "Alerter.IRC.channel"); _socketOut.println("JOIN "+_channel); // start our listening thread this.start(); @@ -236,7 +211,7 @@ public class IRC__Alerter implements PluginAlerter { _socketIn.close(); _socket.close(); } - + /** * The socket connected to the server */ @@ -252,6 +227,11 @@ public class IRC__Alerter implements PluginAlerter { */ private BufferedReader _socketIn; + /** + * Just a reminder to what channel we're on... + * this can't be dynamic :) + */ + private String _channel; } }