org.opennms.bb.dp.poller.plugins
Class ServiceMonitorSMTP

java.lang.Object
  |
  +--org.opennms.bb.dp.poller.plugins.ServiceMonitorSMTP
All Implemented Interfaces:
ServiceMonitor

public class ServiceMonitorSMTP
extends Object
implements ServiceMonitor

This class is designed to be used by the service poller framework to test the availability of the SMTP service on remote interfaces. The class implements the ServiceMonitor interface that allows it to be used along with other plug-ins by the service poller framework.

Version:
CVS $Revision: 1.5 $
Author:
OpenNMS

Field Summary
private static int DEFAULT_PORT
          Default SMTP port.
private static int DEFAULT_RETRY
          Default retries.
private static int DEFAULT_TIMEOUT
          Default timeout.
private static String SERVICE_NAME
          Name of monitored service.
 
Fields inherited from interface org.opennms.bb.dp.poller.plugins.ServiceMonitor
SERVICE_AVAILABLE, SERVICE_STATUS_MASK, SERVICE_UNAVAILABLE, SURPRESS_EVENT_MASK
 
Constructor Summary
ServiceMonitorSMTP()
           
 
Method Summary
private static long convertTimeToLong(String valueToConvert)
          Converts the passed time string to a time value that is measured in milliseconds.
private  String getLine(InputStream istream)
          Reads a single line at a time from the input stream.
 void initialize(ConfigurationProxy proxy, Properties parameters)
          Initialize the service monitor.
 void initialize(NetworkInterface iface)
          Called by the poller framework when an interface is being added to the scheduler.
 int poll(NetworkInterface iface, EventProxy eproxy, Properties parameters)
          Poll the specified address for SMTP service availability.
 void release()
          Called by the poller framework when the plug-in is being unloaded.
 void release(NetworkInterface iface)
          Called by the poller framework when an interface is being removed from the scheduler.
 String serviceName()
          Returns the name of the service that the plug-in monitors ("SMTP").
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

SERVICE_NAME

private static final String SERVICE_NAME
Name of monitored service.

DEFAULT_PORT

private static final int DEFAULT_PORT
Default SMTP port.

DEFAULT_RETRY

private static final int DEFAULT_RETRY
Default retries.

DEFAULT_TIMEOUT

private static final int DEFAULT_TIMEOUT
Default timeout. Specifies how long (in milliseconds) to block waiting for data from the monitored interface.
Constructor Detail

ServiceMonitorSMTP

public ServiceMonitorSMTP()
Method Detail

serviceName

public String serviceName()

Returns the name of the service that the plug-in monitors ("SMTP").

Specified by:
serviceName in interface ServiceMonitor
Returns:
The service that the plug-in monitors.

initialize

public void initialize(ConfigurationProxy proxy,
                       Properties parameters)
                throws ServiceMonitorException

Initialize the service monitor.

Specified by:
initialize in interface ServiceMonitor
Parameters:
proxy - The object that can be used to load/save config information.
parameter - The parameters from the appropiate package(s).
Throws:
ServiceMonitorException - Thrown if an unrecoverable error occurs that prevents the plug-in from functioning.

release

public void release()
             throws ServiceMonitorException

Called by the poller framework when the plug-in is being unloaded. Any resources still being used by the monitor are released.

Specified by:
release in interface ServiceMonitor
Throws:
ServiceMonitorException - Thrown if an error occurs during deallocation.

initialize

public void initialize(NetworkInterface iface)
                throws ServiceMonitorException

Called by the poller framework when an interface is being added to the scheduler. Here we perform any necessary initialization to prepare the NetworkInterface object for polling.

Specified by:
initialize in interface ServiceMonitor
Parameters:
iface - The network interface to be added to the scheduler.
Throws:
ServiceMonitorException - Thrown if an unrecoverable error occurs that prevents the interface from being monitored.

release

public void release(NetworkInterface iface)
             throws ServiceMonitorException

Called by the poller framework when an interface is being removed from the scheduler. Here we free any resources or save any persistent information associated with the interface.

If an exception is thrown during the release the exception will be logged, but the interface will still be discarded for garbage collection.

Specified by:
release in interface ServiceMonitor
Parameters:
iface - The network interface that was being monitored.
Throws:
ServiceMonitorException - Thrown if an unrecoverable error occurs for the interface.

poll

public int poll(NetworkInterface iface,
                EventProxy eproxy,
                Properties parameters)
         throws ServiceMonitorException

Poll the specified address for SMTP service availability.

During the poll an attempt is made to connect on the specified port (by default TCP port 25). If the connection request is successful, the banner line generated by the interface is parsed and if the extracted return code indicates that we are talking to an SMTP server we continue. Next, an SMTP 'HELO' command is sent to the interface. Again the response is parsed and a return code extracted and verified. Finally, an SMTP 'QUIT' command is sent. Provided that the interface's response is valid we set the service status to SERVICE_AVAILABLE and return.

Specified by:
poll in interface ServiceMonitor
Parameters:
iface - The network interface to test the service on.
eproxy - The event proxy object for sending custom events.
parameters - The package parameters (timeout, retry, etc...) to be used for this poll.
Returns:
The availibility of the interface and if a transition event should be supressed.

getLine

private String getLine(InputStream istream)
                throws IOException

Reads a single line at a time from the input stream. Each line is terminated by the sequence '\r\n'. For more information on the format of the line see the SMTP RFC.

If the end of file condition is reached before the cariage-return line-feed sequence then the received buffer is returned, or a string of zero length.

NOTE: The \r\n sequence is stripped from the returned line.

Parameters:
istream - The input stream from which characters are to be read.
Returns:
A line of characters read off the input stream.
Throws:
java.lang.IOException - Thrown if an error occurs reading the data from the stream.

convertTimeToLong

private static long convertTimeToLong(String valueToConvert)
                               throws NumberFormatException

Converts the passed time string to a time value that is measured in milliseconds. The following extension are considered when converting the string:

ExtensionConversion Value
usMicroseconds
msMilliseconds
sSeconds
mMinutes
hHours
dDays

A number entered with out any units is considered to be in milliseconds.

Parameters:
valueToConvert - The string to convert to milliseconds.
Returns:
Returns the string converted to a millisecond value.
Throws:
NumberFormatException - Thrown if the string is malformed and a number cannot be extracted from the value.