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 SummaryConstructors Constructor Description SnmpPeerFactory(org.springframework.core.io.Resource resource)Constructor for SnmpPeerFactory.
 - 
Method SummaryAll 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- 
getReadLockprotected Lock getReadLock() 
 - 
getWriteLockprotected Lock getWriteLock() 
 - 
initpublic static void init() throws IOException- Throws:
- IOException
 
 - 
getInstancepublic 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
 
 - 
setInstancepublic static void setInstance(SnmpPeerFactory singleton) setInstance - Parameters:
- singleton- a- SnmpPeerFactoryobject.
 
 - 
getFilepublic static File getFile() throws IOException - Throws:
- IOException
 
 - 
setFilepublic static void setFile(File configFile) setFile - Parameters:
- configFile- a- Fileobject.
 
 - 
saveCurrentpublic void saveCurrent() throws IOExceptionSaves the current settings to disk- Throws:
- IOException- if any.
 
 - 
saveToFilepublic void saveToFile(File file) throws UnsupportedEncodingException, FileNotFoundException, IOException 
 - 
getAgentConfigpublic SnmpAgentConfig getAgentConfig(InetAddress agentAddress) 
 - 
getAgentConfigpublic SnmpAgentConfig getAgentConfig(InetAddress agentAddress, String location) Description copied from interface:SnmpAgentConfigFactorygetAgentConfig - Specified by:
- getAgentConfigin interface- SnmpAgentConfigFactory
- Parameters:
- agentAddress- a- InetAddressobject.
- location- a- Stringobject.
- Returns:
- a SnmpAgentConfigobject.
 
 - 
getAgentConfigFromProfilepublic SnmpAgentConfig getAgentConfigFromProfile(SnmpProfile snmpProfile, InetAddress address) Description copied from interface:SnmpAgentConfigFactorygetAgentConfig for a given profile - Specified by:
- getAgentConfigFromProfilein interface- SnmpAgentConfigFactory
- Parameters:
- snmpProfile- a @- Definitionobject.
- address- a- InetAddressobject.
- Returns:
- a SnmpAgentConfigobject.
 
 - 
getAgentConfigpublic SnmpAgentConfig getAgentConfig(InetAddress agentInetAddress, int requestedSnmpVersion) 
 - 
getAgentConfigpublic SnmpAgentConfig getAgentConfig(InetAddress agentInetAddress, String location, int requestedSnmpVersion) 
 - 
getVersionCodepublic int getVersionCode(Definition def, SnmpConfig config, int requestedSnmpVersion) 
 - 
getSnmpConfigpublic SnmpConfig getSnmpConfig() getSnmpConfig - Returns:
- a SnmpConfigobject.
 
 - 
definepublic 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- SnmpEventInfoobject.
 
 - 
saveDefinitionpublic void saveDefinition(Definition definition) Description copied from interface:SnmpAgentConfigFactoryMerge this definition into current config.- Specified by:
- saveDefinitionin interface- SnmpAgentConfigFactory
- Parameters:
- definition- Definition that has SNMP parameters associated with a specific IP address or Range.
 
 - 
removeFromDefinitionpublic boolean removeFromDefinition(InetAddress inetAddress, String location, String module) Description copied from interface:SnmpAgentConfigFactoryRemove an address from the definitions.- Specified by:
- removeFromDefinitionin 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.
 
 - 
saveAgentConfigAsDefinitionpublic 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 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.
 
 - 
getProfilespublic List<SnmpProfile> getProfiles() Description copied from interface:SnmpAgentConfigFactoryGet all the SNMP profiles from SNMP Config.- Specified by:
- getProfilesin interface- SnmpAgentConfigFactory
- Returns:
- a List of snmp profiles.
 
 - 
getSnmpConfigAsStringpublic String getSnmpConfigAsString() Creates a string containing the XML of the current SnmpConfig- Returns:
- Marshalled SnmpConfig
 
 
- 
 
-