Package org.snmp4j.agent.db.sample
Class SampleAgent
java.lang.Object
org.snmp4j.agent.db.sample.SampleAgent
- All Implemented Interfaces:
org.snmp4j.agent.AgentStateListener<org.snmp4j.agent.AgentConfigManager>
public class SampleAgent
extends Object
implements org.snmp4j.agent.AgentStateListener<org.snmp4j.agent.AgentConfigManager>
The SampleAgent uses an
AgentConfigManager
instance to create a
minimal SNMP agent using the configuration defined by
SampleAgentConfig.properties
in this package. That properties
file defines the initial content of the registered MIB objects of this agent
which may differ from the hard coded defaults.
This SampleAgent
uses the MOXodusPersistenceProvider
to persistently
store ManagedObject
s. It assumes that all managed objects that are non-volatile
are implementing the RandomAccessManagedObject
interfaces.
The agent uses the console logging to log messages.
- Since:
- 3.0
- Version:
- 3.0
- Author:
- Frank Fock
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.snmp4j.agent.AgentConfigManager
static final String
static final String
protected org.snmp4j.agent.MOServer
protected Properties
-
Constructor Summary
ModifierConstructorDescriptionSampleAgent
(Map<String, List<Object>> args) protected
SampleAgent
(Map<String, List<Object>> args, org.snmp4j.agent.MOServer[] moServers, MOXodusPersistence xodusPersistence, Properties tableSizeLimits, org.snmp4j.agent.io.ImportMode importMode) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addListenAddresses
(org.snmp4j.MessageDispatcher md, List<Object> addresses) void
agentStateChanged
(org.snmp4j.agent.AgentConfigManager agentConfigManager, org.snmp4j.agent.AgentState newState) The agent state has changed to the new state as provided.protected org.snmp4j.agent.io.MOInputFactory
createMOInputFactory
(String configFilename, org.snmp4j.agent.io.ImportMode importMode) protected org.snmp4j.agent.mo.MOFactory
Get theMOFactory
that creates the various MOs (MIB Objects).protected static Properties
getTableSizeLimitsProperties
(Map<String, List<Object>> args) Read the content of theSampleAgentTableSizeLimits.properties
file.static void
Runs a sample agent with a default configuration defined bySampleAgentConfig.properties
.protected void
Register your own MIB modules in the specified context of the agent.void
run()
protected void
setupAgent
(Map<String, List<Object>> args, org.snmp4j.agent.MOServer[] moServers, org.snmp4j.agent.io.MOInputFactory configurationFactory, List<Object> listenAddress, String dhKickstartInfoPath)
-
Field Details
-
COMMAND_LINE_OPTIONS
- See Also:
-
COMMAND_LINE_PARAMS
- See Also:
-
agent
protected org.snmp4j.agent.AgentConfigManager agent -
server
protected org.snmp4j.agent.MOServer server -
tableSizeLimits
-
-
Constructor Details
-
SampleAgent
-
SampleAgent
protected SampleAgent(Map<String, List<Object>> args, org.snmp4j.agent.MOServer[] moServers, MOXodusPersistence xodusPersistence, Properties tableSizeLimits, org.snmp4j.agent.io.ImportMode importMode)
-
-
Method Details
-
getTableSizeLimitsProperties
Read the content of theSampleAgentTableSizeLimits.properties
file.- Parameters:
args
- the command line arguments. If the arguements contain the key "ts" the default file name is replaced by the key's value.- Returns:
- a Properties instance with the table size properties read from the given file.
-
createMOInputFactory
@NotNull protected org.snmp4j.agent.io.MOInputFactory createMOInputFactory(String configFilename, org.snmp4j.agent.io.ImportMode importMode) -
setupAgent
-
addListenAddresses
-
run
public void run() -
getFactory
protected org.snmp4j.agent.mo.MOFactory getFactory()Get theMOFactory
that creates the various MOs (MIB Objects).- Returns:
- a
DefaultMOFactory
instance by default. - Since:
- 1.3.2
-
registerMIBs
protected void registerMIBs()Register your own MIB modules in the specified context of the agent. TheMOFactory
provided to theModules
constructor is returned bygetFactory()
. -
main
Runs a sample agent with a default configuration defined bySampleAgentConfig.properties
. A sample command line is:-c SampleAgent.cfg -bc SampleAgent.bc udp:127.0.0.1/4700 tcp:127.0.0.1/4700
- Parameters:
args
- the command line arguments defining at least the listen addresses. The format is-c[s{=SampleAgent.cfg}] -bc[s{=SampleAgent.bc}] +ts[s] +cfg[s] #address[s<(udp|tcp|tls):.*[/[0-9]+]?>] ..
. For the format description seeArgumentParser
.
-
agentStateChanged
public void agentStateChanged(org.snmp4j.agent.AgentConfigManager agentConfigManager, org.snmp4j.agent.AgentState newState) The agent state has changed to the new state as provided.- Specified by:
agentStateChanged
in interfaceorg.snmp4j.agent.AgentStateListener<org.snmp4j.agent.AgentConfigManager>
- Parameters:
agentConfigManager
- the agent's configuration manager. Use this object to access all agent resources, if needed to process this event.newState
- the new state of the agent. Although the listener may advance to agent state further, it is not recommended to do so, because theAgentConfigManager
will do it anyway.
-