org.opennms.bb.dp.poller.plugins
Interface ServiceMonitor

All Known Implementing Classes:
ServiceMonitorDNS, ServiceMonitorFTP, ServiceMonitorHTTP, ServiceMonitorSMTP, ServiceMonitorICMP

public interface ServiceMonitor

This is the interfact that is implemented by a poller framework plug-in that performs service monitoring. Each plug-in is uniquely identified by its service name. In order for the framework to appropriate use a plug-in the service name must be the exact same as the service names in the service package and the Service table in the distribute poller database.

When a service monitor plug-in is loaded and initialized, the framework will initialize the monitor by calling the initialize() method. Likewise, when the monitor is unloaded the framework calls the release() method is called. If the plug-in needs to save or read any configuration information after the initialize() call, a reference to the proxy object should be saved at initialization.

NOTE: The plug-in poll() must be thread safe in order to operate. Any synchronized methods or data accessed in the poll() can negatively affect the framework if multiple poller threads are blocked on a critical resource. Synchronization issues should be seriously evaluated to ensure that the plug-in scales well to large deployments.

Version:
CVS $Revision: 1.5 $
Author:
Brian Weaver, OpenNMS

Field Summary
static int SERVICE_AVAILABLE
          The constant that defines a service as being in a normal state.
static int SERVICE_STATUS_MASK
          The status mask is used to mask off the bits that apply to scheduling information only.
static int SERVICE_UNAVAILABLE
          The constant that defines a service that is not working normally and should be scheduled using the downtime models.
static int SURPRESS_EVENT_MASK
          This constants defines the mask that can be bitwise anded with the status return from the poll() method to determine if a status event should be surpressed.
 
Method Summary
 void initialize(ConfigurationProxy proxy, Properties parameters)
          This method is called after the framework creates an instance of the plug-in.
 void initialize(NetworkInterface iface)
          This method is called whenever a new interface that supports the plug-in service is added to the scheduling system.
 int poll(NetworkInterface iface, EventProxy eproxy, Properties parameters)
          This method is the heart of the plug-in monitor.
 void release()
          This method is called whenever the plug-in is being unloaded, normally during framework exit.
 void release(NetworkInterface iface)
          This method is the called whenever an interface is being removed from the scheduler.
 String serviceName()
          Returns the name of the service that the plug-in monitors.
 

Field Detail

SERVICE_AVAILABLE

public static final int SERVICE_AVAILABLE

The constant that defines a service as being in a normal state. If this is returned by the poll() method then the framework will re-schedule the service for its next poll using the standard uptime interval


SERVICE_UNAVAILABLE

public static final int SERVICE_UNAVAILABLE

The constant that defines a service that is not working normally and should be scheduled using the downtime models.


SERVICE_STATUS_MASK

public static final int SERVICE_STATUS_MASK

The status mask is used to mask off the bits that apply to scheduling information only. The other bits of the status return information are used to encode special processing instructions to the poller framework.


SURPRESS_EVENT_MASK

public static final int SURPRESS_EVENT_MASK

This constants defines the mask that can be bitwise anded with the status return from the poll() method to determine if a status event should be surpressed. By default the framework will generate an event when the status transitions from up to down or vice versa. If the mask bit is set then the framework should not generate a transitional event.

Method Detail

serviceName

public String serviceName()

Returns the name of the service that the plug-in monitors. A plug-in can only support a single service and the returned name must match both the name of the service in the package definition and an entry in the distributed poller services table.

Returns:
The service that the plug-in monitors.

initialize

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

This method is called after the framework creates an instance of the plug-in. The framework passes the object a proxy object that can be used to retreive configuration information specific to the plug-in. Additionally, any parameters for the plug-in from the package definition are passed using the parameters element.

If there is a critical error, like missing service libraries, the the montior may throw a ServiceMonitorException. If the plug-in throws an exception then the plug-in will be disabled in the framework.

Parameters:
proxy - The object that can be used to load/save config information.
parameters - Not currently used
Throws:
ServiceMonitorException - Thrown if an unrecoverable error occurs that prevents the plug-in from functioning.

release

public void release()
             throws ServiceMonitorException

This method is called whenever the plug-in is being unloaded, normally during framework exit. During this time the framework may release any resource and save any state information using the proxy object from the initialization routine.

Even if the plug-in throws a monitor exception, it will not prevent the plug-in from being unloaded. The plug-in should not return until all of its state information is saved. Once the plug-in returns from this call its configuration proxy object is considered invalid.

Throws:
ServiceMonitorException - Thrown if an error occurs during deallocation.

initialize

public void initialize(NetworkInterface iface)
                throws ServiceMonitorException

This method is called whenever a new interface that supports the plug-in service is added to the scheduling system. The plug-in has the option to load and/or associate configuration information with the interface before the framework begins scheduling the new device.

Should a monitor exception be thrown during an initialization call then the framework will log an error and discard the interface from scheduling.

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

This method is the called whenever an interface is being removed from the scheduler. For example, if a service is determined as being no longer supported then this method will be invoked to cleanup any information associated with this device. This gives the implementor of the interface the ability to serialize any data prior to the interface being discarded.

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

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

This method is the heart of the plug-in monitor. Each time an interface requires a check to be performed as defined by the scheduler the poll method is invoked. The poll is passed the interface to check and a reference to an EventProxy object. The proxy object can be used to send special events as defined by the monitor. This allows special events aside from the standard available/unavailable performed by the scheduler.

By default when the status transition from up to down or vice versa the framework will generate an event. Additionally, if the polling interval changes due to an extended unavailbility, the framework will generate an additional down event. The plug-in can surpress the generation of the default events by setting the surpress event bit in the returned integer.

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 surpressed.
See Also:
SURPRESS_EVENT_MASK, #STATUS_AVAILABLE, #STATUS_UNAVAILABLE