OpenNMS API 1.2.9

## org.opennms.netmgt.config
Class CapsdConfigFactory

    java.lang.Object
      org.opennms.netmgt.config.CapsdConfigFactory

public final class CapsdConfigFactory
extends java.lang.Object

This is the singleton class used to load the configuration for the OpenNMS Capsd service from the capsd-configuration xml file. Note: Users of this class should make sure the init() is called before calling any other method to ensure the config is loaded before accessing other convenience methods.

Author:
  Mike Davidson , OpenNMS

Nested Class Summary
`private static class` `CapsdConfigFactory.LightWeightIfEntry` LightWeightIfEntry is designed to hold specific information about an IP interface in the database such as its IP address, its parent node id, and its managed status and represents a lighter weight version of the DbIpInterfaceEntry class.
`static class` `CapsdConfigFactory.ProtocolInfo` This class is used to encapsulate the basic protocol information read from the config file.

Field Summary
`static java.lang.Integer` `AUTO_SET` This integer value is used to represent the state when the protocol should be automatically set, with any status checks.
`private static char` `COMMENT_CHAR` This character at the start of a line indicates a comment line in a URL file
`private static java.lang.String` `COMMENT_STR` The string indicating the start of the comments in a line containing the IP address in a file URL
`private static java.lang.String` `DELETE_IFSERVICES_SQL` The SQL statement used to mark all ifservices table entries which refer to the specified serviceId as deleted.
`private static java.lang.String` `DELETE_OUTAGES_SQL` The SQL statement used to delete all entries from the outage table which refer to the specified serviceId
`static int` `LAME_SNMP_HOST_IFINDEX` This integer value is used to represent the primary snmp interface ifindex in the ipinterface table for SNMP hosts that don't support the MIB2 ipAddrTable
`private CapsdConfiguration` `m_config` The config class loaded from the config file
`private static boolean` `m_loaded` This member is set to true if the configuration file has been loaded.
`private static java.util.Map` `m_plugins` The map of capsd plugins.
`private static java.util.Map` `m_serviceIds` The map of service identifiers, mapped by the service id and name.
`private static CapsdConfigFactory` `m_singleton` The singleton instance of this factory
`private java.util.Map` `m_urlMap` Maps url names to a list of addresses specified by the url.
`private static java.lang.String` `NEXT_SVC_ID_SQL` The SQL statement used to get the next value for a service identifier.
`private static java.lang.String` `RETRIEVE_IPADDR_NODEID_SQL` The SQL statement used to determine if an IP address is already in the ipInterface table and if so what its parent nodeid is.
`private static java.lang.String` `RETRIEVE_IPADDR_SQL` The SQL statement used to determine if an IP address is already in the ipInterface table and there is known.
`static java.lang.Integer` `SCAN` The integer value that is used to represent the protocol scan configuration.
`static java.lang.Integer` `SKIP` This integer value is used to represent that the protocol plugin should not be used to scan the interface.
`(package private) static java.lang.String` `SQL_DB_RETRIEVE_IF_SERVICES` The SQL statement used to retrieve all non-deleted/non-forced unamanaged services for a nodeid/ip from the 'ifservices' table.
`(package private) static java.lang.String` `SQL_DB_RETRIEVE_IP_INTERFACE` The SQL statement used to retrieve all non-deleted/non-forced unamanaged IP interfaces from the 'ipInterface' table.
`(package private) static java.lang.String` `SQL_DB_RETRIEVE_IP_INTERFACE_IN_LOCAL_SERVER` The SQL statement used to retrieve all non-deleted/non-forced unamanaged IP interfaces from the 'ipInterface' table with the local OpenNMS server restriction.
`private static java.lang.String` `SQL_DB_RETRIEVE_SNMP_IP_INTERFACES` SQL statement to retrieve all non-deleted IP addresses from the ipInterface table which support SNMP.
`(package private) static java.lang.String` `SQL_DB_UPDATE_ALL_SERVICES_FOR_NIP` The SQL statement which updates the 'status' field in the ifServices table for a specific node/ipAddr pair
`(package private) static java.lang.String` `SQL_DB_UPDATE_IP_INTERFACE` The SQL statement which updates the 'isManaged' field in the ipInterface table for a specific node/ipAddr pair
`(package private) static java.lang.String` `SQL_DB_UPDATE_SERVICE_FOR_NIP`
`private static java.lang.String` `SQL_DB_UPDATE_SNMP_PRIMARY_STATE` SQL statement used to update the 'isSnmpPrimary' field of the ipInterface table.
`private static java.lang.String` `SVCTBL_ADD_SQL` The SQL statement used to add a new entry into the service table
`private static java.lang.String` `SVCTBL_LOAD_SQL` The SQL statement used to load the currenly defined service table.

