Class TestMasterAgent
java.lang.Object
org.snmp4j.agent.agentx.master.test.TestMasterAgent
Sample master agent with programmatically applied security configuration. To create your own master agent,
create a similar class and implement your own MIB initialization code either programmatically or by using
a
package.
MOInputFactory which uses a PropertyMOInput
to read configuration from a properties file (see the TestSubagentConfig.properties file of the
invalid reference
org.snmp4j.agent.example
- Version:
- 3.0.0
- Author:
- Frank Fock
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe listen address of the agent.protected AgentXMasterAgentTheAgentXMasterAgentinstance managed and run by this test agent.static final StringTheArgumentParserformat string describing the supported command line options.static final StringTheArgumentParserformat string describing the required command line parameters.static org.snmp4j.log.LogAdapterThe logger used by this master agent to report status and error messages.protected org.snmp4j.agent.MOServerTheMOServerthat holds the managed objects served by the agent.protected PropertiesThe table size limits applied to the agent's tables, keyed by table OID. -
Constructor Summary
ConstructorsConstructorDescriptionTestMasterAgent(Map<String, List<Object>> args, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy) Creates a newTestMasterAgentfrom the parsed command line arguments and the given audit policy. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddListenAddresses(org.snmp4j.MessageDispatcher md, List<Object> addresses) Adds the given transport addresses as listen addresses to the supplied message dispatcher by creating and starting a matchingTransportMappingfor each address.protected org.snmp4j.agent.io.MOInputFactorycreateMOInputFactory(String configFilename, org.snmp4j.agent.io.ImportMode importMode) Creates aMOInputFactorythat supplies the initial agent configuration from a properties file.protected static PropertiesgetTableSizeLimitsProperties(Map<String, List<Object>> args, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy) Read the content of theSampleAgentTableSizeLimits.propertiesfile.static voidThe program entry point that parses the command line arguments, creates the master agent, binds the AgentX master transport, and runs the agent until the process is interrupted.protected voidsetupAgent(Map<String, List<Object>> args, org.snmp4j.agent.MOServer[] moServers, org.snmp4j.agent.io.MOInputFactory configurationFactory, List<Object> listenAddress, String dhKickstartInfoPath, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy) Sets up theAgentConfigManagerincluding its message dispatcher, listen addresses, optional Diffie-Hellman kickstart parameters, and persistence provider.protected voidwriteInitialConfigOverview(Properties props, String fileName) Writes a human-readable Markdown (.md) overview of the initial MIB configuration defined by the supplied properties (seeSampleAgentConfig.properties).
-
Field Details
-
logger
public static org.snmp4j.log.LogAdapter loggerThe logger used by this master agent to report status and error messages. -
COMMAND_LINE_OPTIONS
TheArgumentParserformat string describing the supported command line options.- See Also:
-
COMMAND_LINE_PARAMS
TheArgumentParserformat string describing the required command line parameters.- See Also:
-
address
The listen address of the agent. -
agent
TheAgentXMasterAgentinstance managed and run by this test agent. -
server
protected org.snmp4j.agent.MOServer serverTheMOServerthat holds the managed objects served by the agent. -
tableSizeLimits
The table size limits applied to the agent's tables, keyed by table OID.
-
-
Constructor Details
-
TestMasterAgent
public TestMasterAgent(Map<String, List<Object>> args, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy) Creates a newTestMasterAgentfrom the parsed command line arguments and the given audit policy. The constructor sets up theMOServer, the persistence storage, the initial configuration factory, the table size limits, and the underlyingAgentXMasterAgent, and adds the configured listen addresses.- Parameters:
args- the parsed command line arguments as returned by theArgumentParser.auditPolicy- theAgentAuditPolicyused to control managed object, network, and file access.
-
-
Method Details
-
setupAgent
protected void setupAgent(Map<String, List<Object>> args, org.snmp4j.agent.MOServer[] moServers, org.snmp4j.agent.io.MOInputFactory configurationFactory, List<Object> listenAddress, String dhKickstartInfoPath, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy) Sets up theAgentConfigManagerincluding its message dispatcher, listen addresses, optional Diffie-Hellman kickstart parameters, and persistence provider.- Parameters:
args- the parsed command line arguments as returned by theArgumentParser.moServers- the managed object servers the agent registers its managed objects with.configurationFactory- theMOInputFactoryproviding the initial configuration, ornullif none.listenAddress- the list of transport addresses the agent should listen on.dhKickstartInfoPath- the path to the Diffie-Hellman kickstart parameters file, ornullif none.auditPolicy- theAgentAuditPolicyto use for the agent.
-
getTableSizeLimitsProperties
protected static Properties getTableSizeLimitsProperties(Map<String, List<Object>> args, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy) Read the content of theSampleAgentTableSizeLimits.propertiesfile.- Parameters:
args- the command line arguments. If the arguements contain the key "ts" the default file name is replaced by the key's value.auditPolicy- the audit policy to use ornullif no audit policy is to be used.- Returns:
- a Properties instance with the table size properties read from the given file or an empty Properties instance if the file could not be read.
-
createMOInputFactory
protected org.snmp4j.agent.io.MOInputFactory createMOInputFactory(String configFilename, org.snmp4j.agent.io.ImportMode importMode) Creates aMOInputFactorythat supplies the initial agent configuration from a properties file.- Parameters:
configFilename- the path to the configuration properties file ornullto use the bundledSampleAgentConfig.propertiesresource.importMode- theImportModethat controls how the configuration is applied to existing data.- Returns:
- a
MOInputFactoryproviding the parsed configuration.
-
writeInitialConfigOverview
Writes a human-readable Markdown (.md) overview of the initial MIB configuration defined by the supplied properties (seeSampleAgentConfig.properties). The overview is produced by building aMIBTreewith aPropertyMOTreeBuilderand rendering it with aMarkdownMIBTreeFormatter. Any-viewer/-adminpass keys are injected so the overview reflects the same secrets the agent would use; otherwise references to unresolved runtime instance values are shown with their configured reference.- Parameters:
props- the initial configuration properties inMOInputformat.fileName- the target file name for the generated Markdown overview.
-
addListenAddresses
Adds the given transport addresses as listen addresses to the supplied message dispatcher by creating and starting a matchingTransportMappingfor each address.- Parameters:
md- theMessageDispatcherthe created transport mappings are added to.addresses- the list of transport addresses to listen on;nullentries are ignored.
-
main
The program entry point that parses the command line arguments, creates the master agent, binds the AgentX master transport, and runs the agent until the process is interrupted.- Parameters:
args- the command line arguments.
-