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 theSnmpAgentConfigobjects 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 voiddefine(SnmpEventInfo info)Enhancement: Allows specific or ranges to be merged into SNMP configuration with many other attributes.SnmpAgentConfiggetAgentConfig(InetAddress agentAddress)SnmpAgentConfiggetAgentConfig(InetAddress agentInetAddress, int requestedSnmpVersion)SnmpAgentConfiggetAgentConfig(InetAddress agentAddress, String location)getAgentConfigSnmpAgentConfiggetAgentConfig(InetAddress agentInetAddress, String location, int requestedSnmpVersion)SnmpAgentConfiggetAgentConfigFromProfile(SnmpProfile snmpProfile, InetAddress address)getAgentConfig for a given profilestatic FilegetFile()static SnmpPeerFactorygetInstance()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 LockgetReadLock()SnmpConfiggetSnmpConfig()getSnmpConfigStringgetSnmpConfigAsString()Creates a string containing the XML of the current SnmpConfigintgetVersionCode(Definition def, SnmpConfig config, int requestedSnmpVersion)protected LockgetWriteLock()static voidinit()booleanremoveFromDefinition(InetAddress inetAddress, String location, String module)Remove an address from the definitions.voidsaveAgentConfigAsDefinition(SnmpAgentConfig snmpAgentConfig, String location, String module)Create definition and merge this definition into Current SNMP Config.voidsaveCurrent()Saves the current settings to diskvoidsaveDefinition(Definition definition)Merge this definition into current config.voidsaveToFile(File file)static voidsetFile(File configFile)setFilestatic voidsetInstance(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- aSnmpPeerFactoryobject.
-
getFile
public static File getFile() throws IOException
- Throws:
IOException
-
setFile
public static void setFile(File configFile)
setFile
- Parameters:
configFile- aFileobject.
-
saveCurrent
public void saveCurrent() throws IOExceptionSaves 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:SnmpAgentConfigFactorygetAgentConfig
- Specified by:
getAgentConfigin interfaceSnmpAgentConfigFactory- Parameters:
agentAddress- aInetAddressobject.location- aStringobject.- Returns:
- a
SnmpAgentConfigobject.
-
getAgentConfigFromProfile
public SnmpAgentConfig getAgentConfigFromProfile(SnmpProfile snmpProfile, InetAddress address)
Description copied from interface:SnmpAgentConfigFactorygetAgentConfig for a given profile
- Specified by:
getAgentConfigFromProfilein interfaceSnmpAgentConfigFactory- Parameters:
snmpProfile- a @Definitionobject.address- aInetAddressobject.- Returns:
- a
SnmpAgentConfigobject.
-
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
SnmpConfigobject.
-
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- aSnmpEventInfoobject.
-
saveDefinition
public void saveDefinition(Definition definition)
Description copied from interface:SnmpAgentConfigFactoryMerge this definition into current config.- Specified by:
saveDefinitionin 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:SnmpAgentConfigFactoryRemove an address from the definitions.- Specified by:
removeFromDefinitionin 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:SnmpAgentConfigFactoryCreate definition and merge this definition into Current SNMP Config.- Specified by:
saveAgentConfigAsDefinitionin 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:SnmpAgentConfigFactoryGet all the SNMP profiles from SNMP Config.- Specified by:
getProfilesin interfaceSnmpAgentConfigFactory- Returns:
- a List of snmp profiles.
-
getSnmpConfigAsString
public String getSnmpConfigAsString()
Creates a string containing the XML of the current SnmpConfig- Returns:
- Marshalled SnmpConfig
-
-