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

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

public class ServiceMonitorDNS
extends Object
implements ServiceMonitor

This class is designed to be used by the service poller framework to test the availability of the DNS 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.6 $
Author:
OpenNMS

Field Summary
private static int DEFAULT_PORT
          Default DNS 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
ServiceMonitorDNS()
           
 
Method Summary
private static long convertTimeToLong(String valueToConvert)
          Converts the passed time string to a time value that is measured in milliseconds.
private  void getResponse(DNSAddressRequest request, DatagramSocket socket)
          Receives the data packet and retrieves the address from the packet.
 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 DNS 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.
private  void sendRequest(DNSAddressRequest request, DatagramSocket socket, InetAddress nameServer, int port)
          Sends a DNSAddressRequest to the name server.
 String serviceName()
          Returns the name of the service that the plug-in monitors ("DNS").
 
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 DNS 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

ServiceMonitorDNS

public ServiceMonitorDNS()
Method Detail

serviceName

public String serviceName()

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

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 DNS service availability.

During the poll an DNS address request query packet is generated for hostname 'localhost'. The query is sent via UDP socket to the interface at the specified port (by default UDP port 53). If a response is received, it is parsed and validated. If the DNS lookup was successful the service status is set to SERVICE_AVAILABLE and the method returns.

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.

sendRequest

private void sendRequest(DNSAddressRequest request,
                         DatagramSocket socket,
                         InetAddress nameServer,
                         int port)
                  throws IOException

Sends a DNSAddressRequest to the name server.

Parameters:
request - The address request to send to the name server.
socket - The datagram socket the request is sent on.
nameServer - The nameserver address for the packet destination.
port - The port number to send the address.
Throws:
IOException - Thrown if an error occurs while sending the datagram packet.

getResponse

private void getResponse(DNSAddressRequest request,
                         DatagramSocket socket)
                  throws IOException

Receives the data packet and retrieves the address from the packet.

Parameters:
request - the DNSAddressRequest whose response is to be got
socket - the socket on which the response is recieved
Throws:
IOException - Thrown if response is not decoded as expected.

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.