Constructor Summary
`private` `CapsdConfigFactory(java.lang.String configFile)` Constructs a new CapsdConfigFactory object for access to the Capsd configuration information.

Method Summary
`boolean` `getAbortProtocolScansFlag()` Defines Capsd's behavior when, during a protocol scan, it gets a java.net.NoRouteToHostException exception.
`private java.util.List` `getAddressesFromURL(java.lang.String url)` The file URL is read and a 'specific IP' is added for each entry in this file.
`CapsdConfiguration` `getConfiguration()` Return the Capsd configuration object.
`boolean` `getDeletePropagationEnabled()`
`long` `getInitialSleepTime()`
`static CapsdConfigFactory` `getInstance()` Return the singleton instance of this factory.
`int` `getInterfaceDbNodeId(java.sql.Connection dbConn, java.net.InetAddress ifAddress, int ifIndex)`
`int` `getMaxRescanThreadPoolSize()`
`int` `getMaxSuspectThreadPoolSize()`
`CapsdConfigFactory.ProtocolInfo[]` `getProtocolSpecification(java.net.InetAddress address)` Returns the list of protocol plugins and the associated actions for the named address.
`long` `getRescanFrequency()`
`java.lang.Object` `getServiceIdentifier(java.lang.Object key)` Returns the protocol identifier from the service table that was loaded during class initialization.
`SmbAuth` `getSmbAuth(java.lang.String target)` Finds the SMB authentication object using the netbios name.
`java.lang.String` `getXmlrpc()` Return the boolean xmlrpc as string to indicate if notification to external xmlrpc server is needed.
`static void` `init()` Load the config from the default config file and create the singleton instance of this factory.
`boolean` `isAddressUnmanaged(java.net.InetAddress target)` Checks the configuration to determine if the target is managed or unmanaged.
`boolean` `isInterfaceInDB(java.sql.Connection dbConn, java.net.InetAddress ifAddress)`
`static void` `reload()` Reload the config from the default config file
`void` `syncManagementState(java.sql.Connection conn)` Responsible for syncing up the 'isManaged' field of the ipInterface table and the 'status' field of the ifServices table based on the capsd and poller configurations.
`void` `syncServices(java.sql.Connection conn)` This method is responsible for sync'ing the content of the 'service' table with the protocols listed in the caspd-configuration.xml file.
`void` `syncSnmpPrimaryState(java.sql.Connection conn)` Responsible for syncing up the 'isPrimarySnmp' field of the ipInterface table based on the capsd and collectd configurations.
`private static long` `toLong(java.net.InetAddress addr)` Deprecated. Use org.opennms.netmgt.utils.IPSorter.convertToLong() instead.

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

Field Detail

### COMMENT_STR

    private static final java.lang.String COMMENT_STR

  The string indicating the start of the comments in a line containing the IP address in a file URL

  See Also:
    Constant Field Values

### COMMENT_CHAR

    private static final char COMMENT_CHAR

  This character at the start of a line indicates a comment line in a URL file

  See Also:
    Constant Field Values

### m_loaded

    private static boolean m_loaded

  This member is set to true if the configuration file has been loaded.

### m_singleton

    private static CapsdConfigFactory m_singleton

  The singleton instance of this factory

### m_config

    private CapsdConfiguration m_config

  The config class loaded from the config file

### m_urlMap

    private java.util.Map m_urlMap

  Maps url names to a list of addresses specified by the url. Initialized at factory construction.

### SQL_DB_RETRIEVE_IP_INTERFACE

    static final java.lang.String SQL_DB_RETRIEVE_IP_INTERFACE

  The SQL statement used to retrieve all non-deleted/non-forced unamanaged IP interfaces from the 'ipInterface' table.

  See Also:
    Constant Field Values

