FAQs - MIBs API

  1. I need to generate and decode MIB table indexes. How do I use the methods decodeInstanceString(), encodeInstanceString(), getIndexes(), and getIndexes(MibOperations) for this purpose. How do I generate their parameters, and how do they relate to each other? Do these methods support augmented tables? Do these methods support IMPLIED indexes?

  2. How do I know if a table is augmented (from the interface)? How do I get a reference to the conceptual index?

  3. I use the method loadMibModules(String file) of MibOperations class to load and unload MIB modules. Is there a class that supports unloading selected or all loaded modules?

  4. In my manager application, do I need to call SnmpTarget.loadMib() to load vendor-specific private MIB files? Can I GET/SET any value without loading MIB files?

  5. I use the loadMibs() method on SnmpTarget to load the MIB definitions. This works fine but takes longer time. Is it possible to precompile the MIB files and load a binary file at run time?

  6. How do I load the MIBs in my application?

  7. How do I get the root OID and the labels of the variables?

  8. Can SNMP API return me the string value that is defined in the MIB, when I receive the response?

 

1. I need to generate and decode MIB table indexes. How do I use the methods decodeInstanceString(), encodeInstanceString(), getIndexes(), and getIndexes(MibOperations) for this purpose. How do I generate their parameters, and how do they relate to each other? Do these methods support augmented tables? Do these methods support IMPLIED indexes?

 

The two methods getIndexNames() and getIndexes() in MibNode is for getting the index name and node of the table. The getIndexNames() returns vector of indexes (as String) for the table when invoked on the entry node of the table while getIndexes() returns vector of indexes (as MibNode) when invoked on any of the column nodes of the table.

 

The encodeInstanceString() encodes an instance string based on the indexVector (vector of basic SNMP type values). The instance int array should be concatenated to the OID int array to get the complete OID. For example, the tcpConnTable has the following entry.

 

tcpConnState

established(5)

tcpConnLocalAddress

128.253.154.64

tcpConnLocalPort

23

tcpConnRemAddress

128.253.154.3

tcpConnRemPort

1111

 

In this case, assume that you wish to obtain the instance corresponding to the particular tcpConnRemAddress. The index for tcpConnTable and the indexNodes vector contain nodes corresponding to tcpConnLocalAddress, tcpConnLocalPort, tcpConnRemAddress, and tcpConnRemPort in the same order. The indexVector contains the following SnmpVar objects in the specified order.  

The return value, in this case, contains the int array containing 128.253.154.64.23.128.253.154.3.1111, the subIDs forming components of the array.

 

The decodeInstanceString() returns a vector of SnmpVar of the index nodes, given the instance string and index nodes. You can see the walk_indexes example in applications directory to use decodeInstanceString(). For augments, you need to give the index nodes vector. IMPLIED is supported. Therefore, if the last of the index node vector elements has an attached IMPLIED clause in the MIB, it is taken note of during the encoding. The AUGMENTS support is not very neat as of now. As it is at present, for an augmented node such as alphaEntry AUGMENTS betaEntry, the indexNames for alphaEntry will be the same as the indexNames for betaEntry.

Questions

 

2. How do I know if a table is augmented (from the interface)? How do I get a reference to the conceptual index?

 

For Augments you still have to give the index nodes vector. So there is not much of a difference. IMPLIED is supported. So if the last of the index node vector elements has an attached IMPLIED clause in the MIB, it will be taken note of during the encoding. The AUGMENTS support is not very neat as of now. As it is at present, for an augmented node such as alphaEntry AUGMENTS betaEntry , the indexNames for alphaEntry will be the same as the indexNames for betaEntry.

Questions

 

3. I use the method loadMibModules(String file) of MibOperations class to load and unload MIB modules. Is there a class that supports unloading selected or all loaded modules?

 

In MibOperations, you have methods unloadMibModule(String name) and unloadMibModule(MibModule module) to unload a MIB. You can also use MibBrowser to unload MIBs.

Questions

 

4. In my manager application, do I need to call SnmpTarget.loadMib() to load vendor-specific private MIB files? Can I GET/SET any value without loading MIB files?

 

If you specify the OID in the numbered format, you need not load the MIB for SNMP GET. But for SNMP SET operation, the corresponding MIB file should be loaded because it takes the type of the object from the MIB file. In the snmpset example provided in the examples/low_level_api_examples\snmpapps, we specify the type of the object also as an argument. In this case, you need not load the MIB file.

 

Therefore, if you specify the numbered OID, you need not perform SnmpTarget.loadMib() for GET, whereas for performing SET operation, loading the MIB file is a must.

 

Further, for using the methods snmpSet(String) and snmpSetList(String[]), you must load the MIB. For using snmpSet(String, byte), you need to specify the value and the type of the object. The snmpSetVariable(SnmpVar) and snmpSetVariables(SnmpVar[]) methods perform SET by using SnmpVar objects. In this case, you need not load the MIB file. If you load MIB from one Bean, it is loaded in a common place and used by all other beans.

Questions

 

5. I use the loadMibs() method on SnmpTarget to load the MIB definitions. This works fine but takes longer time. Is it possible to precompile the MIB files and load a binary file at run time?

 

We provide methods to serialize the MibModule and load from the serialized module. For very small MIB files, serialization does not help much and for larger files, the load time is decreased by 30%.

Questions

 

6. How do I load the MIBs in my application?

 

You can load MIBs in your application by using the methods loadMibModule() and loadMibModules() of the MibOperations class. You can look into the examples/low_level_api_examples/mibapps directory for more information.
The following code snippet gives the usage of the loadMibModule() method for loading MIBs.

 

MibOperations mibOps = new MibOperations();

mibOps.loadMibModules("c:\mibs\RFC1213-MIB");

//specify the name of the MIB directly

 

WebNMS SNMP API supports the following options for loading MIBs.

Please go through the Using MIBs in Applications section for more details.

Questions

 

7. How do I get the root OID and the labels of the variables?

 

If you want to get the root of a module, you need to use the getRootNode() of the MibModule class. You can get the label of a node by using the getLabel() method of the MibNode class, provided you have loaded the corresponding MIBs.

 

Questions

 

8. Can SNMP API return me the string value that is defined in the MIB, when I receive the response?

 

If you want to view the enumerated label for the output value, you have to load the MIB in the receiver side.

 

MibOperations mibOps = new MibOperations();

mibOps.loadMibModules("mib file");

 

For example, if you have SnmpVarBind and if the output value is major(3), you can get the required String as follows.

 

mibOps.toString(snmpvarbind));

 

This will return MySeverity:-->major(3).

 

If you want only the enumeration label, then use the following code.

 

SnmpInt in = (SnmpInt)snmpvarbind.getVariable();

MibNode mn = mibOps.getMibNode(snmpvarbind.getObjectID().toString());

LeafSyntax ls = mn.getSyntax();

 

ls.getLabel(in.intValue()) will give you the enumeration label "major".

 

Questions

 

 



Copyright © 2012, ZOHO Corp. All Rights Reserved.