OpenNMS API 1.2.9

## org.opennms.netmgt.capsd
Class SuspectEventProcessor

    java.lang.Object
      org.opennms.netmgt.capsd.SuspectEventProcessor

All Implemented Interfaces:
  java.lang.Runnable

final class SuspectEventProcessor
extends java.lang.Object
implements java.lang.Runnable

This class is designed to scan/capability check a suspect interface, update the database based on the information collected from the device, and generate events necessary to notify the other OpenNMS services. The constructor takes a string which is the IP address of the interface to be scanned.

Author:
  James Zuo , Mike Davidson , Brian Weaver , OpenNMS

Field Summary
`(package private) java.lang.String` `m_suspectIf` IP address of new suspect interface
`private static java.lang.String` `SELECT_METHOD_MAX`
`private static java.lang.String` `SELECT_METHOD_MIN`
`private static java.lang.String` `SQL_RETRIEVE_INTERFACE_NODEID_PREFIX` SQL statement to retrieve the node identifier for a given IP address
`private static java.lang.String` `SQL_RETRIEVE_IPINTERFACES_ON_NODEID` SQL statement to retrieve the ipaddresses for a given node ID

Constructor Summary
`(package private)` `SuspectEventProcessor(java.lang.String ifAddress)` Constructor.

Method Summary
`private void` `addInterfaces(java.sql.Connection dbc, DbNodeEntry node, boolean useExistingNode, java.net.InetAddress ifaddr, IfCollector collector)` This method is responsble for inserting new entries into the ipInterface table for each interface found to be associated with the suspect interface during the capabilities scan.
`private void` `addSupportedProtocols(DbNodeEntry node, java.net.InetAddress ifaddr, java.util.List protocols, boolean addrUnmanaged, int ifIndex, Package ipPkg)` Responsible for iterating inserting an entry into the ifServices table for each protocol supported by the interface.
`private static java.util.List` `buildLBSnmpAddressList(IfCollector collector)` Builds a list of InetAddress objects representing each of the interfaces from the IfCollector object which support SNMP and have a valid ifIndex and is a loopback interface.
`private static java.util.List` `buildSnmpAddressList(IfCollector collector)` Builds a list of InetAddress objects representing each of the interfaces from the IfCollector object which support SNMP and have a valid ifIndex.
`(package private) static java.net.InetAddress` `compareAndSelectPrimary(java.net.InetAddress currentIf, java.net.InetAddress oldPrimary, java.lang.String method)` Utility method which compares two InetAddress objects based on the provided method (MIN/MAX) and returns the InetAddress which is to be considered the primary interface.
`private void` `createAndSendDuplicateIpaddressEvent(int nodeId, java.lang.String ipAddr)` This method is responsible for creating and sending a 'duplicateIPAddress' event to Eventd
`private void` `createAndSendNodeAddedEvent(DbNodeEntry nodeEntry)` This method is responsible for creating and sending a 'nodeAdded' event to Eventd
`private void` `createAndSendNodeGainedInterfaceEvent(int nodeId, java.net.InetAddress ipAddr)` This method is responsible for creating and sending a 'nodeGainedInterface' event to Eventd
`private void` `createAndSendNodeGainedServiceEvent(DbNodeEntry nodeEntry, java.net.InetAddress ipAddr, java.lang.String svcName, java.lang.String qualifier)` This method is responsible for creating and sending a 'nodeGainedService' event to Eventd
`private void` `createAndSendPrimarySnmpInterfaceChangedEvent(int nodeId, java.net.InetAddress newPrimaryIf, java.net.InetAddress oldPrimaryIf)` This method is responsible for generating a primarySnmpInterfaceChanged event and sending it to eventd..
`private void` `createAndSendReinitializePrimarySnmpInterfaceEvent(int nodeId, java.net.InetAddress primarySnmpIf)` This method is responsible for generating a reinitializePrimarySnmpInterface event and sending it to eventd.
`private DbNodeEntry` `createNode(java.sql.Connection dbc, java.net.InetAddress ifaddr, IfCollector collector)` This method is responsble for inserting a new node into the node table.
`private java.net.InetAddress` `determinePrimaryInterface(IfCollector collector)` This method is responsbile for determining the node's primary IP interface from among all the node's IP interfaces.
`private void` `generateSnmpDataCollectionEvents(DbNodeEntry nodeEntry, java.net.InetAddress oldPrimary, java.net.InetAddress newPrimary)` Determines if any SNMP data collection related events need to be generated based upon the results of the current rescan.
`private java.lang.String` `getDuplicateIpaddress(java.util.List ipListA, java.util.List ipListB)` This method is used to verify if there is a same ipaddress existing in two sets of ipaddresses, and return the first ipaddress that is the same in both sets as a string.
`private DbNodeEntry` `getExistingNodeEntry(java.sql.Connection dbc, IfCollector collector)` This method is responsible for determining if a node already exists in the database for the current interface.
`(package private) static int` `getIfType(java.net.InetAddress ipaddr, IfSnmpCollector snmpc)` Utility method which determines returns the ifType for the passed IP address.
`(package private) static java.util.List` `getPrimarySnmpInterfaceFromDb(java.sql.Connection dbc, DbNodeEntry node)` Returns a list of InetAddress object(s) of the primary SNMP interface(s) (if one or more exists).
`(package private) static boolean` `hasIfIndex(java.net.InetAddress ipaddr, IfSnmpCollector snmpc)` Utility method which determines if the passed IfSnmpCollector object contains an ifIndex value for the passed IP address.
`void` `run()` This is where all the work of the class is done.
`private void` `sendInterfaceEvents(DbNodeEntry node, boolean useExistingNode, java.net.InetAddress ifaddr, IfCollector collector)` This method is responsible for creating all the necessary interface-level events for the node and sending them to Eventd.
`(package private) static void` `setPrimarySnmpInterface(java.sql.Connection dbc, DbNodeEntry node, java.net.InetAddress newPrimarySnmpIf, java.net.InetAddress oldPrimarySnmpIf)` Responsible for setting the value of the 'isSnmpPrimary' field of the ipInterface table to 'P' (Primary) for the primary SNMP interface address.
`(package private) static boolean` `supportsSnmp(java.util.List supportedProtocols)` Utility method which checks the provided list of supported protocols to determine if the SNMP service is present.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### SQL_RETRIEVE_INTERFACE_NODEID_PREFIX

    private static java.lang.String SQL_RETRIEVE_INTERFACE_NODEID_PREFIX

  SQL statement to retrieve the node identifier for a given IP address

