|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.opennms.bb.dp.poller.plugins.ServiceMonitorSMTP
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.
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 |
|
Field Detail |
private static final String SERVICE_NAME
private static final int DEFAULT_PORT
private static final int DEFAULT_RETRY
private static final int DEFAULT_TIMEOUT
Constructor Detail |
public ServiceMonitorSMTP()
Method Detail |
public String serviceName()
Returns the name of the service that the plug-in monitors ("SMTP").
serviceName
in interface ServiceMonitor
public void initialize(ConfigurationProxy proxy, Properties parameters) throws ServiceMonitorException
Initialize the service monitor.
initialize
in interface ServiceMonitor
proxy
- The object that can be used to load/save config information.parameter
- The parameters from the appropiate package(s).ServiceMonitorException
- Thrown if
an unrecoverable error occurs that prevents the plug-in from functioning.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.
release
in interface ServiceMonitor
ServiceMonitorException
- Thrown if
an error occurs during deallocation.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.
initialize
in interface ServiceMonitor
iface
- The network interface to be added to the scheduler.ServiceMonitorException
- Thrown if
an unrecoverable error occurs that prevents the interface from being monitored.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.
release
in interface ServiceMonitor
iface
- The network interface that was being monitored.ServiceMonitorException
- Thrown if
an unrecoverable error occurs for the interface.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.
poll
in interface ServiceMonitor
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.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.
istream
- The input stream from which characters are to be read.java.lang.IOException
- Thrown if an error occurs reading
the data from the stream.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:
Extension | Conversion Value |
---|---|
us | Microseconds |
ms | Milliseconds |
s | Seconds |
m | Minutes |
h | Hours |
d | Days |
A number entered with out any units is considered to be in milliseconds.
valueToConvert
- The string to convert to milliseconds.NumberFormatException
- Thrown if the string is
malformed and a number cannot be extracted from the value.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |