Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
SmiManager smiManager;
// Define the MIB repository
smiManager = new SmiManager(null /* Put your license key here */, new MemRepositoryDriver());
// Load MIB modules from the repository
String modulePatterns = "IF-.*";
loadModules(smiManager, modulePatterns);
// Alternatively compile some new MIB specifications and load them on-the-fly:
File[] files = new File[] { new File("IF-MIB.txt") };
List<CompilationResult> result =
              compiler.compile(files, null /* no monitoring*/,
                               SmiCompiler.TargetMode.storeIntoRepositoryAndLoad,
                               SmiCompiler.OverwriteMode.overwriteIfNewer, 
                               SmiCompiler.Strictness.standard);

// Here the formatting with MIB information is finally configured in SNMP4J:
SNMP4JSettings.setOIDTextFormat(smiManager);
SNMP4JSettings.setVariableTextFormat(smiManager);
smiManager.setOidFormat(SmiManager.OIDFormat.ObjectNameAndDecodedIndex4RoundTrip);
smiManager.setOidVariableLengthStringQuote(smiManager.getOidFixedLengthStringQuote());
// Activate your own error messages (if needed), othwerwise comment out the following line:
smiManager.setSmiErrorTextResourceBundle("SampleSmiErrorResourceBundle");
 
// Use the extended features:
 
// We can cast here to SmiObjectType because we know that ifAdminStatus is an OBJECT-TYPE.
// To be 100% safe, we would have to check it with insteanceof...
SmiObjectType smiObjectType = (SmiObjectType)smiManager.findSmiObject(new OID("ifAdminStatus"));
System.out.println(smiObjectType.toString());
String description = smiObjectType.getDescription();
SmiSyntax syntax = smiObjectType.getSyntax();
String units = smiObjectType.getUnits();
...
 

...