### SQL_RETRIEVE_IPINTERFACES_ON_NODEID

    private static final java.lang.String SQL_RETRIEVE_IPINTERFACES_ON_NODEID

  SQL statement to retrieve the ipaddresses for a given node ID

  See Also:
    Constant Field Values

### SELECT_METHOD_MIN

    private static final java.lang.String SELECT_METHOD_MIN

See Also:
  Constant Field Values

### SELECT_METHOD_MAX

    private static final java.lang.String SELECT_METHOD_MAX

See Also:
  Constant Field Values

### m_suspectIf

    java.lang.String m_suspectIf

  IP address of new suspect interface

Constructor Detail

### SuspectEventProcessor

    SuspectEventProcessor(java.lang.String ifAddress)

  Constructor.

Parameters:
  `ifAddress` - Suspect interface address.

Method Detail

### getExistingNodeEntry

    private DbNodeEntry getExistingNodeEntry(java.sql.Connection dbc,
                                             IfCollector collector)
                                      throws java.sql.SQLException

  This method is responsible for determining if a node already exists in the database for the current interface. If the IfCollector object contains a valid SNMP collection, an attempt will be made to look up in the database each interface contained in the SNMP collection's ifTable. If an interface is found to already exist in the database a DbNodeEntry object will be created from it and returned. If the IfCollector object does not contain a valid SNMP collection or if none of the interfaces exist in the database null is returned.

  Parameters:
    `dbc` - Connection to the database.
    `collector` - Interface collector object
  Returns:
    dbNodeEntry Returns null if a node does not already exist in the database, otherwise returns the DbNodeEntry object for the node under which the current interface/IP address should be added.
  Throws:
    `java.sql.SQLException` - Thrown if an error occurs retrieving the parent nodeid from the database.

