OpenNMS API 1.2.9

## org.opennms.netmgt.config
Class CollectdConfigFactory

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

public final class CollectdConfigFactory
extends java.lang.Object

This is the singleton class used to load the configuration for the OpenNMS Collection Daemon from the collectd-configuration xml file. A mapping of the configured URLs to the iplist they contain is built at init() time so as to avoid numerous file reads. 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.

Field Summary
`private CollectdConfiguration` `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.lang.String` `m_localServer` Name of the local NMS server.
`private java.util.Map` `m_pkgIpMap` A mapping of the configured package to a list of IPs selected via filter rules, so as to avoid repetetive database access.
`private static CollectdConfigFactory` `m_singleton` The singleton instance of this factory
`private java.util.Map` `m_urlIPMap` A mapping of the configured URLs to a list of the specific IPs configured in each - so as to avoid file reads
`private static boolean` `m_verifyServer` A boolean flag to indicate If a filter rule against the local NMS server has to be used.
`private static java.lang.String` `SELECT_METHOD_MAX`
`private static java.lang.String` `SELECT_METHOD_MIN`

Constructor Summary
`private` `CollectdConfigFactory(java.lang.String configFile)` Private constructor

Method Summary
`java.net.InetAddress` `compareAndSelectPrimaryCollectionInterface(java.lang.String svcName, java.net.InetAddress currentIf, java.net.InetAddress oldPrimary, java.lang.String method, boolean strict)` 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` `createPackageIpListMap()` This method is used to establish package agaist iplist mapping, with which, the iplist is selected per package via the configured filter rules from the database.
`private void` `createUrlIpMap()` Go through the configuration and build a mapping of each configured URL to a list of IPs configured in that URL - done at init() time so that repeated file reads can be avoided
`java.net.InetAddress` `determinePrimarySnmpInterface(java.util.List addressList, boolean strict)` This method is responsbile for determining the node's primary SNMP interface from the specified list of InetAddress objects.
`CollectdConfiguration` `getConfiguration()` Return the collectd configuration object.
`static CollectdConfigFactory` `getInstance()` Return the singleton instance of this factory.
`Package` `getPackage(java.lang.String name)`
`private boolean` `hasExcludeRange(Package pkg, long addr, boolean has_specific)`
`private boolean` `hasIncludeRange(long addr, java.util.Enumeration eincs)`
`private boolean` `hasSpecific(Package pkg, long addr)`
`private boolean` `hasSpecificUrl(java.lang.String iface, Package pkg, boolean has_specific)`
`static void` `init()` Load the config from the default config file and create the singleton instance of this factory.
`private boolean` `interfaceInFilter(java.lang.String iface, Package pkg, org.apache.log4j.Category log)`
`boolean` `interfaceInPackage(java.lang.String iface, Package pkg)` This method is used to determine if the named interface is included in the passed package definition.
`private boolean` `interfaceInUrl(java.lang.String addr, java.lang.String url)` This method is used to determine if the named interface is included in the passed package's url includes.
`boolean` `lookupInterfaceServicePair(java.lang.String ipAddr, java.lang.String svcName)` Returns true if the specified interface is included by at least one package which has the specified service and that service is enabled (set to "on").
`void` `rebuildPackageIpListMap()` This method is used to rebuild the package agaist iplist mapping when needed.
`static void` `reload()` Reload the config from the default config file
`void` `saveCurrent()` Saves the current in-memory configuration to disk and reloads
`boolean` `serviceInPackageAndEnabled(java.lang.String svcName, Package pkg)` Returns true if the service is part of the package and the status of the service is set to "on".

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

Field Detail

### 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_singleton

    private static CollectdConfigFactory m_singleton

  The singleton instance of this factory

### m_loaded

    private static boolean m_loaded

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

### m_config

    private CollectdConfiguration m_config

  The config class loaded from the config file

### m_urlIPMap

    private java.util.Map m_urlIPMap

  A mapping of the configured URLs to a list of the specific IPs configured in each - so as to avoid file reads

### m_pkgIpMap

    private java.util.Map m_pkgIpMap

  A mapping of the configured package to a list of IPs selected via filter rules, so as to avoid repetetive database access.

### m_verifyServer

    private static boolean m_verifyServer

  A boolean flag to indicate If a filter rule against the local NMS server has to be used.

### m_localServer

    private static java.lang.String m_localServer

  Name of the local NMS server.

Constructor Detail

### CollectdConfigFactory

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

  Private constructor

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

### createUrlIpMap

    private void createUrlIpMap()

  Go through the configuration and build a mapping of each configured URL to a list of IPs configured in that URL - done at init() time so that repeated file reads can be avoided

### createPackageIpListMap

    private void createPackageIpListMap()

  This method is used to establish package agaist iplist mapping, with which, the iplist is selected per package via the configured filter rules from the database.

### rebuildPackageIpListMap

    public void rebuildPackageIpListMap()

  This method is used to rebuild the package agaist iplist mapping when needed. When a node gained service event occurs, collectd has to determine which package the ip/service combination is in, but if the interface is a newly added one, the package iplist should be rebuilt so that collectd could know which package this ip/service pair is in.

### 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.

### saveCurrent

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

  Saves the current in-memory configuration to disk and reloads

  Throws:
    `org.exolab.castor.xml.MarshalException`
    `java.io.IOException`
    `org.exolab.castor.xml.ValidationException`

### getInstance

    public static CollectdConfigFactory 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 CollectdConfiguration getConfiguration()

  Return the collectd configuration object.

### getPackage

    public Package getPackage(java.lang.String name)

### interfaceInUrl

    private boolean interfaceInUrl(java.lang.String addr,
                                   java.lang.String url)

  This method is used to determine if the named interface is included in the passed package's url includes. If the interface is found in any of the URL files, then a value of true is returned, else a false value is returned.

       The file URL is read and each entry in this file checked. 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:
    `addr` - The interface to test against the package's URL
    `url` - The url file to read
  Returns:
    True if the interface is included in the url, false otherwise.

### interfaceInPackage

    public boolean interfaceInPackage(java.lang.String iface,
                                      Package pkg)

  This method is used to determine if the named interface is included in the passed package definition. If the interface belongs to the package then a value of true is returned. If the interface does not belong to the package a false value is returned. Note: Evaluation of the interface against a package filter will only work if the IP is already in the database.

  Parameters:
    `iface` - The interface to test against the package.
    `pkg` - The package to check for the inclusion of the interface.
  Returns:
    True if the interface is included in the package, false otherwise.

### serviceInPackageAndEnabled

    public boolean serviceInPackageAndEnabled(java.lang.String svcName,
                                              Package pkg)

  Returns true if the service is part of the package and the status of the service is set to "on". Returns false if the service is not in the package or it is but the status of the service is set to "off".

  Parameters:
    `svcName` - The service name to lookup.
    `pkg` - The package to lookup up service.

### lookupInterfaceServicePair

    public boolean lookupInterfaceServicePair(java.lang.String ipAddr,
                                              java.lang.String svcName)

  Returns true if the specified interface is included by at least one package which has the specified service and that service is enabled (set to "on").

  Parameters:
    `ipAddr` - IP address of the interface to lookup
    `svcName` - The service name to lookup
  Returns:
    true if Collectd config contains a package which includes the specified interface and has the specified service enabled.

### determinePrimarySnmpInterface

    public java.net.InetAddress determinePrimarySnmpInterface(java.util.List addressList,
                                                              boolean strict)

  This method is responsbile for determining the node's primary SNMP interface from the specified list of InetAddress objects.

  Parameters:
    `addressList` - List of InetAddress objects representing all the interfaces belonging to a particular node which support the "SNMP" service and have a valid ifIndex.
    `strict` - Boolean variable which requires an interface to be part of a Collectd package to be eligible as a primary SNMP interface
  Returns:
    InetAddress object of the primary SNMP interface or null if none of the node's interfaces are eligible.

### compareAndSelectPrimaryCollectionInterface

    public java.net.InetAddress compareAndSelectPrimaryCollectionInterface(java.lang.String svcName,
                                                                           java.net.InetAddress currentIf,
                                                                           java.net.InetAddress oldPrimary,
                                                                           java.lang.String method,
                                                                           boolean strict)

  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, if strict is true, it must be included by a Collectd package which supports the specified service. This method will return null if the 'oldPrimary' address is null and the 'currentIf' address does not pass the Collectd package check, if strict is true..

  Parameters:
    `svcName` - Service name
    `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")
    `strict` - require interface to be part of a Collectd package
  Returns:
    InetAddress object of the primary interface based on the provided method or null if neither address is eligible to be primary.

### hasExcludeRange

    private boolean hasExcludeRange(Package pkg,
                                    long addr,
                                    boolean has_specific)

### hasSpecificUrl

    private boolean hasSpecificUrl(java.lang.String iface,
                                   Package pkg,
                                   boolean has_specific)

### hasSpecific

    private boolean hasSpecific(Package pkg,
                                long addr)

### hasIncludeRange

    private boolean hasIncludeRange(long addr,
                                    java.util.Enumeration eincs)

### interfaceInFilter

    private boolean interfaceInFilter(java.lang.String iface,
                                      Package pkg,
                                      org.apache.log4j.Category log)

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.