[SNMP4J] OID Name to OID Dot Notation and vice Versa

Garcia, Maurice Maurice_Garcia at Cable.Comcast.com
Wed Dec 18 06:00:53 CET 2013


I hope this is a trivial fix, I am really new to SNMP4J.

I simply want to simply translate an OID name to a OID dot notation.  I can find any clear documentation on how to do this.

Also do I need to compile new MIBS or simple provide the text files?

Below is just a test file to get me started

Any help Please!!!!

Thanks,

Maurice

public class SmiManagerTest {

       public static void main(String[] args) {

              SmiManager smiManager = null;

              String sLicense = "";

              try {

                  smiManager = new SmiManager(sLicense, new File("C:\\mibrepository"));
                  SNMP4JSettings.setOIDTextFormat(smiManager);
                  SNMP4JSettings.setVariableTextFormat(smiManager);

              } catch (IOException e) {
                     e.printStackTrace();
              }

              try {

                     for (String sModule : smiManager.listModules()) {
                           System.out.println("Module: " + sModule);
                     }

              } catch (IOException e) {
                     e.printStackTrace();
              }

              try {
                     smiManager.parse("sysContact.0");
              } catch (ParseException e) {
                     e.printStackTrace();
              }

              OID oOID = null;

              try {
                     oOID = new OID(smiManager.parse("sysContact.0"));
              } catch (ParseException e) {
                     e.printStackTrace();
              }

              System.out.println("OID: "  + oOID.format());

       }

}


OUTPUT:

Module: ACCOUNTING-CONTROL-MIB
Module: ADSL-LINE-EXT-MIB
Module: ADSL-LINE-MIB
Module: ADSL-TC-MIB
Module: ADSL2-LINE-MIB
Module: ADSL2-LINE-TC-MIB
Module: AGENTPP-AGENTX-MIB
Module: AGENTPP-BUILTIN-CAP
.
.
.
Module: VDSL-LINE-MIB
Module: VRRP-MIB
Module: WWW-MIB
java.text.ParseException: Could not resolve OID 'sysContact'
       at com.snmp4j.smi.SmiManager.parse(SmiManager.java:784)
       at SmiManagerTest.main(SmiManagerTest.java:42)
java.text.ParseException: Could not resolve OID 'sysContact.0'
       at com.snmp4j.smi.SmiManager.parse(SmiManager.java:784)
       at SmiManagerTest.main(SmiManagerTest.java:50)
Exception in thread "main" java.lang.NullPointerException
       at SmiManagerTest.main(SmiManagerTest.java:55)



More information about the SNMP4J mailing list