### SQL_DB_RETRIEVE_IP_INTERFACE_IN_LOCAL_SERVER

    static final java.lang.String SQL_DB_RETRIEVE_IP_INTERFACE_IN_LOCAL_SERVER

  The SQL statement used to retrieve all non-deleted/non-forced unamanaged IP interfaces from the 'ipInterface' table with the local OpenNMS server restriction.

  See Also:
    Constant Field Values

### SQL_DB_RETRIEVE_SNMP_IP_INTERFACES

    private static java.lang.String SQL_DB_RETRIEVE_SNMP_IP_INTERFACES

  SQL statement to retrieve all non-deleted IP addresses from the ipInterface table which support SNMP.

### SQL_DB_UPDATE_SNMP_PRIMARY_STATE

    private static java.lang.String SQL_DB_UPDATE_SNMP_PRIMARY_STATE

  SQL statement used to update the 'isSnmpPrimary' field of the ipInterface table.

### SQL_DB_RETRIEVE_IF_SERVICES

    static final java.lang.String SQL_DB_RETRIEVE_IF_SERVICES

  The SQL statement used to retrieve all non-deleted/non-forced unamanaged services for a nodeid/ip from the 'ifservices' table.

  See Also:
    Constant Field Values

### SQL_DB_UPDATE_IP_INTERFACE

    static final java.lang.String SQL_DB_UPDATE_IP_INTERFACE

  The SQL statement which updates the 'isManaged' field in the ipInterface table for a specific node/ipAddr pair

  See Also:
    Constant Field Values

### SQL_DB_UPDATE_ALL_SERVICES_FOR_NIP

    static final java.lang.String SQL_DB_UPDATE_ALL_SERVICES_FOR_NIP

  The SQL statement which updates the 'status' field in the ifServices table for a specific node/ipAddr pair

  See Also:
    Constant Field Values

### SQL_DB_UPDATE_SERVICE_FOR_NIP

    static final java.lang.String SQL_DB_UPDATE_SERVICE_FOR_NIP

See Also:
  Constant Field Values

### RETRIEVE_IPADDR_SQL

    private static final java.lang.String RETRIEVE_IPADDR_SQL

  The SQL statement used to determine if an IP address is already in the ipInterface table and there is known.

  See Also:
    Constant Field Values

### RETRIEVE_IPADDR_NODEID_SQL

    private static final java.lang.String RETRIEVE_IPADDR_NODEID_SQL

  The SQL statement used to determine if an IP address is already in the ipInterface table and if so what its parent nodeid is.

  See Also:
    Constant Field Values

### SVCTBL_LOAD_SQL

    private static final java.lang.String SVCTBL_LOAD_SQL

  The SQL statement used to load the currenly defined service table.

  See Also:
    Constant Field Values

### SVCTBL_ADD_SQL

    private static final java.lang.String SVCTBL_ADD_SQL

  The SQL statement used to add a new entry into the service table

  See Also:
    Constant Field Values

### NEXT_SVC_ID_SQL

    private static final java.lang.String NEXT_SVC_ID_SQL

  The SQL statement used to get the next value for a service identifier. This is a sequence defined in the database.

  See Also:
    Constant Field Values

### DELETE_OUTAGES_SQL

    private static final java.lang.String DELETE_OUTAGES_SQL

  The SQL statement used to delete all entries from the outage table which refer to the specified serviceId

  See Also:
    Constant Field Values

### DELETE_IFSERVICES_SQL

    private static final java.lang.String DELETE_IFSERVICES_SQL

  The SQL statement used to mark all ifservices table entries which refer to the specified serviceId as deleted.

  See Also:
    Constant Field Values

### m_serviceIds

    private static final java.util.Map m_serviceIds

  The map of service identifiers, mapped by the service id and name. The identifier keys are integers and the names are string. The integers map to strings and the strings map to integers.

### m_plugins

    private static final java.util.Map m_plugins

  The map of capsd plugins. The plugins are indexed by both their class name and the protocols that they support.

### SCAN

    public static final java.lang.Integer SCAN

  The integer value that is used to represent the protocol scan configuration. If this value is used the the plugin should be used to scan the address.

