Class TestMasterAgent

java.lang.Object
org.snmp4j.agent.agentx.master.test.TestMasterAgent

public class TestMasterAgent extends Object
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 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
package.
Version:
3.0.0
Author:
Frank Fock
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    The listen address of the agent.
    The AgentXMasterAgent instance managed and run by this test agent.
    static final String
    The ArgumentParser format string describing the supported command line options.
    static final String
    The ArgumentParser format string describing the required command line parameters.
    static org.snmp4j.log.LogAdapter
    The logger used by this master agent to report status and error messages.
    protected org.snmp4j.agent.MOServer
    The MOServer that holds the managed objects served by the agent.
    protected Properties
    The table size limits applied to the agent's tables, keyed by table OID.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TestMasterAgent(Map<String,List<Object>> args, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy)
    Creates a new TestMasterAgent from the parsed command line arguments and the given audit policy.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addListenAddresses(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 matching TransportMapping for each address.
    protected org.snmp4j.agent.io.MOInputFactory
    createMOInputFactory(String configFilename, org.snmp4j.agent.io.ImportMode importMode)
    Creates a MOInputFactory that supplies the initial agent configuration from a properties file.
    protected static Properties
    getTableSizeLimitsProperties(Map<String,List<Object>> args, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy)
    Read the content of the SampleAgentTableSizeLimits.properties file.
    static void
    main(String[] args)
    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.
    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 the AgentConfigManager including its message dispatcher, listen addresses, optional Diffie-Hellman kickstart parameters, and persistence provider.
    protected void
    Writes a human-readable Markdown (.md) overview of the initial MIB configuration defined by the supplied properties (see SampleAgentConfig.properties).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      public static org.snmp4j.log.LogAdapter logger
      The logger used by this master agent to report status and error messages.
    • COMMAND_LINE_OPTIONS

      public static final String COMMAND_LINE_OPTIONS
      The ArgumentParser format string describing the supported command line options.
      See Also:
    • COMMAND_LINE_PARAMS

      public static final String COMMAND_LINE_PARAMS
      The ArgumentParser format string describing the required command line parameters.
      See Also:
    • address

      protected String address
      The listen address of the agent.
    • agent

      protected AgentXMasterAgent agent
      The AgentXMasterAgent instance managed and run by this test agent.
    • server

      protected org.snmp4j.agent.MOServer server
      The MOServer that holds the managed objects served by the agent.
    • tableSizeLimits

      protected Properties 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 new TestMasterAgent from the parsed command line arguments and the given audit policy. The constructor sets up the MOServer, the persistence storage, the initial configuration factory, the table size limits, and the underlying AgentXMasterAgent, and adds the configured listen addresses.
      Parameters:
      args - the parsed command line arguments as returned by the ArgumentParser.
      auditPolicy - the AgentAuditPolicy used 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 the AgentConfigManager including its message dispatcher, listen addresses, optional Diffie-Hellman kickstart parameters, and persistence provider.
      Parameters:
      args - the parsed command line arguments as returned by the ArgumentParser.
      moServers - the managed object servers the agent registers its managed objects with.
      configurationFactory - the MOInputFactory providing the initial configuration, or null if none.
      listenAddress - the list of transport addresses the agent should listen on.
      dhKickstartInfoPath - the path to the Diffie-Hellman kickstart parameters file, or null if none.
      auditPolicy - the AgentAuditPolicy to use for the agent.
    • getTableSizeLimitsProperties

      protected static Properties getTableSizeLimitsProperties(Map<String,List<Object>> args, org.snmp4j.agent.audit.AgentAuditPolicy auditPolicy)
      Read the content of the SampleAgentTableSizeLimits.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.
      auditPolicy - the audit policy to use or null if 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 a MOInputFactory that supplies the initial agent configuration from a properties file.
      Parameters:
      configFilename - the path to the configuration properties file or null to use the bundled SampleAgentConfig.properties resource.
      importMode - the ImportMode that controls how the configuration is applied to existing data.
      Returns:
      a MOInputFactory providing the parsed configuration.
    • writeInitialConfigOverview

      protected void writeInitialConfigOverview(Properties props, String fileName)
      Writes a human-readable Markdown (.md) overview of the initial MIB configuration defined by the supplied properties (see SampleAgentConfig.properties). The overview is produced by building a MIBTree with a PropertyMOTreeBuilder and rendering it with a MarkdownMIBTreeFormatter. Any -viewer/-admin pass 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 in MOInput format.
      fileName - the target file name for the generated Markdown overview.
    • addListenAddresses

      protected void addListenAddresses(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 matching TransportMapping for each address.
      Parameters:
      md - the MessageDispatcher the created transport mappings are added to.
      addresses - the list of transport addresses to listen on; null entries are ignored.
    • main

      public static void main(String[] args)
      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.