Class SmiManager

java.lang.Object
com.snmp4j.smi.SmiManager
All Implemented Interfaces:
SmiCompiler, org.snmp4j.util.OIDTextFormat, org.snmp4j.util.VariableTextFormat

public final class SmiManager extends Object implements org.snmp4j.util.OIDTextFormat, org.snmp4j.util.VariableTextFormat, SmiCompiler
The SmiManager Pro class manages the Structure of Management Information (SMI) specifications. SMIv1 and v2 MIB modules can be parsed and compiled to a MIB repository which provides its content to SNMP4J through a OID and Variable formatter and parser.
Author:
Frank Fock
  • Constructor Details

    • SmiManager

      public SmiManager(String licenseKey, File repositoryDirectory) throws IOException
      Creates a SmiManager that provides the MIB information to SNMP4J through implementations of the OIDTextFormat and VariableTextFormat interfaces. In addition, MIB information can be retrieved through the methods of this class too.

      To add MIB support to your SNMP4J based application, simply add the following code in your main class:

       static {
          SmiManager smiManager = new SmiManager("myLicenseKey", new File("myEmptyDirectory"));
          SNMP4JSettings.setOIDTextFormat(smiManager);
          SNMP4JSettings.setVariableTextFormat(smiManager);
          // If you need to disable full index formatting,
          // then choose a different format below and uncomment the line:
          // smiManager.setOidFormat(OIDFormat.ObjectNameAndDecodedIndex4RoundTrip);
       }
       
      Parameters:
      licenseKey - the license key string you received with the purchase a SNMP4J-SMI license or its evaluation. You may provide null to use SNMP4J-SMI for free. But then you may not use any MIB modules of the "enterprise" OID subtree.
      repositoryDirectory - an empty directory where the SmiManager can read and store compiled MIB modules persistently. This directory may contain files from an existing MIB repository of AGENT++ AgenPro, MIB Designer, or MIB Explorer. It must not contain any plain text (i.e., uncompiled) MIB files.
      Throws:
      IOException - when the repositoryDirectory is not accessible.
    • SmiManager

      public SmiManager(String licenseKey, RepositoryDriver repositoryDriver)
      Creates a SmiManager that provides the MIB information to SNMP4J through implementations of the OIDTextFormat and VariableTextFormat interfaces. In addition, MIB information can be retrieved through the methods of this class too.

      To add MIB support to your SNMP4J based application, simply add the following code in your main class:

       static {
          SmiManager smiManager = new SmiManager("myLicenseKey", new File("myEmptyDirectory"));
          SNMP4JSettings.setOIDTextFormat(smiManager);
          SNMP4JSettings.setVariableTextFormat(smiManager);
       }
       
      Parameters:
      licenseKey - the license key string you received with the purchase a SNMP4J-SMI license or its evaluation.
      repositoryDriver - a RepositoryDriver instance which handles the reading and writing of MIB modules to disk, database, or other persistent storage.
  • Method Details

    • getOidFormat

      public SmiManager.OIDFormat getOidFormat()
      Returns:
      the current OID format. See setOidFormat(com.snmp4j.smi.SmiManager.OIDFormat).
    • setOidFormat

      public void setOidFormat(SmiManager.OIDFormat oidFormat)
      Sets the SmiManager.OIDFormat to be used to render object identifiers. To get numeric OIDs (e.g., "1.3.6.1.2.1") use SmiManager.OIDFormat.Numbers. To get object name prefix and numeric suffix (e.g., "ifDescr.0") use SmiManager.OIDFormat.ObjectNameNumIndex, which is the default. To get object name prefix and decoded index suffix (e.g., "vacmViewTreeFamilyType.demoReadView.mib-2" instead of "1.3.6.1.6.3.16.1.5.2.1.4.12.100.101.109.111.82.101.97.100.86.105.101.119.6.1.3.6.1.2.1") use SmiManager.OIDFormat.ObjectNameAndDecodedIndex. To get object name prefix and decoded index suffix for round-trip (e.g., "vacmViewTreeFamilyType."demoReadView".'mib-2'" instead of "1.3.6.1.6.3.16.1.5.2.1.4.12.100.101.109.111.82.101.97.100.86.105.101.119.6.1.3.6.1.2.1") use SmiManager.OIDFormat.ObjectNameAndDecodedIndex4RoundTrip.
      Parameters:
      oidFormat - an SmiManager.OIDFormat value.
    • getOctetStringDisplayHint

      public SmiManager.OctetStringDefaultFormat getOctetStringDisplayHint()
      Gets the current OCTET STRING default display format.
      Returns:
      the SmiManager.OctetStringDefaultFormat which is used to display OCTET STRING (and enumerated) values, if there is no MIB defined DISPLAY-HINT available. The default is SmiManager.OctetStringDefaultFormat.ASCII.
    • setOctetStringDisplayHint

      public void setOctetStringDisplayHint(SmiManager.OctetStringDefaultFormat octetStringDisplayHint)
      Sets the display format for OctetString values as defined by the enumeration SmiManager.OctetStringDefaultFormat. If this value is set to any SmiManager.OctetStringDefaultFormat other than SmiManager.OctetStringDefaultFormat.MIB then enumerated values (syntax INTEGER with labels) will be formatted by format(org.snmp4j.smi.OID, org.snmp4j.smi.Variable, boolean) as number. Otherwise as label(n) where n is the INTEGER number and label the enum label.
      Parameters:
      octetStringDisplayHint - the display format. SmiManager.OctetStringDefaultFormat.MIB is the default and displays the values as defined in the MIB. If there is no DISPLAY-HINT in the MIB format, OCTET STRING values will be displayed in ASCII format.
    • listModules

      public final String[] listModules() throws IOException
      Returns the MIB module names of the MIB modules available in the repository directory.
      Returns:
      an array of MIB module names.
      Throws:
      IOException - if the repository directory cannot be read and listed.
    • getLoadedModuleNames

      public final String[] getLoadedModuleNames()
      Returns the MIB module names of the MIB modules loaded into the SmiManager either explicitly by a previous call of loadModule(String) and compile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness) with SmiCompiler.TargetMode.storeIntoRepositoryAndLoad or indirectly by imports of directly loaded MIB modules.
      Returns:
      an array of MIB module names.
    • getExplicitlyLoadedModuleNames

      public final String[] getExplicitlyLoadedModuleNames()
      Returns the MIB module names of the MIB modules explicitly loaded with the loadModule(String) and compile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness) with SmiCompiler.TargetMode.storeIntoRepositoryAndLoad into the SmiManager. This method will not return MIB module names of MIB modules that were loaded because of IMPORT dependencies only.
      Returns:
      an array of MIB module names.
      Since:
      1.9.0 (Pro edition only)
    • getLoadedSmiModules

      public final List<SmiModule> getLoadedSmiModules() throws IOException
      Get the SmiModule object for all loaded MIB modules.
      Returns:
      the list of loaded SmiModule instances.
      Throws:
      IOException - if the repository manager uses an IO based RepositoryDriver and the IO operation failed.
      Since:
      1.7.1
    • loadModule

      public final boolean loadModule(String moduleName)
      Loads a MIB module from disk (MIB repository) into memory. If the module has been loaded its data is available for the formatting and parsing operations of this SmiManager instance.
      Parameters:
      moduleName - the MIB module name (e.g. "SNMPv2-MIB").
      Returns:
      true if the module and all the MIB objects it is importing from other modules could be loaded successfully, false otherwise.
    • unloadModule

      public final boolean unloadModule(String moduleName)
      Unload a MIB module from the SmiManager memory. The corresponding MIB module in the MIB repository directory will not be modified.
      Parameters:
      moduleName - a MIB module name.
      Returns:
      true if the MIB module was in memory and is now removed, false otherwise.
    • unloadModuleWithDependencies

      public final int unloadModuleWithDependencies(String moduleName)
      Unload a MIB module from the SmiManager memory, including all its dependencies that are not needed by other loaded MIB modules. The compiled MIB modules in the MIB repository directory will not be modified.
      Parameters:
      moduleName - a MIB module name.
      Returns:
      The number of MIB objects removed from the memory (including the module itself). If zero is returned, then no object has been removed.
      Since:
      1.9.0
    • isModuleLoaded

      public final boolean isModuleLoaded(String moduleName)
      Checks if the MIB module with the specified name is already loaded into the SmiManager from disk.
      Parameters:
      moduleName - a MIB module name.
      Returns:
      true if the MIB module is loaded, false otherwise.
    • deleteModule

      public final List<String> deleteModule(String moduleName, boolean forceDeletion)
      Deletes a MIB module from the MIB repository directory if it is not used/imported by other MIB modules in the repository.
      Parameters:
      moduleName - the MIB module name of the module which should be deleted.
      forceDeletion - if true, it will not be checked if other MIB modules in the repository import from the MIB module with name moduleName, otherwise that check is performed and the MIB module will not be deleted if it is still used by depending MIB modules. WARNING: Deleting a MIB module which is used by others can lead to errors while accessing those modules.
      Returns:
      an empty List if the MIB module has been deleted or one or more MIB module names of MIB modules that depend on the MIB module with the name moduleName. If the list contains only one element and that is the module's name, then the RepositoryDriver did not allow to delete the MIB module or an IO error occurred.
    • compile

      public final String[] compile(File textOrZipFile) throws SmiParseException, FileNotFoundException
      Compiles a MIB module from a given text or ZIP file.
      Parameters:
      textOrZipFile - an existing text or ZIP file. A ZIP file must end with ".ZIP" or ".zip" to be recognized as ZIP file.
      Returns:
      an array of the module names successfully parsed.
      Throws:
      SmiParseException - if the MIB module contains a syntax or semantic error.
      FileNotFoundException - if the specified cannot be found or opened for reading.
    • resetOidQuoting

      public void resetOidQuoting()
      Resets the OID quotation characters and escape sequences to the default (which is highly recommended to be used). This method executes as follows:
          oidFixedLengthStringQuote = '\'';
          oidVariableLengthStringQuote = '"';
          oidFixedLengthStringQuoteEscapeSequence = "\\'";
          oidVariableLengthStringQuoteEscapeSequence =  "\\\"";
          oidStringQuoteEscapeCharacter = '\\';
       
      Since:
      1.1.1
    • getOidFixedLengthStringQuote

      public char getOidFixedLengthStringQuote()
      Gets the quote character for fixed length formatted sub-index OIDs.
      Returns:
      a quote character, by default the single quote '.
      Since:
      1.1.1
    • setOidFixedLengthStringQuote

      public void setOidFixedLengthStringQuote(char oidFixedLengthStringQuote)
      Sets the quote character for fixed length formatted sub-index OIDs.
      Parameters:
      oidFixedLengthStringQuote - a quote character.
      Since:
      1.1.1
    • getOidVariableLengthStringQuote

      public char getOidVariableLengthStringQuote()
      Gets the quote character for variable length formatted sub-index OIDs.
      Returns:
      a quote character, by default the double quote ".
      Since:
      1.1.1
    • setOidVariableLengthStringQuote

      public void setOidVariableLengthStringQuote(char oidVariableLengthStringQuote)
      Sets the quote character for variable length formatted sub-index OIDs.
      Parameters:
      oidVariableLengthStringQuote - a quote character.
      Since:
      1.1.1
    • getOidFixedLengthStringQuoteEscapeSequence

      public String getOidFixedLengthStringQuoteEscapeSequence()
      Gets the sequence to escape character sequence for fixed length formatted sub-index OID quotes.
      Returns:
      a quote escape sequence.
      Since:
      1.1.1
    • setOidFixedLengthStringQuoteEscapeSequence

      public void setOidFixedLengthStringQuoteEscapeSequence(String oidFixedLengthStringQuoteEscapeSequence)
      Sets the sequence to escape character sequence for fixed length formatted sub-index OID quotes.
      Parameters:
      oidFixedLengthStringQuoteEscapeSequence - a quote escape sequence.
      Since:
      1.1.1
    • getOidVariableLengthStringQuoteEscapeSequence

      public String getOidVariableLengthStringQuoteEscapeSequence()
      Gets the sequence to escape character sequence for variable length formatted sub-index OID quotes.
      Returns:
      a quote escape sequence.
    • setOidVariableLengthStringQuoteEscapeSequence

      public void setOidVariableLengthStringQuoteEscapeSequence(String oidVariableLengthStringQuoteEscapeSequence)
      Sets the sequence to escape character sequence for variable length formatted sub-index OID quotes.
      Parameters:
      oidVariableLengthStringQuoteEscapeSequence - a quote escape sequence.
      Since:
      1.1.1
    • getOidStringQuoteEscapeCharacter

      public char getOidStringQuoteEscapeCharacter()
      Gets the OID string escape character for quotes. This character must be used to define the both escape sequences getOidFixedLengthStringQuoteEscapeSequence() and getOidVariableLengthStringQuoteEscapeSequence(). Otherwise the results of formatting and parsing of OIDs are undefined.
      Returns:
      the escape character (default is the backslash character) for escaping OID string quotes.
    • setOidStringQuoteEscapeCharacter

      public void setOidStringQuoteEscapeCharacter(char oidStringQuoteEscapeCharacter)
      Sets the OID string escape character for quotes. This character must be used to define the both escape sequences getOidFixedLengthStringQuoteEscapeSequence() and getOidVariableLengthStringQuoteEscapeSequence(). Otherwise the results of formatting and parsing of OIDs are undefined!
      Parameters:
      oidStringQuoteEscapeCharacter - the escape character (default is the backslash character) for escaping OID string quotes.
    • compile

      public final String[] compile(NamedInputStream mibFile) throws SmiParseException
      Compiles a MIB module from a given InputStream and returns the names of the compiled MIB modules from the stream.
      Parameters:
      mibFile - a stream containing the contents of one or more MIB module specifications.
      Returns:
      an array of MIB module names compiled from the stream.
      Throws:
      SmiParseException - if the specification has SMI syntax or semantic errors.
    • compile

      public List<CompilationResult> compile(File[] files, CompilationMonitor compilationMonitor, boolean loadIntoRepository, boolean updateExistent, boolean compileLeniently) throws IOException
      Compiles an array of text or ZIP files provided as Files. The compilation is executed in three phases:
      1. The provided files are loaded into memory.
      2. The loaded files are analyzed about their module names and then sorted according to their dependencies to other modules.
      3. The sorted MIB modules will then be compiled and written into the internal MIB repository. In addition, if enabled, the compiled MIB modules will also be loaded into the MIB cache.
      The compilation progress can be monitored by callbacks through the CompilationMonitor interface.
      Parameters:
      files - an array of File instances where each instance may represent a text or ZIP file. ZIP file names have to end with ".ZIP" or ".zip".
      compilationMonitor - an optional CompilationMonitor implementation to monitor the progress of the compilation.
      loadIntoRepository - if true the compiled MIB modules will not only be stored into the internal MIB repository, but also directly loaded into the MIB cache so that they can be used right after this method call completes.
      updateExistent - if true compiled MIB modules will replace existing MIB modules in the MIB repository with the same module names.
      compileLeniently - if true syntax and semantic checks are limited to the necessary minimum. A MIB module that can be successfully parsed in lenient mode may contain severe standard violations and even errors that can affect proper formatting and value parsing support for SNMP4J. Use this option only if you can handle the risk or if you are not able to fix or let fix the errors in the MIB specification(s).
      Returns:
      a List of CompilationResult instances. Each instance represents an input file. For ZIP files, a CompilationResult instance is returned for each ZIP file entry.
      Throws:
      IOException - if any IO operation fails when accessing the input files (InputStreams).
    • compile

      public List<CompilationResult> compile(NamedInputStream[] files, CompilationMonitor compilationMonitor, SmiCompiler.TargetMode compilerTargetMode, SmiCompiler.OverwriteMode overwriteMode, SmiCompiler.Strictness strictness) throws IOException
      Description copied from interface: SmiCompiler
      Compiles an array of text or ZIP files provided as NamedInputStreams. The compilation is executed in three phases:
      1. The provided NamedInputStreams are loaded into memory.
      2. The loaded files are analyzed about their module names and then sorted according to their dependencies to other modules.
      3. The sorted MIB modules will then be compiled and written into the internal MIB repository. In addition, if enabled, the compiled MIB modules will also be loaded into the MIB cache.
      The compilation progress can be monitored by callbacks through the CompilationMonitor interface.
      Specified by:
      compile in interface SmiCompiler
      Parameters:
      files - an array of NamedInputStream instances where each instance may represent a text or ZIP file.
      compilationMonitor - an optional CompilationMonitor implementation to monitor the progress of the compilation.
      compilerTargetMode - with the mode SmiCompiler.TargetMode.storeIntoRepositoryAndLoad the compiled MIB modules will not only be stored into the internal MIB repository, but also directly loaded into the MIB cache so that they can be used right after this method call completes. With SmiCompiler.TargetMode.dryRun no modifications to the MIB repository or MIB cache are done and only the result of the syntax check is returned.
      overwriteMode - specifies whether compiled MIB modules will replace existing MIB modules in the MIB repository as well as in the cache with the same module names or not.
      strictness - if SmiCompiler.Strictness.lenient is used then syntax and semantic checks are limited to the necessary minimum. A MIB module that can be successfully parsed in lenient mode may contain severe standard violations and even errors that can affect proper formatting and value parsing support for SNMP4J. Use this option only if you can handle the risk or if you are not able to fix or let fix the errors in the MIB specification(s).
      Returns:
      a List of CompilationResult instances. Each instance represents an input file. For ZIP files, a CompilationResult instance is returned for each ZIP file entry.
      Throws:
      IOException - if any IO operation fails when accessing the input files (InputStreams).
    • compile

      public List<CompilationResult> compile(NamedInputStream[] files, CompilationMonitor compilationMonitor, boolean loadIntoRepository, boolean updateExistent, boolean compileLeniently) throws IOException
      Compiles an array of text or ZIP files provided as NamedInputStreams. The compilation is executed in three phases:
      1. The provided NamedInputStreams are loaded into memory.
      2. The loaded files are analyzed about their module names and then sorted according to their dependencies to other modules.
      3. The sorted MIB modules will then be compiled and written into the internal MIB repository. In addition, if enabled, the compiled MIB modules will also be loaded into the MIB cache.
      The compilation progress can be monitored by callbacks through the CompilationMonitor interface.
      Parameters:
      files - an array of NamedInputStream instances where each instance may represent a text or ZIP file.
      compilationMonitor - an optional CompilationMonitor implementation to monitor the progress of the compilation.
      loadIntoRepository - if true the compiled MIB modules will not only be stored into the internal MIB repository, but also directly loaded into the MIB cache so that they can be used right after this method call completes.
      updateExistent - if true compiled MIB modules will replace existing MIB modules in the MIB repository with the same module names.
      compileLeniently - if true syntax and semantic checks are limited to the necessary minimum. A MIB module that can be successfully parsed in lenient mode may contain severe standard violations and even errors that can affect proper formatting and value parsing support for SNMP4J. Use this option only if you can handle the risk or if you are not able to fix or let fix the errors in the MIB specification(s).
      Returns:
      a List of CompilationResult instances. Each instance represents an input file. For ZIP files, a CompilationResult instance is returned for each ZIP file entry.
      Throws:
      IOException - if any IO operation fails when accessing the input files (InputStreams).
    • format

      public final String format(org.snmp4j.smi.OID instanceOID, org.snmp4j.smi.Variable variable, boolean withOID)
      Specified by:
      format in interface org.snmp4j.util.VariableTextFormat
    • parseVariableBinding

      public final org.snmp4j.smi.VariableBinding parseVariableBinding(String text) throws ParseException
      Specified by:
      parseVariableBinding in interface org.snmp4j.util.VariableTextFormat
      Throws:
      ParseException
    • parse

      public final org.snmp4j.smi.Variable parse(org.snmp4j.smi.OID classOrInstanceOID, String text) throws ParseException
      Specified by:
      parse in interface org.snmp4j.util.VariableTextFormat
      Throws:
      ParseException
    • parse

      public final org.snmp4j.smi.Variable parse(int smiSyntax, String text) throws ParseException
      Specified by:
      parse in interface org.snmp4j.util.VariableTextFormat
      Throws:
      ParseException
    • format

      public final String format(int[] value)
      Specified by:
      format in interface org.snmp4j.util.OIDTextFormat
    • formatForRoundTrip

      public String formatForRoundTrip(int[] value)
      Specified by:
      formatForRoundTrip in interface org.snmp4j.util.OIDTextFormat
    • parse

      public final int[] parse(String text) throws ParseException
      Specified by:
      parse in interface org.snmp4j.util.OIDTextFormat
      Throws:
      ParseException
    • tokenizeQuotedString

      public static List<String> tokenizeQuotedString(String text, String quotes, char escapeChar, String delimiter, boolean includeQuotes)
      Tokenize a string by a delimiter string but do not split quoted strings with the supplied quote characters. Value escaping of the quote characters as well.
      Parameters:
      text - the text to tokenize (split into pieces).
      quotes - the list of quote characters to process.
      escapeChar - the escape character that can be used to escape quotes.
      delimiter - the delimiter string that separates the tokens.
      includeQuotes - if true quotes will be return as part of the returned tokens, otherwise they will be removed from the token boundaries.
      Returns:
      the list of tokens.
    • getOidFormatNonPrintableStrings

      public SmiManager.NonPrintableStringFormat getOidFormatNonPrintableStrings()
      Gets the SmiManager.NonPrintableStringFormat for strings in formatted OIDs. A string is not printable if it contains any ISO control characters as defined by Character.isISOControl(char) except if these ISO control characters are all whitespace characters as defined by Character.isWhitespace(char) and not '&#92;u001C'-'&#92;u001F'.
      Returns:
      the current format for non-printable strings.
      Since:
      1.1
    • setOidFormatNonPrintableStrings

      public void setOidFormatNonPrintableStrings(SmiManager.NonPrintableStringFormat oidFormatNonPrintableStrings)
      Sets the SmiManager.NonPrintableStringFormat for strings in formatted OIDs. The default is SmiManager.NonPrintableStringFormat.asIs
      Parameters:
      oidFormatNonPrintableStrings - the new format for non-printable strings (must not be null).
      Since:
      1.1
    • getIndexVariables

      public org.snmp4j.smi.Variable[] getIndexVariables(org.snmp4j.smi.OID table, org.snmp4j.smi.OID index)
      Gets the variable values for all sub-index objects for the specified table entry.
      Parameters:
      table - the table entry OID (= "tableOID.1") the index OID belongs to.
      index - the index OID which should be split into its sub-index values (variables).
      Returns:
      null if the table entry OID cannot be resolved, otherwise the index OID is split into the sub-index variables which are then returned as an array.
    • getIndexStringFromVariables

      public String getIndexStringFromVariables(org.snmp4j.smi.OID table, List<org.snmp4j.smi.VariableBinding> indexObjects)
      Gets the INDEX string representations from a list of INDEX objects.
      Parameters:
      table - the table definition with the INDEX clause to be used for the conversion.
      indexObjects - a list of INDEX object values.
      Returns:
      creates dot ('.') separated string representation of the given INDEX objects using the variable display
    • findSmiObject

      public SmiObject findSmiObject(org.snmp4j.smi.OID oid)
      Gets the SMI object defined for the specified OID. For SMI objects that have no OID, i.e. TEXTUAL CONVENTIONS you will have to use findSmiObject(String, String) instead.
      Parameters:
      oid - the object identifier of the SMI object to return.
      Returns:
      the SMI object that provides additional information about a MIB object.
      Since:
      1.2 (Pro edition only)
    • findSmiObjectType

      public SmiObjectType findSmiObjectType(org.snmp4j.smi.OID oidInstance)
      Gets the SMI object type defined for the specified instance OID. For looking up SMI objectfrom their OID, thus without index suffix use findSmiObject(OID) instead. For example, this method will return the SmiObject sysDescr on "1.3.6.1.2.1.1.1.0" and "1.3.6.1.2.1.1.1" if the SNMPv2-MIB is loaded. If IF-MIB is loaded, "1.3.6.1.2.1.2.2.1.7.20100" will return the ifAdminStatus SmiObjectType.
      Parameters:
      oidInstance - the object instance identifier of the SMI OBJECT-TYPE to lookup.
      Returns:
      the SmiObjectType that provides information about a MIB object type.
      Since:
      1.9.14 (Pro edition only)
    • findRootSmiObject

      public SmiObject findRootSmiObject()
      Gets the SMI object with the lexicographic smallest OID within the currently loaded MIB modules.
      Returns:
      the SmiObject with the smallest OID (which exists - i.e. SmiTextualConvention instances must not be returned) within all loaded MIB modules. If no module with an object with OID is loaded then null will be returned.
      Since:
      1.2 (Pro edition only)
    • findRootSmiObject

      public SmiObject findRootSmiObject(String moduleName)
      Gets the SMI object with the lexicographic smallest OID within the given loaded MIB module.
      Parameters:
      moduleName - the module name for which the root object should be returned. If there is no MIB module loaded with that name or it contains no object identifiers, then null is returned.
      Returns:
      the SmiObject with the smallest OID (which exists - i.e. SmiTextualConvention instances must not be returned) within the given loaded MIB module.
      Since:
      1.9 (Pro edition only)
    • findSmiModule

      public SmiModule findSmiModule(String moduleName)
      Gets the SmiModule with the specified module name. Note: The module name is an uppercase name and is always different from the MODULE-IDENTITY object name which starts with a lower case letter.

      For SMIv2 the returned SmiModule is also a SmiModuleIdentity!

      Parameters:
      moduleName - a MIB module name (e.g. SNMPv2-MIB).
      Returns:
      the SmiModule with the module name moduleName or null if such a module has not been loaded yet with loadModule(String).
      Since:
      1.2 (Pro edition only)
    • findSmiModules

      public List<SmiModule> findSmiModules(org.snmp4j.smi.OID smiObjectIdentifier)
      Gets the SmiModule that defines the provided object identifier.

      For SMIv2 the returned SmiModule is also a SmiModuleIdentity!

      Parameters:
      smiObjectIdentifier - an OID of an object that is defined by the MIB module (usage by import will not match).
      Returns:
      a list of SmiModules defining the provided OID or null if the OID could not be found in any module. The returned list might be empty if no MIB module that defines it is currently loaded with loadModule(String)).
      Since:
      1.6 (Pro edition only)
    • findSmiObject

      public SmiObject findSmiObject(String moduleName, String objectName)
      Gets the SMI object defined for the specified object name. For SMI objects that have an OID, i.e. OBJECT-TYPE it is recommend to use the findSmiObject(org.snmp4j.smi.OID) instead if possible in order to avoid ambiguities when not able to provide a MIB module name.
      Parameters:
      moduleName - the name of the MIB module, the object is defined in.
      objectName - the name of the SMI object to return.
      Returns:
      the SMI object that provides additional information about a MIB object.
      Since:
      1.2 (Pro edition only)
    • findSmiObject

      public SmiObject findSmiObject(String moduleName, String objectName, boolean includeImportedModules)
      Gets the SMI object defined for the specified object name. For SMI objects that have an OID, i.e. OBJECT-TYPE it is recommend to use the findSmiObject(org.snmp4j.smi.OID) instead if possible in order to avoid ambiguities when not able to provide a MIB module name.
      Parameters:
      moduleName - the name of the MIB module, the object is defined in or imported by (if includeImportedModules is set to true).
      objectName - the name of the SMI object to return.
      includeImportedModules - if false this method behaves exactly like findSmiObject(String, String) if true then first the provided moduleName is searched for the definition of an object with the name objectName. If it is not found then the first import of an object with that name is used and findSmiObject(String, String) is called with the MIB module name of that import dependency.
      Returns:
      the SMI object that provides additional information about a MIB object.
      Since:
      1.7 (Pro edition only)
    • findSmiObject

      public <S extends SmiObject> List<S> findSmiObject(String moduleName, SmiObjectFilter<S> filter)
      Gets the SMI object defined for the specified OID. For SMI objects that have an OID, i.e. OBJECT-TYPE it is recommend to use the findSmiObject(org.snmp4j.smi.OID) instead if possible in order to avoid ambiguities when not able to provide a MIB module name.
      Type Parameters:
      S - the type of the SMI object to find.
      Parameters:
      moduleName - the name of the MIB module, the object is defined in or null when objects of all modules should be returned.
      filter - a SmiObjectFilter instance that selects the objects to return by callback.
      Returns:
      the SMI object that provides additional information about a MIB object.
      Since:
      1.2 (Pro edition only)
    • setIncludeUnknownErrorsCause

      public void setIncludeUnknownErrorsCause(boolean includeUnknownErrorsCause)
      Sets the flag that controls whether exceptions or other unknown error messages during parsing and storing of MIB modules to the repository should be included in the error message or not.
      Parameters:
      includeUnknownErrorsCause - if true the message text of caught exceptions during MIB compilation will be included in the "errUnknownError" message, false otherwise (the default).
      Since:
      1.3 (Pro edition only)
    • isIncludeUnknownErrorsCause

      public boolean isIncludeUnknownErrorsCause()
      Returns the flag that controls whether exceptions or other unknown error messages during parsing and storing of MIB modules to the repository should be included in the error message or not.
      Returns:
      true if the message text of caught exceptions during MIB compilation will be included in the "errUnknownError" message, false otherwise (the default).
      Since:
      1.3 (Pro edition only)
    • setSmiErrorTextResourceBundle

      public void setSmiErrorTextResourceBundle(String resourceBundleClassName)
      Sets the class name of the custom resource bundle for SMI error texts. You need to set this value only if you want to provide your own error texts or error texts for languages other than English.
      Parameters:
      resourceBundleClassName - the class name (including package name) of the resource bundle with the SMI error texts. For an example message resource bundle, see the "examples" directory of the distribution.
      Since:
      1.3 (Pro edition only)
    • setStoreFilenamesInRepository

      public void setStoreFilenamesInRepository(boolean storeFilenameInRepository)
      Sets a system property that controls whether the MIB compiler will store the file names of the MIB files into the repository when a MIB module is compiled. The filename can be later read with the SmiModule.getSourceFilename() method.
      Parameters:
      storeFilenameInRepository - if true file names are stored, otherwise not stored at all (default).
      Since:
      1.6
    • isStoreFilenamesInRepository

      public boolean isStoreFilenamesInRepository()
      Checks a system property that controls whether the MIB compiler will store the file names of the MIB files into the repository when a MIB module is compiled or not.
      Returns:
      if true file names are stored, otherwise not stored at all (default).
      Since:
      1.6