### SKIP

    public static final java.lang.Integer SKIP

  This integer value is used to represent that the protocol plugin should not be used to scan the interface.

### AUTO_SET

    public static final java.lang.Integer AUTO_SET

  This integer value is used to represent the state when the protocol should be automatically set, with any status checks.

### LAME_SNMP_HOST_IFINDEX

    public static final int LAME_SNMP_HOST_IFINDEX

  This integer value is used to represent the primary snmp interface ifindex in the ipinterface table for SNMP hosts that don't support the MIB2 ipAddrTable

  See Also:
    Constant Field Values

Constructor Detail

### CapsdConfigFactory

    private CapsdConfigFactory(java.lang.String configFile)
                        throws java.io.IOException,
                               org.exolab.castor.xml.MarshalException,
                               org.exolab.castor.xml.ValidationException

  Constructs a new CapsdConfigFactory object for access to the Capsd configuration information. In addition to loading the configuration from the capsd-configuration.xml file the constructor also inserts any plugins defined in the configuration but not in the database into the 'service' table.

Parameters:
  `configFile` - The configuration file to load.
Throws:
  `java.io.IOException` - Thrown if the specified config file cannot be read
  `org.exolab.castor.xml.MarshalException` - Thrown if the file does not conform to the schema.
  `org.exolab.castor.xml.ValidationException` - Thrown if the contents do not match the required schema.

Method Detail

### init

    public static void init()
                     throws java.io.IOException,
                            org.exolab.castor.xml.MarshalException,
                            org.exolab.castor.xml.ValidationException

  Load the config from the default config file and create the singleton instance of this factory.

  Throws:
    `java.io.IOException` - Thrown if the specified config file cannot be read
    `org.exolab.castor.xml.MarshalException` - Thrown if the file does not conform to the schema.
    `org.exolab.castor.xml.ValidationException` - Thrown if the contents do not match the required schema.

### reload

    public static void reload()
                       throws java.io.IOException,
                              org.exolab.castor.xml.MarshalException,
                              org.exolab.castor.xml.ValidationException

  Reload the config from the default config file

  Throws:
    `java.io.IOException` - Thrown if the specified config file cannot be read/loaded
    `org.exolab.castor.xml.MarshalException` - Thrown if the file does not conform to the schema.
    `org.exolab.castor.xml.ValidationException` - Thrown if the contents do not match the required schema.

### getInstance

    public static CapsdConfigFactory getInstance()

  Return the singleton instance of this factory.

  Returns:
    The current factory instance.
  Throws:
    `java.lang.IllegalStateException` - Thrown if the factory has not yet been initialized.

### getConfiguration

    public CapsdConfiguration getConfiguration()

  Return the Capsd configuration object.

### syncServices

    public void syncServices(java.sql.Connection conn)
                      throws java.sql.SQLException

  This method is responsible for sync'ing the content of the 'service' table with the protocols listed in the caspd-configuration.xml file. First a list of services currently contained in the 'service' table in the database is built. Next, the list of services defined in capsd-configuration.xml is iterated over and if any services are defined but do not yet exist in the 'service' table they are added to the table. Finally, the list of services in the database is iterated over and if any service exists in the database but is no longer listed in the capsd-configuration.xml file then that the following occurs: 1. All 'outage' table entries which refer to the service are deleted. 2. All 'ifServices' table entries which refer to the service are deleted. Note that the 'service' table entry will remain in the database since events most likely exist which refer to the service.

  Throws:
    `java.sql.SQLException`

### syncManagementState

    public void syncManagementState(java.sql.Connection conn)
                             throws java.sql.SQLException

  Responsible for syncing up the 'isManaged' field of the ipInterface table and the 'status' field of the ifServices table based on the capsd and poller configurations. Note that the 'sync' only takes place for interfaces and services that are not deleted or force unmanaged.

       Here is how the statuses are set:
        If an interface is 'unmanaged' based on the capsd configuration,
            ipManaged='U' and status='U'

        If an interface is 'managed' based on the capsd configuration,
          1. If the interface is not in any pacakge, ipManaged='N' and status ='N'
          2. If the interface in atleast one package but the service is not polled by
             by any of the packages, ipManaged='M' and status='N'
          3. If the interface in atleast one package and the service is polled by a
             package that this interface belongs to, ipManaged='M' and status'=A'

  Parameters:
    `conn` - Connection to the database.
  Throws:
    `java.sql.SQLException` - Thrown if an error occurs while syncing the database.

