Package com.snmp4j.smi
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines the format for non-printable strings in formatted object identifiers (OIDs).static enumThe default formats to be applied for displayingOctetStrings.static enumThe OIDFormat defines the formatting ofOIDvalues.Nested classes/interfaces inherited from interface com.snmp4j.smi.SmiCompiler
SmiCompiler.OverwriteMode, SmiCompiler.Strictness, SmiCompiler.TargetMode -
Constructor Summary
ConstructorsConstructorDescriptionSmiManager(String licenseKey, RepositoryDriver repositoryDriver) Creates aSmiManagerthat provides the MIB information to SNMP4J through implementations of theOIDTextFormatandVariableTextFormatinterfaces.SmiManager(String licenseKey, File repositoryDirectory) Creates aSmiManagerthat provides the MIB information to SNMP4J through implementations of theOIDTextFormatandVariableTextFormatinterfaces. -
Method Summary
Modifier and TypeMethodDescriptionString[]compile(NamedInputStream mibFile) Compiles a MIB module from a given InputStream and returns the names of the compiled MIB modules from the stream.compile(NamedInputStream[] files, CompilationMonitor compilationMonitor, boolean loadIntoRepository, boolean updateExistent, boolean compileLeniently) Deprecated.compile(NamedInputStream[] files, CompilationMonitor compilationMonitor, SmiCompiler.TargetMode compilerTargetMode, SmiCompiler.OverwriteMode overwriteMode, SmiCompiler.Strictness strictness) Compiles an array of text or ZIP files provided asNamedInputStreams.final String[]Compiles a MIB module from a given text or ZIP file.compile(File[] files, CompilationMonitor compilationMonitor, boolean loadIntoRepository, boolean updateExistent, boolean compileLeniently) Compiles an array of text or ZIP files provided asFiles.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.Gets the SMI object with the lexicographic smallest OID within the currently loaded MIB modules.findRootSmiObject(String moduleName) Gets the SMI object with the lexicographic smallest OID within the given loaded MIB module.findSmiModule(String moduleName) Gets theSmiModulewith the specified module name.findSmiModules(org.snmp4j.smi.OID smiObjectIdentifier) Gets theSmiModulethat defines the provided object identifier.findSmiObject(String moduleName, SmiObjectFilter<S> filter) Gets the SMI object defined for the specifiedOID.findSmiObject(String moduleName, String objectName) Gets the SMI object defined for the specified object name.findSmiObject(String moduleName, String objectName, boolean includeImportedModules) Gets the SMI object defined for the specified object name.findSmiObject(org.snmp4j.smi.OID oid) Gets the SMI object defined for the specifiedOID.findSmiObjectType(org.snmp4j.smi.OID oidInstance) Gets the SMI object type defined for the specified instanceOID.final Stringformat(int[] value) final Stringformat(org.snmp4j.smi.OID instanceOID, org.snmp4j.smi.Variable variable, boolean withOID) formatForRoundTrip(int[] value) final String[]Returns the MIB module names of the MIB modules explicitly loaded with theloadModule(String)andcompile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness)withSmiCompiler.TargetMode.storeIntoRepositoryAndLoadinto theSmiManager.getIndexStringFromVariables(org.snmp4j.smi.OID table, List<org.snmp4j.smi.VariableBinding> indexObjects) Gets the INDEX string representations from a list of INDEX objects.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.final String[]Returns the MIB module names of the MIB modules loaded into theSmiManagereither explicitly by a previous call ofloadModule(String)andcompile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness)withSmiCompiler.TargetMode.storeIntoRepositoryAndLoador indirectly by imports of directly loaded MIB modules.Get theSmiModuleobject for all loaded MIB modules.Gets the current OCTET STRING default display format.charGets the quote character for fixed length formatted sub-index OIDs.Gets the sequence to escape character sequence for fixed length formatted sub-index OID quotes.Gets the currentSmiManager.OIDFormat(default isSmiManager.OIDFormat.ObjectNameAndDecodedIndex4RoundTrip).Gets theSmiManager.NonPrintableStringFormatfor strings in formattedOIDs.charGets the OID string escape character for quotes.charGets the quote character for variable length formatted sub-index OIDs.Gets the sequence to escape character sequence for variable length formatted sub-index OID quotes.booleanReturns 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.final booleanisModuleLoaded(String moduleName) Checks if the MIB module with the specified name is already loaded into the SmiManager from disk.booleanChecks 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.booleanDetermines if compression is enabled for compiled MIB modules.final String[]Returns the MIB module names of the MIB modules available in the repository directory.booleanloadModule(String moduleName) Loads a MIB module from disk (MIB repository) into memory.boolean[]loadModules(String[] moduleNames, int maxThreads, boolean overwriteExistingObjects) Loads the specified modules concurrently, using a thread pool with a maximum number of threads defined by the given parameter.final org.snmp4j.smi.Variablefinal int[]final org.snmp4j.smi.Variablefinal org.snmp4j.smi.VariableBindingparseVariableBinding(String text) voidRemove all loaded modules from memory and clears the module repository.voidResets the OID quotation characters and escape sequences to the default (which is highly recommended to be used).voidsetIncludeUnknownErrorsCause(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.voidsetOctetStringDisplayHint(SmiManager.OctetStringDefaultFormat octetStringDisplayHint) Sets the display format forOctetStringvalues as defined by the enumerationSmiManager.OctetStringDefaultFormat.voidsetOidFixedLengthStringQuote(char oidFixedLengthStringQuote) Sets the quote character for fixed length formatted sub-index OIDs.voidsetOidFixedLengthStringQuoteEscapeSequence(String oidFixedLengthStringQuoteEscapeSequence) Sets the sequence to escape character sequence for fixed length formatted sub-index OID quotes.voidsetOidFormat(SmiManager.OIDFormat oidFormat) Sets theSmiManager.OIDFormatto be used to render object identifiers.voidsetOidFormatNonPrintableStrings(SmiManager.NonPrintableStringFormat oidFormatNonPrintableStrings) Sets theSmiManager.NonPrintableStringFormatfor strings in formattedOIDs.voidsetOidStringQuoteEscapeCharacter(char oidStringQuoteEscapeCharacter) Sets the OID string escape character for quotes.voidsetOidVariableLengthStringQuote(char oidVariableLengthStringQuote) Sets the quote character for variable length formatted sub-index OIDs.voidsetOidVariableLengthStringQuoteEscapeSequence(String oidVariableLengthStringQuoteEscapeSequence) Sets the sequence to escape character sequence for variable length formatted sub-index OID quotes.voidsetSmiErrorTextResourceBundle(String resourceBundleClassName) Sets the class name of the custom resource bundle for SMI error texts.voidsetStoreFilenamesInRepository(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.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.booleanunloadModule(String moduleName) Unload a MIB module from theSmiManagermemory.final intunloadModuleWithDependencies(String moduleName) Unload a MIB module from theSmiManagermemory, including all its dependencies that are not needed by other loaded MIB modules.useCompression(boolean enableCompressionOfCompiledModules) Configures whether to enable or disable compression for compiled modules.
-
Constructor Details
-
SmiManager
Creates aSmiManagerthat provides the MIB information to SNMP4J through implementations of theOIDTextFormatandVariableTextFormatinterfaces. 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 providenullto 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 therepositoryDirectoryis not accessible.
-
SmiManager
Creates aSmiManagerthat provides the MIB information to SNMP4J through implementations of theOIDTextFormatandVariableTextFormatinterfaces. 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- aRepositoryDriverinstance which handles the reading and writing of MIB modules to disk, database, or other persistent storage.
-
-
Method Details
-
useCompression
Configures whether to enable or disable compression for compiled modules. Any MIB modules compiled after setting this to true will be compressed using GZIP. Existing MIB modules will not be changed. Compressed MIB modules can be read even if this setting isfalse. The default is @code true} since 1.12.0.- Parameters:
enableCompressionOfCompiledModules- a boolean value where true enables compression of compiled modules and false disables it.- Returns:
- this instance for fluent configuration.
- Since:
- 1.12.0
-
isUseCompression
public boolean isUseCompression()Determines if compression is enabled for compiled MIB modules.- Returns:
- true if compression is enabled, false otherwise
- Since:
- 1.12.0
-
getOidFormat
Gets the currentSmiManager.OIDFormat(default isSmiManager.OIDFormat.ObjectNameAndDecodedIndex4RoundTrip).- Returns:
- the current OID format. See
setOidFormat(com.snmp4j.smi.SmiManager.OIDFormat).
-
setOidFormat
Sets theSmiManager.OIDFormatto be used to render object identifiers. To get numeric OIDs (e.g., "1.3.6.1.2.1") useSmiManager.OIDFormat.Numbers. To get object name prefix and numeric suffix (e.g., "ifDescr.0") useSmiManager.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") useSmiManager.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") useSmiManager.OIDFormat.ObjectNameAndDecodedIndex4RoundTrip.- Parameters:
oidFormat- anSmiManager.OIDFormatvalue.
-
getOctetStringDisplayHint
Gets the current OCTET STRING default display format.- Returns:
- the
SmiManager.OctetStringDefaultFormatwhich is used to display OCTET STRING (and enumerated) values, if there is no MIB defined DISPLAY-HINT available. The default isSmiManager.OctetStringDefaultFormat.ASCII.
-
setOctetStringDisplayHint
Sets the display format forOctetStringvalues as defined by the enumerationSmiManager.OctetStringDefaultFormat. If this value is set to anySmiManager.OctetStringDefaultFormatother thanSmiManager.OctetStringDefaultFormat.MIBthen enumerated values (syntax INTEGER with labels) will be formatted byformat(org.snmp4j.smi.OID, org.snmp4j.smi.Variable, boolean)as number. Otherwise aslabel(n)wherenis the INTEGER number andlabelthe enum label.- Parameters:
octetStringDisplayHint- the display format.SmiManager.OctetStringDefaultFormat.MIBis 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
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
Returns the MIB module names of the MIB modules loaded into theSmiManagereither explicitly by a previous call ofloadModule(String)andcompile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness)withSmiCompiler.TargetMode.storeIntoRepositoryAndLoador indirectly by imports of directly loaded MIB modules.- Returns:
- an array of MIB module names.
-
getExplicitlyLoadedModuleNames
Returns the MIB module names of the MIB modules explicitly loaded with theloadModule(String)andcompile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness)withSmiCompiler.TargetMode.storeIntoRepositoryAndLoadinto theSmiManager. 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
Get theSmiModuleobject for all loaded MIB modules.- Returns:
- the list of loaded
SmiModuleinstances. - Throws:
IOException- if the repository manager uses an IO basedRepositoryDriverand the IO operation failed.- Since:
- 1.7.1
-
loadModule
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 thisSmiManagerinstance.- Parameters:
moduleName- the MIB module name (e.g. "SNMPv2-MIB").- Returns:
trueif the module and all the MIB objects it is importing from other modules could be loaded successfully,falseotherwise.
-
loadModules
public boolean[] loadModules(String[] moduleNames, int maxThreads, boolean overwriteExistingObjects) Loads the specified modules concurrently, using a thread pool with a maximum number of threads defined by the given parameter. The method attempts to load the modules either completely. Depending on the value of the `overwriteExistingObjects` flag, already loaded objects from the same module (identified by a technical ID from the repository) will be removed and reloaded or added as a duplicate.- Parameters:
moduleNames- an array of strings representing the names of the modules to loadmaxThreads- the maximum number of threads to be used for concurrent loading operationsoverwriteExistingObjects- a boolean flag specifying whether existing objects should be overwritten. It is recommended to usetrueunless you need to load MIB modules as quickly as possible.- Returns:
- a boolean array where each element corresponds to the success state of loading the respective module
- Since:
- 1.12.0
-
unloadModule
Unload a MIB module from theSmiManagermemory. The corresponding MIB module in the MIB repository directory will not be modified.- Parameters:
moduleName- a MIB module name.- Returns:
trueif the MIB module was in memory and is now removed,falseotherwise.
-
resetModules
public void resetModules()Remove all loaded modules from memory and clears the module repository. This method performs the following actions: 1. Clears the module repository to ensure all loaded modules are removed. 2. Empties the collection of loaded modules, resetting the internal state. This method is synchronized to ensure thread safety when accessing or modifying the module repository and loaded module list.- Since:
- 1.12.0
-
unloadModuleWithDependencies
Unload a MIB module from theSmiManagermemory, 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
Checks if the MIB module with the specified name is already loaded into the SmiManager from disk.- Parameters:
moduleName- a MIB module name.- Returns:
trueif the MIB module is loaded,falseotherwise.
-
deleteModule
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- iftrue, it will not be checked if other MIB modules in the repository import from the MIB module with namemoduleName, 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 theRepositoryDriverdid not allow to delete the MIB module or an IO error occurred.
-
compile
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
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
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 sequencesgetOidFixedLengthStringQuoteEscapeSequence()andgetOidVariableLengthStringQuoteEscapeSequence(). 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 sequencesgetOidFixedLengthStringQuoteEscapeSequence()andgetOidVariableLengthStringQuoteEscapeSequence(). 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
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 asFiles. The compilation is executed in three phases:- The provided files are loaded into memory.
- The loaded files are analyzed about their module names and then sorted according to their dependencies to other modules.
- 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.
CompilationMonitorinterface.- Parameters:
files- an array ofFileinstances where each instance may represent a text or ZIP file. ZIP file names have to end with ".ZIP" or ".zip".compilationMonitor- an optionalCompilationMonitorimplementation to monitor the progress of the compilation.loadIntoRepository- iftruethe 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- iftruecompiled MIB modules will replace existing MIB modules in the MIB repository with the same module names.compileLeniently- iftruesyntax 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
CompilationResultinstances. Each instance represents an input file. For ZIP files, aCompilationResultinstance is returned for each ZIP file entry. - Throws:
IOException- if any IO operation fails when accessing the inputfiles(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:SmiCompilerCompiles an array of text or ZIP files provided asNamedInputStreams. The compilation is executed in three phases:- The provided
NamedInputStreams are loaded into memory. - The loaded files are analyzed about their module names and then sorted according to their dependencies to other modules.
- 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.
CompilationMonitorinterface.- Specified by:
compilein interfaceSmiCompiler- Parameters:
files- an array ofNamedInputStreaminstances where each instance may represent a text or ZIP file.compilationMonitor- an optionalCompilationMonitorimplementation to monitor the progress of the compilation.compilerTargetMode- with the modeSmiCompiler.TargetMode.storeIntoRepositoryAndLoadthe 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. WithSmiCompiler.TargetMode.dryRunno 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- ifSmiCompiler.Strictness.lenientis 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
CompilationResultinstances. Each instance represents an input file. For ZIP files, aCompilationResultinstance is returned for each ZIP file entry. - Throws:
IOException- if any IO operation fails when accessing the inputfiles(InputStreams).
- The provided
-
compile
public List<CompilationResult> compile(NamedInputStream[] files, CompilationMonitor compilationMonitor, boolean loadIntoRepository, boolean updateExistent, boolean compileLeniently) throws IOException Deprecated.Usecompile(NamedInputStream[], CompilationMonitor, com.snmp4j.smi.SmiCompiler.TargetMode, com.snmp4j.smi.SmiCompiler.OverwriteMode, com.snmp4j.smi.SmiCompiler.Strictness)instead which provides a cleaner interface.Compiles an array of text or ZIP files provided asNamedInputStreams. The compilation is executed in three phases:- The provided
NamedInputStreams are loaded into memory. - The loaded files are analyzed about their module names and then sorted according to their dependencies to other modules.
- 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.
CompilationMonitorinterface.- Parameters:
files- an array ofNamedInputStreaminstances where each instance may represent a text or ZIP file.compilationMonitor- an optionalCompilationMonitorimplementation to monitor the progress of the compilation.loadIntoRepository- iftruethe 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- iftruecompiled MIB modules will replace existing MIB modules in the MIB repository with the same module names.compileLeniently- iftruesyntax 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
CompilationResultinstances. Each instance represents an input file. For ZIP files, aCompilationResultinstance is returned for each ZIP file entry. - Throws:
IOException- if any IO operation fails when accessing the inputfiles(InputStreams).
- The provided
-
format
public final String format(org.snmp4j.smi.OID instanceOID, org.snmp4j.smi.Variable variable, boolean withOID) - Specified by:
formatin interfaceorg.snmp4j.util.VariableTextFormat
-
parseVariableBinding
- Specified by:
parseVariableBindingin interfaceorg.snmp4j.util.VariableTextFormat- Throws:
ParseException
-
parse
public final org.snmp4j.smi.Variable parse(org.snmp4j.smi.OID classOrInstanceOID, String text) throws ParseException - Specified by:
parsein interfaceorg.snmp4j.util.VariableTextFormat- Throws:
ParseException
-
parse
- Specified by:
parsein interfaceorg.snmp4j.util.VariableTextFormat- Throws:
ParseException
-
format
- Specified by:
formatin interfaceorg.snmp4j.util.OIDTextFormat
-
formatForRoundTrip
- Specified by:
formatForRoundTripin interfaceorg.snmp4j.util.OIDTextFormat
-
parse
- Specified by:
parsein interfaceorg.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- iftruequotes will be return as part of the returned tokens, otherwise they will be removed from the token boundaries.- Returns:
- the list of tokens.
-
getOidFormatNonPrintableStrings
Gets theSmiManager.NonPrintableStringFormatfor strings in formattedOIDs. A string is not printable if it contains any ISO control characters as defined byCharacter.isISOControl(char)except if these ISO control characters are all whitespace characters as defined byCharacter.isWhitespace(char)and not'\u001C'-'\u001F'.- Returns:
- the current format for non-printable strings.
- Since:
- 1.1
-
setOidFormatNonPrintableStrings
public void setOidFormatNonPrintableStrings(SmiManager.NonPrintableStringFormat oidFormatNonPrintableStrings) Sets theSmiManager.NonPrintableStringFormatfor strings in formattedOIDs. The default isSmiManager.NonPrintableStringFormat.asIs- Parameters:
oidFormatNonPrintableStrings- the new format for non-printable strings (must not benull).- 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:
nullif 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
Gets the SMI object defined for the specifiedOID. For SMI objects that have no OID, i.e. TEXTUAL CONVENTIONS you will have to usefindSmiObject(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
Gets the SMI object type defined for the specified instanceOID. For looking up SMI objectfrom their OID, thus without index suffix usefindSmiObject(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
SmiObjectTypethat provides information about a MIB object type. - Since:
- 1.9.14 (Pro edition only)
-
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.
SmiTextualConventioninstances must not be returned) within all loaded MIB modules. If no module with an object with OID is loaded thennullwill be returned. - Since:
- 1.2 (Pro edition only)
-
findRootSmiObject
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, thennullis returned.- Returns:
- the SmiObject with the smallest OID (which exists - i.e.
SmiTextualConventioninstances must not be returned) within the given loaded MIB module. - Since:
- 1.9 (Pro edition only)
-
findSmiModule
Gets theSmiModulewith 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
SmiModuleis also aSmiModuleIdentity!- Parameters:
moduleName- a MIB module name (e.g.SNMPv2-MIB).- Returns:
- the
SmiModulewith the module namemoduleNameornullif such a module has not been loaded yet withloadModule(String). - Since:
- 1.2 (Pro edition only)
-
findSmiModules
Gets theSmiModulethat defines the provided object identifier.For SMIv2 the returned
SmiModuleis also aSmiModuleIdentity!- Parameters:
smiObjectIdentifier- anOIDof an object that is defined by the MIB module (usage by import will not match).- Returns:
- a list of
SmiModules defining the providedOIDornullif 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 withloadModule(String)). - Since:
- 1.6 (Pro edition only)
-
findSmiObject
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 thefindSmiObject(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 recommended to use thefindSmiObject(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 (ifincludeImportedModulesis set to true).objectName- the name of the SMI object to return.includeImportedModules- iffalsethis method behaves exactly likefindSmiObject(String, String)iftruethen first the providedmoduleNameis searched for the definition of an object with the nameobjectName. If it is not found then the first import of an object with that name is used andfindSmiObject(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
Gets the SMI object defined for the specifiedOID. For SMI objects that have an OID, i.e. OBJECT-TYPE it is recommend to use thefindSmiObject(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 ornullwhen objects of all modules should be returned.filter- aSmiObjectFilterinstance 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- iftruethe message text of caught exceptions during MIB compilation will be included in the "errUnknownError" message,falseotherwise (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:
trueif the message text of caught exceptions during MIB compilation will be included in the "errUnknownError" message,falseotherwise (the default).- Since:
- 1.3 (Pro edition only)
-
setSmiErrorTextResourceBundle
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 theSmiModule.getSourceFilename()method.- Parameters:
storeFilenameInRepository- iftruefile 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
truefile names are stored, otherwise not stored at all (default). - Since:
- 1.6
-
compile(NamedInputStream[], CompilationMonitor, com.snmp4j.smi.SmiCompiler.TargetMode, com.snmp4j.smi.SmiCompiler.OverwriteMode, com.snmp4j.smi.SmiCompiler.Strictness)instead which provides a cleaner interface.