### getDuplicateIpaddress

    private java.lang.String getDuplicateIpaddress(java.util.List ipListA,
                                                   java.util.List ipListB)

  This method is used to verify if there is a same ipaddress existing in two sets of ipaddresses, and return the first ipaddress that is the same in both sets as a string.

  Parameters:
    `ipListA` - a collection of ip addresses.
    `ipListB` - a collection of ip addresses.
  Returns:
    the first ipaddress exists in both ipaddress lists.

### createNode

    private DbNodeEntry createNode(java.sql.Connection dbc,
                                   java.net.InetAddress ifaddr,
                                   IfCollector collector)
                            throws java.sql.SQLException

  This method is responsble for inserting a new node into the node table.

  Parameters:
    `dbc` - Database connection.
    `ifaddr` - Suspect interface
    `collector` - Interface collector containing SMB and SNMP info collected from the remote device.
  Returns:
    DbNodeEntry object associated with the newly inserted node table entry.
  Throws:
    `java.sql.SQLException` - if an error occurs inserting the new node.

### addInterfaces

    private void addInterfaces(java.sql.Connection dbc,
                               DbNodeEntry node,
                               boolean useExistingNode,
                               java.net.InetAddress ifaddr,
                               IfCollector collector)
                        throws java.sql.SQLException

  This method is responsble for inserting new entries into the ipInterface table for each interface found to be associated with the suspect interface during the capabilities scan.

  Parameters:
    `dbc` - Database connection.
    `node` - DbNodeEntry object representing the suspect interface's parent node table entry
    `useExistingNode` - False if a new node was created for the suspect interface. True if an existing node entry was found under which the the suspect interface is to be added.
    `ifaddr` - Suspect interface
    `collector` - Interface collector containing SMB and SNMP info collected from the remote device.
  Throws:
    `java.sql.SQLException` - if an error occurs adding interfaces to the ipInterface table.

### addSupportedProtocols

    private void addSupportedProtocols(DbNodeEntry node,
                                       java.net.InetAddress ifaddr,
                                       java.util.List protocols,
                                       boolean addrUnmanaged,
                                       int ifIndex,
                                       Package ipPkg)
                                throws java.sql.SQLException

  Responsible for iterating inserting an entry into the ifServices table for each protocol supported by the interface.

  Parameters:
    `node` - Node entry
    `ifaddr` - Interface address
    `protocols` - List of supported protocols
    `addrUnmanaged` - Boolean flag indicating if interface is managed or unmanaged according to the Capsd configuration.
    `ifIndex` - Interface index or -1 if index is not known
    `ipPkg` - Poller package to which the interface belongs
  Throws:
    `java.sql.SQLException` - if an error occurs adding interfaces to the ipInterface table.

### supportsSnmp

    static boolean supportsSnmp(java.util.List supportedProtocols)

  Utility method which checks the provided list of supported protocols to determine if the SNMP service is present.

  Parameters:
    `supportedProtocols` - List of supported protocol objects.
  Returns:
    TRUE if service "SNMP" or "SNMPv1" or "SNMPv2" is present in the list, FALSE otherwise

### hasIfIndex

    static boolean hasIfIndex(java.net.InetAddress ipaddr,
                              IfSnmpCollector snmpc)

  Utility method which determines if the passed IfSnmpCollector object contains an ifIndex value for the passed IP address.

  Parameters:
    `ipaddr` - IP address
    `snmpc` - SNMP collection
  Returns:
    TRUE if an ifIndex value was found in the SNMP collection for the provided IP address, FALSE otherwise.

