I'm encountering an issue while using SNMP4J: I have some private MIB library files, and when I load them into a MIB Browser, I can successfully resolve OIDs from SNMP Trap messages and display the correct names. However, I'm unsure how to achieve the same OID resolution in Java using SNMP4J. Does anyone know how to integrate private MIB library files into SNMP4J to correctly resolve OID names?
I attempted to use snmp4j-smi to parse MIB files, but I couldn't locate any documentation or guides on how to properly integrate and parse private MIB libraries. As an alternative, I tried using Mibble, but even after following the official documentation, I encountered errors during execution.
updated 2025/2/18 16:33
I wrote a demo program. When I use mibble to parse the file, the console will prompt the following error message:
net.percederberg.mibble.MibLoaderException: found 15 MIB loader errors
at net.percederberg.mibble.MibLoader.loadQueue(MibLoader.java:796)
at net.percederberg.mibble.MibLoader.load(MibLoader.java:602)
at net.percederberg.mibble.MibLoader.load(MibLoader.java:529)
at com.longyan.MibbleTest.loadMib(MibbleTest.java:41)
at com.longyan.MibbleTest.test(MibbleTest.java:27)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at .junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at .junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at .junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at .junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at .junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at .junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at .junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at .junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at .junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at .junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at .junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at .junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at .junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at .junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at .junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at .junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at .junit.runners.ParentRunner.run(ParentRunner.java:413)
at .junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
But my program is written according to the Mibble doc:
@Slf4j
public class MibbleTest {
private File file;
@Before
public void setup() {
file = new File("src/main/resources/mib/hh3c-alarm.mib");
}
@SneakyThrows
@Test
public void test() {
Mib mib = loadMib(file);
System.out.println(mib.getName());
}
public Mib loadMib(File file) throws IOException, MibLoaderException {
MibLoader loader = new MibLoader();
loader.addDir(file.getParentFile());
return loader.load(file);
}
}
Parsing a public mib file in the same way will get the correct content, and I'm guessing that you need to use a commercial version to parse a private mib file.