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
Modifier and TypeClassDescriptionstatic class
Defines the format for non-printable strings in formatted object identifiers (OIDs).static class
The default formats to be applied for displayingOctetString
s.static class
The OIDFormat defines the formatting ofOID
values.Nested classes/interfaces inherited from interface com.snmp4j.smi.SmiCompiler
SmiCompiler.OverwriteMode, SmiCompiler.Strictness, SmiCompiler.TargetMode
-
Constructor Summary
ConstructorDescriptionSmiManager(String licenseKey, RepositoryDriver repositoryDriver)
Creates aSmiManager
that provides the MIB information to SNMP4J through implementations of theOIDTextFormat
andVariableTextFormat
interfaces.SmiManager(String licenseKey, File repositoryDirectory)
Creates aSmiManager
that provides the MIB information to SNMP4J through implementations of theOIDTextFormat
andVariableTextFormat
interfaces. -
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 asNamedInputStream
s.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 asFile
s.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 theSmiModule
with the specified module name.findSmiModules(org.snmp4j.smi.OID smiObjectIdentifier)
Gets theSmiModule
that 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
.format(int[] value)
format(org.snmp4j.smi.OID instanceOID, org.snmp4j.smi.Variable variable, boolean withOID)
formatForRoundTrip(int[] value)
String[]
Returns the MIB module names of the MIB modules explicitly loaded with theloadModule(String)
andcompile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness)
withSmiCompiler.TargetMode.storeIntoRepositoryAndLoad
into 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.String[]
Returns the MIB module names of the MIB modules loaded into theSmiManager
either explicitly by a previous call ofloadModule(String)
andcompile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness)
withSmiCompiler.TargetMode.storeIntoRepositoryAndLoad
or indirectly by imports of directly loaded MIB modules.Get theSmiModule
object for all loaded MIB modules.Gets the current OCTET STRING default display format.char
Gets 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.NonPrintableStringFormat
for strings in formattedOID
s.char
Gets the OID string escape character for quotes.char
Gets 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.boolean
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.boolean
isModuleLoaded(String moduleName)
Checks if the MIB module with the specified name is already loaded into the SmiManager from disk.boolean
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.String[]
Returns the MIB module names of the MIB modules available in the repository directory.boolean
loadModule(String moduleName)
Loads a MIB module from disk (MIB repository) into memory.org.snmp4j.smi.Variable
int[]
org.snmp4j.smi.Variable
org.snmp4j.smi.VariableBinding
parseVariableBinding(String text)
void
Resets the OID quotation characters and escape sequences to the default (which is highly recommended to be used).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.void
setOctetStringDisplayHint(SmiManager.OctetStringDefaultFormat octetStringDisplayHint)
Sets the display format forOctetString
values as defined by the enumerationSmiManager.OctetStringDefaultFormat
.void
setOidFixedLengthStringQuote(char oidFixedLengthStringQuote)
Sets the quote character for fixed length formatted sub-index OIDs.void
setOidFixedLengthStringQuoteEscapeSequence(String oidFixedLengthStringQuoteEscapeSequence)
Sets the sequence to escape character sequence for fixed length formatted sub-index OID quotes.void
setOidFormat(SmiManager.OIDFormat oidFormat)
Sets theSmiManager.OIDFormat
to be used to render object identifiers.void
setOidFormatNonPrintableStrings(SmiManager.NonPrintableStringFormat oidFormatNonPrintableStrings)
Sets theSmiManager.NonPrintableStringFormat
for strings in formattedOID
s.void
setOidStringQuoteEscapeCharacter(char oidStringQuoteEscapeCharacter)
Sets the OID string escape character for quotes.void
setOidVariableLengthStringQuote(char oidVariableLengthStringQuote)
Sets the quote character for variable length formatted sub-index OIDs.void
setOidVariableLengthStringQuoteEscapeSequence(String oidVariableLengthStringQuoteEscapeSequence)
Sets the sequence to escape character sequence for variable length formatted sub-index OID quotes.void
setSmiErrorTextResourceBundle(String resourceBundleClassName)
Sets the class name of the custom resource bundle for SMI error texts.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.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.boolean
unloadModule(String moduleName)
Unload a MIB module from theSmiManager
memory.int
unloadModuleWithDependencies(String moduleName)
Unload a MIB module from theSmiManager
memory, including all its dependencies that are not needed by other loaded MIB modules.
-
Constructor Details
-
SmiManager
Creates aSmiManager
that provides the MIB information to SNMP4J through implementations of theOIDTextFormat
andVariableTextFormat
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 providenull
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 therepositoryDirectory
is not accessible.
-
SmiManager
Creates aSmiManager
that provides the MIB information to SNMP4J through implementations of theOIDTextFormat
andVariableTextFormat
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
- aRepositoryDriver
instance which handles the reading and writing of MIB modules to disk, database, or other persistent storage.
-
-
Method Details
-
getOidFormat
Gets the currentSmiManager.OIDFormat
(default isSmiManager.OIDFormat.ObjectNameAndDecodedIndex4RoundTrip
).- Returns:
- the current OID format. See
setOidFormat(com.snmp4j.smi.SmiManager.OIDFormat)
.
-
setOidFormat
Sets theSmiManager.OIDFormat
to 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.OIDFormat
value.
-
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 isSmiManager.OctetStringDefaultFormat.ASCII
.
-
setOctetStringDisplayHint
Sets the display format forOctetString
values as defined by the enumerationSmiManager.OctetStringDefaultFormat
. If this value is set to anySmiManager.OctetStringDefaultFormat
other thanSmiManager.OctetStringDefaultFormat.MIB
then enumerated values (syntax INTEGER with labels) will be formatted byformat(org.snmp4j.smi.OID, org.snmp4j.smi.Variable, boolean)
as number. Otherwise aslabel(n)
wheren
is the INTEGER number andlabel
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
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 theSmiManager
either explicitly by a previous call ofloadModule(String)
andcompile(NamedInputStream[], CompilationMonitor, TargetMode, OverwriteMode, Strictness)
withSmiCompiler.TargetMode.storeIntoRepositoryAndLoad
or 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.storeIntoRepositoryAndLoad
into 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 theSmiModule
object for all loaded MIB modules.- Returns:
- the list of loaded
SmiModule
instances. - Throws:
IOException
- if the repository manager uses an IO basedRepositoryDriver
and 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 thisSmiManager
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
Unload a MIB module from theSmiManager
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
Unload a MIB module from theSmiManager
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
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
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 theRepositoryDriver
did 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 IOExceptionCompiles an array of text or ZIP files provided asFile
s. 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.
CompilationMonitor
interface.- Parameters:
files
- an array ofFile
instances where each instance may represent a text or ZIP file. ZIP file names have to end with ".ZIP" or ".zip".compilationMonitor
- an optionalCompilationMonitor
implementation to monitor the progress of the compilation.loadIntoRepository
- iftrue
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
- iftrue
compiled MIB modules will replace existing MIB modules in the MIB repository with the same module names.compileLeniently
- iftrue
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, aCompilationResult
instance is returned for each ZIP file entry. - Throws:
IOException
- if any IO operation fails when accessing the inputfiles
(InputStream
s).
-
compile
public List<CompilationResult> compile(NamedInputStream[] files, CompilationMonitor compilationMonitor, SmiCompiler.TargetMode compilerTargetMode, SmiCompiler.OverwriteMode overwriteMode, SmiCompiler.Strictness strictness) throws IOExceptionDescription copied from interface:SmiCompiler
Compiles an array of text or ZIP files provided asNamedInputStream
s. The compilation is executed in three phases:- The provided
NamedInputStream
s 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.
CompilationMonitor
interface.- Specified by:
compile
in interfaceSmiCompiler
- Parameters:
files
- an array ofNamedInputStream
instances where each instance may represent a text or ZIP file.compilationMonitor
- an optionalCompilationMonitor
implementation to monitor the progress of the compilation.compilerTargetMode
- with the modeSmiCompiler.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. WithSmiCompiler.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
- ifSmiCompiler.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, aCompilationResult
instance is returned for each ZIP file entry. - Throws:
IOException
- if any IO operation fails when accessing the inputfiles
(InputStream
s).
- The provided
-
compile
public List<CompilationResult> compile(NamedInputStream[] files, CompilationMonitor compilationMonitor, boolean loadIntoRepository, boolean updateExistent, boolean compileLeniently) throws IOExceptionDeprecated.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 asNamedInputStream
s. The compilation is executed in three phases:- The provided
NamedInputStream
s 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.
CompilationMonitor
interface.- Parameters:
files
- an array ofNamedInputStream
instances where each instance may represent a text or ZIP file.compilationMonitor
- an optionalCompilationMonitor
implementation to monitor the progress of the compilation.loadIntoRepository
- iftrue
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
- iftrue
compiled MIB modules will replace existing MIB modules in the MIB repository with the same module names.compileLeniently
- iftrue
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, aCompilationResult
instance is returned for each ZIP file entry. - Throws:
IOException
- if any IO operation fails when accessing the inputfiles
(InputStream
s).
- The provided
-
format
public final String format(org.snmp4j.smi.OID instanceOID, org.snmp4j.smi.Variable variable, boolean withOID)- Specified by:
format
in interfaceorg.snmp4j.util.VariableTextFormat
-
parseVariableBinding
public final org.snmp4j.smi.VariableBinding parseVariableBinding(String text) throws ParseException- Specified by:
parseVariableBinding
in 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:
parse
in interfaceorg.snmp4j.util.VariableTextFormat
- Throws:
ParseException
-
parse
- Specified by:
parse
in interfaceorg.snmp4j.util.VariableTextFormat
- Throws:
ParseException
-
format
- Specified by:
format
in interfaceorg.snmp4j.util.OIDTextFormat
-
formatForRoundTrip
- Specified by:
formatForRoundTrip
in interfaceorg.snmp4j.util.OIDTextFormat
-
parse
- Specified by:
parse
in 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
- iftrue
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
Gets theSmiManager.NonPrintableStringFormat
for strings in formattedOID
s. 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.NonPrintableStringFormat
for strings in formattedOID
s. 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:
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
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
SmiObjectType
that 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.
SmiTextualConvention
instances must not be returned) within all loaded MIB modules. If no module with an object with OID is loaded thennull
will 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, thennull
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
Gets theSmiModule
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 aSmiModuleIdentity
!- Parameters:
moduleName
- a MIB module name (e.g.SNMPv2-MIB
).- Returns:
- the
SmiModule
with the module namemoduleName
ornull
if such a module has not been loaded yet withloadModule(String)
. - Since:
- 1.2 (Pro edition only)
-
findSmiModules
Gets theSmiModule
that defines the provided object identifier.For SMIv2 the returned
SmiModule
is also aSmiModuleIdentity
!- Parameters:
smiObjectIdentifier
- anOID
of an object that is defined by the MIB module (usage by import will not match).- Returns:
- a list of
SmiModule
s defining the providedOID
ornull
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 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 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 or imported by (ifincludeImportedModules
is set to true).objectName
- the name of the SMI object to return.includeImportedModules
- iffalse
this method behaves exactly likefindSmiObject(String, String)
iftrue
then first the providedmoduleName
is 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 ornull
when objects of all modules should be returned.filter
- aSmiObjectFilter
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
- iftrue
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
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
- iftrue
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
-
compile(NamedInputStream[], CompilationMonitor, com.snmp4j.smi.SmiCompiler.TargetMode, com.snmp4j.smi.SmiCompiler.OverwriteMode, com.snmp4j.smi.SmiCompiler.Strictness)
instead which provides a cleaner interface.