### getIfType

    static int getIfType(java.net.InetAddress ipaddr,
                         IfSnmpCollector snmpc)

  Utility method which determines returns the ifType for the passed IP address.

  Parameters:
    `ipaddr` - IP address
    `snmpc` - SNMP collection
  Returns:
    TRUE if an ifIndex value was found in the SNMP collection for the provided IP address, FALSE otherwise.

### compareAndSelectPrimary

    static java.net.InetAddress compareAndSelectPrimary(java.net.InetAddress currentIf,
                                                        java.net.InetAddress oldPrimary,
                                                        java.lang.String method)

  Utility method which compares two InetAddress objects based on the provided method (MIN/MAX) and returns the InetAddress which is to be considered the primary interface. NOTE: In order for an interface to be considered primary it must be managed. This method will return null if the 'oldPrimary' address is null and the 'currentIf' address is unmanaged.

  Parameters:
    `currentIf` - Interface with which to compare the 'oldPrimary' address.
    `oldPrimary` - Primary interface to be compared against the 'currentIf' address.
    `method` - Comparison method to be used (either "min" or "max")
  Returns:
    InetAddress object of the primary interface based on the provided method or null if neither address is eligible to be primary.

### buildLBSnmpAddressList

    private static java.util.List buildLBSnmpAddressList(IfCollector collector)

  Builds a list of InetAddress objects representing each of the interfaces from the IfCollector object which support SNMP and have a valid ifIndex and is a loopback interface. This is in order to allow a non-127.*.*.* loopback address to be chosen as the primary SNMP interface.

  Parameters:
    `collector` - IfCollector object containing SNMP and SMB info.
  Returns:
    List of InetAddress objects.

### buildSnmpAddressList

    private static java.util.List buildSnmpAddressList(IfCollector collector)

  Builds a list of InetAddress objects representing each of the interfaces from the IfCollector object which support SNMP and have a valid ifIndex.

  Parameters:
    `collector` - IfCollector object containing SNMP and SMB info.
  Returns:
    List of InetAddress objects.

### determinePrimaryInterface

    private java.net.InetAddress determinePrimaryInterface(IfCollector collector)

  This method is responsbile for determining the node's primary IP interface from among all the node's IP interfaces.

  Parameters:
    `collector` - IfCollector object containing SNMP and SMB info.
  Returns:
    InetAddress object of the primary SNMP interface or null if none of the node's interfaces are eligible.

### run

    public void run()

  This is where all the work of the class is done.

  Specified by:
    `run` in interface `java.lang.Runnable`

### getPrimarySnmpInterfaceFromDb

    static java.util.List getPrimarySnmpInterfaceFromDb(java.sql.Connection dbc,
                                                        DbNodeEntry node)
                                                 throws java.sql.SQLException

  Returns a list of InetAddress object(s) of the primary SNMP interface(s) (if one or more exists).

  Parameters:
    `dbc` - Database connection.
    `node` - DbNodeEntry object representing the interface's parent node table entry
  Returns:
    List of Old SNMP primary interface addresses (usually just one).
  Throws:
    `java.sql.SQLException` - if an error occurs updating the ipInterface table

### setPrimarySnmpInterface

    static void setPrimarySnmpInterface(java.sql.Connection dbc,
                                        DbNodeEntry node,
                                        java.net.InetAddress newPrimarySnmpIf,
                                        java.net.InetAddress oldPrimarySnmpIf)
                                 throws java.sql.SQLException

  Responsible for setting the value of the 'isSnmpPrimary' field of the ipInterface table to 'P' (Primary) for the primary SNMP interface address.

  Parameters:
    `dbc` - Database connection.
    `node` - DbNodeEntry object representing the suspect interface's parent node table entry
    `newPrimarySnmpIf` - New primary SNMP interface.
    `oldPrimarySnmpIf` - Old primary SNMP interface.
  Throws:
    `java.sql.SQLException` - if an error occurs updating the ipInterface table

