Class SnmpPeerFactory

  • All Implemented Interfaces:
    SnmpAgentConfigFactory
    Direct Known Subclasses:
    ProxySnmpAgentConfigFactory

    public class SnmpPeerFactory
    extends java.lang.Object
    implements SnmpAgentConfigFactory
    This class is the main repository for SNMP configuration information used by the capabilities daemon. When this class is loaded it reads the snmp configuration into memory, and uses the configuration to find the SnmpAgentConfig objects for specific addresses. If an address cannot be located in the configuration then a default peer instance is returned to the caller. 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:
    David Hustace, Weave, Gerald Turner
    • Constructor Detail

      • SnmpPeerFactory

        public SnmpPeerFactory​(org.springframework.core.io.Resource resource)

        Constructor for SnmpPeerFactory.

        Parameters:
        resource - a Resource object.
    • Method Detail

      • getReadLock

        protected java.util.concurrent.locks.Lock getReadLock()
      • getWriteLock

        protected java.util.concurrent.locks.Lock getWriteLock()
      • init

        public static void init()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getInstance

        public static SnmpPeerFactory getInstance()
        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
      • getFile

        public static java.io.File getFile()
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • setFile

        public static void setFile​(java.io.File configFile)

        setFile

        Parameters:
        configFile - a File object.
      • saveCurrent

        public void saveCurrent()
                         throws java.io.IOException
        Saves the current settings to disk
        Throws:
        java.io.IOException - if any.
      • saveToFile

        public void saveToFile​(java.io.File file)
                        throws java.io.UnsupportedEncodingException,
                               java.io.FileNotFoundException,
                               java.io.IOException
        Throws:
        java.io.UnsupportedEncodingException
        java.io.FileNotFoundException
        java.io.IOException
      • getAgentConfig

        public SnmpAgentConfig getAgentConfig​(java.net.InetAddress agentAddress)
      • getAgentConfig

        public SnmpAgentConfig getAgentConfig​(java.net.InetAddress agentInetAddress,
                                              int requestedSnmpVersion)
      • getAgentConfig

        public SnmpAgentConfig getAgentConfig​(java.net.InetAddress agentInetAddress,
                                              java.lang.String location,
                                              int requestedSnmpVersion)
      • getVersionCode

        public int getVersionCode​(Definition def,
                                  SnmpConfig config,
                                  int requestedSnmpVersion)
      • define

        public void define​(SnmpEventInfo info)
        Enhancement: Allows specific or ranges to be merged into SNMP configuration with many other attributes. Uses new classes the wrap JAXB-generated code to help with merging, comparing, and optimizing definitions. Thanks for your initial work on this Gerald. Puts a specific IP address with associated read-community string into the currently loaded snmp-config.xml.
        Parameters:
        info - a SnmpEventInfo object.
      • saveDefinition

        public void saveDefinition​(Definition definition)
        Description copied from interface: SnmpAgentConfigFactory
        Merge this definition into current config.
        Specified by:
        saveDefinition in interface SnmpAgentConfigFactory
        Parameters:
        definition - Definition that has SNMP parameters associated with a specific IP address or Range.
      • removeFromDefinition

        public boolean removeFromDefinition​(java.net.InetAddress inetAddress,
                                            java.lang.String location,
                                            java.lang.String module)
        Description copied from interface: SnmpAgentConfigFactory
        Remove an address from the definitions.
        Specified by:
        removeFromDefinition in interface SnmpAgentConfigFactory
        Parameters:
        inetAddress - IP address that needs to be removed from definition.
        location - location at which this ipaddress belongs.
        module - module from which the definition is getting removed.
      • saveAgentConfigAsDefinition

        public void saveAgentConfigAsDefinition​(SnmpAgentConfig snmpAgentConfig,
                                                java.lang.String location,
                                                java.lang.String module)
        Description copied from interface: SnmpAgentConfigFactory
        Create definition and merge this definition into Current SNMP Config.
        Specified by:
        saveAgentConfigAsDefinition in interface SnmpAgentConfigFactory
        Parameters:
        snmpAgentConfig - agentConfig that might have succeeded in SNMP walk/get.
        location - the location that this agent config belongs.
        module - module from which the definition is getting saved.
      • getSnmpConfigAsString

        public java.lang.String getSnmpConfigAsString()
        Creates a string containing the XML of the current SnmpConfig
        Returns:
        Marshalled SnmpConfig