Package org.opennms.netmgt.config
Class SnmpPeerFactory
- java.lang.Object
-
- org.opennms.netmgt.config.SnmpPeerFactory
-
- All Implemented Interfaces:
SnmpAgentConfigFactory
- Direct Known Subclasses:
ProxySnmpAgentConfigFactory
public class SnmpPeerFactory extends 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 theSnmpAgentConfig
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 Summary
Constructors Constructor Description SnmpPeerFactory(org.springframework.core.io.Resource resource)
Constructor for SnmpPeerFactory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
define(SnmpEventInfo info)
Enhancement: Allows specific or ranges to be merged into SNMP configuration with many other attributes.SnmpAgentConfig
getAgentConfig(InetAddress agentAddress)
SnmpAgentConfig
getAgentConfig(InetAddress agentInetAddress, int requestedSnmpVersion)
SnmpAgentConfig
getAgentConfig(InetAddress agentAddress, String location)
getAgentConfigSnmpAgentConfig
getAgentConfig(InetAddress agentInetAddress, String location, int requestedSnmpVersion)
SnmpAgentConfig
getAgentConfigFromProfile(SnmpProfile snmpProfile, InetAddress address)
getAgentConfig for a given profilestatic File
getFile()
static SnmpPeerFactory
getInstance()
Load the config from the default config file and create the singleton instance of this factory.List<SnmpProfile>
getProfiles()
Get all the SNMP profiles from SNMP Config.protected Lock
getReadLock()
SnmpConfig
getSnmpConfig()
getSnmpConfigString
getSnmpConfigAsString()
Creates a string containing the XML of the current SnmpConfigint
getVersionCode(Definition def, SnmpConfig config, int requestedSnmpVersion)
protected Lock
getWriteLock()
static void
init()
boolean
removeFromDefinition(InetAddress inetAddress, String location, String module)
Remove an address from the definitions.void
saveAgentConfigAsDefinition(SnmpAgentConfig snmpAgentConfig, String location, String module)
Create definition and merge this definition into Current SNMP Config.void
saveCurrent()
Saves the current settings to diskvoid
saveDefinition(Definition definition)
Merge this definition into current config.void
saveToFile(File file)
static void
setFile(File configFile)
setFilestatic void
setInstance(SnmpPeerFactory singleton)
setInstance
-
-
-
Method Detail
-
getReadLock
protected Lock getReadLock()
-
getWriteLock
protected Lock getWriteLock()
-
init
public static void init() throws IOException
- Throws:
IOException
-
getInstance
public static SnmpPeerFactory getInstance()
Load the config from the default config file and create the singleton instance of this factory.- Throws:
IOException
- Thrown if the specified config file cannot be read
-
setInstance
public static void setInstance(SnmpPeerFactory singleton)
setInstance
- Parameters:
singleton
- aSnmpPeerFactory
object.
-
getFile
public static File getFile() throws IOException
- Throws:
IOException
-
setFile
public static void setFile(File configFile)
setFile
- Parameters:
configFile
- aFile
object.
-
saveCurrent
public void saveCurrent() throws IOException
Saves the current settings to disk- Throws:
IOException
- if any.
-
saveToFile
public void saveToFile(File file) throws UnsupportedEncodingException, FileNotFoundException, IOException
-
getAgentConfig
public SnmpAgentConfig getAgentConfig(InetAddress agentAddress)
-
getAgentConfig
public SnmpAgentConfig getAgentConfig(InetAddress agentAddress, String location)
Description copied from interface:SnmpAgentConfigFactory
getAgentConfig
- Specified by:
getAgentConfig
in interfaceSnmpAgentConfigFactory
- Parameters:
agentAddress
- aInetAddress
object.location
- aString
object.- Returns:
- a
SnmpAgentConfig
object.
-
getAgentConfigFromProfile
public SnmpAgentConfig getAgentConfigFromProfile(SnmpProfile snmpProfile, InetAddress address)
Description copied from interface:SnmpAgentConfigFactory
getAgentConfig for a given profile
- Specified by:
getAgentConfigFromProfile
in interfaceSnmpAgentConfigFactory
- Parameters:
snmpProfile
- a @Definition
object.address
- aInetAddress
object.- Returns:
- a
SnmpAgentConfig
object.
-
getAgentConfig
public SnmpAgentConfig getAgentConfig(InetAddress agentInetAddress, int requestedSnmpVersion)
-
getAgentConfig
public SnmpAgentConfig getAgentConfig(InetAddress agentInetAddress, String location, int requestedSnmpVersion)
-
getVersionCode
public int getVersionCode(Definition def, SnmpConfig config, int requestedSnmpVersion)
-
getSnmpConfig
public SnmpConfig getSnmpConfig()
getSnmpConfig
- Returns:
- a
SnmpConfig
object.
-
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
- aSnmpEventInfo
object.
-
saveDefinition
public void saveDefinition(Definition definition)
Description copied from interface:SnmpAgentConfigFactory
Merge this definition into current config.- Specified by:
saveDefinition
in interfaceSnmpAgentConfigFactory
- Parameters:
definition
- Definition that has SNMP parameters associated with a specific IP address or Range.
-
removeFromDefinition
public boolean removeFromDefinition(InetAddress inetAddress, String location, String module)
Description copied from interface:SnmpAgentConfigFactory
Remove an address from the definitions.- Specified by:
removeFromDefinition
in interfaceSnmpAgentConfigFactory
- 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, String location, String module)
Description copied from interface:SnmpAgentConfigFactory
Create definition and merge this definition into Current SNMP Config.- Specified by:
saveAgentConfigAsDefinition
in interfaceSnmpAgentConfigFactory
- 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.
-
getProfiles
public List<SnmpProfile> getProfiles()
Description copied from interface:SnmpAgentConfigFactory
Get all the SNMP profiles from SNMP Config.- Specified by:
getProfiles
in interfaceSnmpAgentConfigFactory
- Returns:
- a List of snmp profiles.
-
getSnmpConfigAsString
public String getSnmpConfigAsString()
Creates a string containing the XML of the current SnmpConfig- Returns:
- Marshalled SnmpConfig
-
-