### generateSnmpDataCollectionEvents

    private void generateSnmpDataCollectionEvents(DbNodeEntry nodeEntry,
                                                  java.net.InetAddress oldPrimary,
                                                  java.net.InetAddress newPrimary)

  Determines if any SNMP data collection related events need to be generated based upon the results of the current rescan. If necessary will generate one of the following events: 'reinitializePrimarySnmpInterface' 'primarySnmpInterfaceChanged'

  Parameters:
    `nodeEntry` - DbNodeEntry object of the node being rescanned.
    `oldPrimary` - Old primary SNMP interface
    `newPrimary` - New primary SNMP interface

### createAndSendPrimarySnmpInterfaceChangedEvent

    private void createAndSendPrimarySnmpInterfaceChangedEvent(int nodeId,
                                                               java.net.InetAddress newPrimaryIf,
                                                               java.net.InetAddress oldPrimaryIf)

  This method is responsible for generating a primarySnmpInterfaceChanged event and sending it to eventd..

  Parameters:
    `nodeId` - Nodeid of node being rescanned.
    `newPrimaryIf` - new primary SNMP interface address
    `oldPrimaryIf` - old primary SNMP interface address

### createAndSendReinitializePrimarySnmpInterfaceEvent

    private void createAndSendReinitializePrimarySnmpInterfaceEvent(int nodeId,
                                                                    java.net.InetAddress primarySnmpIf)

  This method is responsible for generating a reinitializePrimarySnmpInterface event and sending it to eventd.

  Parameters:
    `nodeId` - Nodeid of node being rescanned.
    `primarySnmpIf` - Primary SNMP interface address.

### sendInterfaceEvents

    private void sendInterfaceEvents(DbNodeEntry node,
                                     boolean useExistingNode,
                                     java.net.InetAddress ifaddr,
                                     IfCollector collector)

  This method is responsible for creating all the necessary interface-level events for the node and sending them to Eventd.

  Parameters:
    `node` - DbNodeEntry object for the parent node.
    `useExistingNode` - TRUE if existing node was used, FALSE if new node was created.
    `ifaddr` - Target interface address
    `collector` - Interface collector containing SNMP and SMB info.

### createAndSendNodeAddedEvent

    private void createAndSendNodeAddedEvent(DbNodeEntry nodeEntry)

  This method is responsible for creating and sending a 'nodeAdded' event to Eventd

  Parameters:
    `nodeEntry` - DbNodeEntry object for the newly created node.

### createAndSendDuplicateIpaddressEvent

    private void createAndSendDuplicateIpaddressEvent(int nodeId,
                                                      java.lang.String ipAddr)

  This method is responsible for creating and sending a 'duplicateIPAddress' event to Eventd

  Parameters:
    `nodeId` - Interface's parent node identifier.
    `ipAddr` - Interface's IP address

### createAndSendNodeGainedInterfaceEvent

    private void createAndSendNodeGainedInterfaceEvent(int nodeId,
                                                       java.net.InetAddress ipAddr)

  This method is responsible for creating and sending a 'nodeGainedInterface' event to Eventd

  Parameters:
    `nodeId` - Interface's parent node identifier.
    `ipAddr` - Interface's IP address

### createAndSendNodeGainedServiceEvent

    private void createAndSendNodeGainedServiceEvent(DbNodeEntry nodeEntry,
                                                     java.net.InetAddress ipAddr,
                                                     java.lang.String svcName,
                                                     java.lang.String qualifier)

  This method is responsible for creating and sending a 'nodeGainedService' event to Eventd

  Parameters:
    `nodeEntry` - Interface's parent node identifier.
    `ipAddr` - Interface's IP address
    `svcName` - Service name
    `qualifier` - Service qualifier (typically the port on which the service was found)

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.