Class PropertyMOTreeBuilder

java.lang.Object
org.snmp4j.agent.io.prop.PropertyMOTreeBuilder

public class PropertyMOTreeBuilder extends Object
Builds an in-memory MIBTree from a MOInput-formatted properties configuration (see PropertyMOInput for the format description).

The builder reuses PropertyMOInput.createVariableFromString(String, Class) for the actual value/OID parsing (including all {type}value format codes, embedded OID references and randomly generated secrets), so it is fully faithful to how an agent would interpret the same file. It enumerates the configured scalar and table objects per context and inserts them into an OID tree.

Because no running agent is available to supply referenced instance values, all {$name} value references (and ${name}/$#{name} index references) are resolved to UnresolvedReference placeholders via a ReferenceVariableProvider, preserving the configured reference for display.

The resulting tree can be rendered to a human readable overview using org.snmp4j.agent.util.MarkdownMIBTreeFormatter.

Since:
3.9.2
Version:
3.9.2
Author:
SNMP4J.org
  • Constructor Details

    • PropertyMOTreeBuilder

      public PropertyMOTreeBuilder(Properties properties)
      Creates a builder for the given configuration properties.
      Parameters:
      properties - the PropertyMOInput-formatted properties. The properties are not modified; a private copy is used internally.
  • Method Details

    • from

      public static PropertyMOTreeBuilder from(InputStream in) throws IOException
      Creates a builder by loading properties from the given input stream. The stream is closed by this method.
      Parameters:
      in - the input stream to read the properties from.
      Returns:
      a new builder.
      Throws:
      IOException - if the stream cannot be read.
    • from

      public static PropertyMOTreeBuilder from(Reader reader) throws IOException
      Creates a builder by loading properties from the given reader. The reader is closed by this method.
      Parameters:
      reader - the reader to read the properties from.
      Returns:
      a new builder.
      Throws:
      IOException - if the reader cannot be read.
    • from

      public static PropertyMOTreeBuilder from(File file) throws IOException
      Creates a builder by loading properties from the given file.
      Parameters:
      file - the properties file to read.
      Returns:
      a new builder.
      Throws:
      IOException - if the file cannot be read.
    • setRandomValue

      public void setRandomValue(String name, org.snmp4j.smi.OctetString value)
      Predefines a named random value (secret) that is used instead of generating a new random OctetString wherever the configuration references it via a {r}name/{R}name value. This mirrors PropertyMOInput.setRandomValue(String, OctetString) and must be called before build() so that the generated overview reflects the supplied secrets (for example pass keys provided on an agent command line) rather than freshly generated random values.
      Parameters:
      name - the name of the random value as referenced by a {r}name/{R}name value.
      value - the value to use for that name; a null value removes any predefined value.
    • build

      public MIBTree build()
      Builds the MIB tree from the configuration.
      Returns:
      the resulting MIBTree.