### syncSnmpPrimaryState

    public void syncSnmpPrimaryState(java.sql.Connection conn)
                              throws java.sql.SQLException

  Responsible for syncing up the 'isPrimarySnmp' field of the ipInterface table based on the capsd and collectd configurations. Note that the 'sync' only takes place for interfaces that are not deleted. Also, it will prefer a loopback interface over other interfaces.

  Parameters:
    `conn` - Connection to the database.
  Throws:
    `java.sql.SQLException` - Thrown if an error occurs while syncing the database.

### toLong

    private static long toLong(java.net.InetAddress addr)

  Deprecated. Use org.opennms.netmgt.utils.IPSorter.convertToLong() instead.

  This method is used to convert the passed IP address to a `long` value. The address is converted in network byte order (big endin). This is compatable with the number format of the JVM, and thus the return longs can be compared with other converted IP Addresses to determine inclusion.

  Parameters:
    `addr` - The IP address to convert.
  Returns:
    The converted IP address.

### getProtocolSpecification

    public CapsdConfigFactory.ProtocolInfo[] getProtocolSpecification(java.net.InetAddress address)

  Returns the list of protocol plugins and the associated actions for the named address. The currently loaded configuration is used to find, build, and return the protocol information. The returns information has all the necessary element to check the address for capabilities.

  Parameters:
    `address` - The address to get protocol information for.
  Returns:
    The array of protocol information instances for the address.

### getServiceIdentifier

    public java.lang.Object getServiceIdentifier(java.lang.Object key)

  Returns the protocol identifier from the service table that was loaded during class initialization. The identifier is used determines the result. If a String is passed then the integer value is returned. If an interger value is passed then the string protocol name is returned.

  Parameters:
    `key` - The value used to lookup the result in in the preloaded map.
  Returns:
    The result of the lookup, either a String or an Integer.

### getSmbAuth

    public SmbAuth getSmbAuth(java.lang.String target)

  Finds the SMB authentication object using the netbios name. The target of the search.

### isAddressUnmanaged

    public boolean isAddressUnmanaged(java.net.InetAddress target)

  Checks the configuration to determine if the target is managed or unmanaged.

  Parameters:
    `target` - The target to check against.

### getAddressesFromURL

    private java.util.List getAddressesFromURL(java.lang.String url)

  The file URL is read and a 'specific IP' is added for each entry in this file. Each line in the URL file can be one of -<IP><space># <comments> or <IP>or #<comments> Lines starting with a '#' are ignored and so are characters after a ' <space>#' in a line.

  Parameters:
    `url` - the URL file
  Returns:
    List of addresses retrieved from the URL

### isInterfaceInDB

    public boolean isInterfaceInDB(java.sql.Connection dbConn,
                                   java.net.InetAddress ifAddress)
                            throws java.sql.SQLException

  Throws:
    `java.sql.SQLException`

### getInterfaceDbNodeId

    public int getInterfaceDbNodeId(java.sql.Connection dbConn,
                                    java.net.InetAddress ifAddress,
                                    int ifIndex)
                             throws java.sql.SQLException

  Throws:
    `java.sql.SQLException`

### getRescanFrequency

    public long getRescanFrequency()

### getInitialSleepTime

    public long getInitialSleepTime()

### getMaxSuspectThreadPoolSize

    public int getMaxSuspectThreadPoolSize()

### getMaxRescanThreadPoolSize

    public int getMaxRescanThreadPoolSize()

### getAbortProtocolScansFlag

    public boolean getAbortProtocolScansFlag()

  Defines Capsd's behavior when, during a protocol scan, it gets a java.net.NoRouteToHostException exception. If abort rescan property is set to "true" then Capsd will not perform any additional protocol scans.

### getDeletePropagationEnabled

    public boolean getDeletePropagationEnabled()

### getXmlrpc

    public java.lang.String getXmlrpc()

  Return the boolean xmlrpc as string to indicate if notification to external xmlrpc server is needed.

  Returns:
    boolean flag as a string value

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.