FAQs - Bean Components

  1. I use SNMPv1. While using the TrapEvent's getEnterprise API, I get the OID returned as a char string (.iso.org.dod.internet.private.enterprises....). I want to have it in its numeric form (.1.3.6.1.4...). I have not accessed the class or loaded the MIB. What should I do to get the OID in its numeric form?

  2. How do I format the string values to ensure proper setting of value types Integer and Octet String while using SnmpTarget.snmpSet (String value) and SnmpTarget.snmpSet (String value, byte type). I cannot find any list of constant values to employ in this accord.

  3. While using the SnmpPoller class, if I unplug the ethernet connector on my remote SNMP device, I receive timeout errors in the java console. However, there are no data exceptions in the Pollers result adaptor. How can I receive these timeout messages from the poller?

  4. If I call the SnmpTarget.setTimeout(5), does it mean I set the timeout to 5 seconds or 5 milli-seconds? And, what do you mean by "exponentially back off"?

  5. How do I handle the timeout events separately while performing the SNMP operations?

  6. How do I perform a GET operation in the loaded MIB by using the SnmpTarget bean?

  7. I use the SnmpTrapReceiver bean and the getUpTime() primitive to access the timestamp field of the SNMP traps. But it returns an incorrect value. How can I access the PDU timestamp and/or the time_received field?

  8. The trapreceiver Bean works fine in Windows but gives the java.net.BindException error in Unix.

  9. When I load the AdventnetSnmp.jar in the Visual Cafe, some of the Beans have problem in loading. What should I do?

  10. I use SnmpTarget Bean in an application. I can see two threads, >Snmpsession() and SnmpAPI(), running after I stop using it. How do I kill these threads?

  11. How can I use the LineGraph Bean?

  12. I use the SnmpTarget Bean. What is the difference between setCommunity() and setWriteCommunity()?

  13. I construct an SnmpTarget instance (say targetA) to load all the MIB files that I need inside a function. In the same block, I create another instance (say targetB) that doesn't load any MIB. Can targetB "reference" the MIBs which targetA has already loaded? i.e. Can I use targetB to GET/SET MIBs that are loaded by targetA? If I call getMibOperations() from both targetA and targetB, do these two returned "MibOperations" objects point to same "loaded" MIB files?

  14. If the original snmpBean object (targetA) that loaded the MIBs does not exist, can targetB still access these MIBs? Besides, where are these MIBs kept after they are loaded?

  15. I construct a MibOperations object first and load all of the MIB files I need using the MibOperations instance. Then I create an SnmpTarget object without loading any MIB files. Can this SnmpTarget instance GET/SET all the MIBs that are loaded by MibOperations object?

  16. I use SnmpTarget to perform snmpRequest. After I perform an SnmpTarget.snmpSet() operation, I understand that SnmpTarget.getErrorCode() will return me the error code. How do I get the "Error Index" corresponding to the Error Index in a PDU?

  17. In case of ADSLConProfileTable, the format is Column.length.ascii whereas in case of accessing the attributes of any other table, the format is Column.primaryKey. Why is this so?

  18. When I get an SnmpOID, I can get the instance string through MibOps. Let us say I have a table indexed by a string, integer, and OID. How do I break each one of these individually from the instance using the toolkit.

  19. I use WebNMS stack for SNMP v1. While adding, updating, or deleting rows, I get "no access" exception if the table contains any read-only columns. In the code, I use the addRow method in the ClippedTable class. Should these tables be handled differently?

  20. I have two Psion Teklogix devices with tables containing three rows of information about another network device. I am able to read only one entry in the table. How do I read each row in the table and retrieve a couple of columns (say, the IP address and name)? This works fine when a manual request is made using SnmpTarget object.

  21. Which OID should I use to set a new entry in a table? The OID of the new attribute does not exist and hence there is none that I can use.

  22. Is there any limit as to the number of OIDs I can get at a time using SnmpGetList()?

  23. Why is that in SnmpRequestServer the OID list is not updated for further GETNEXT operations?

  24. (a) Is it true that different threads using a single instance of SnmpTarget/SnmpThread cause problems. (b) And do the APIs also create problems if each thread has its own instance of SnmpTarget. In other words, do they get/set any "global (static etc)" data that may interfere with each other?

  25. I use the WebNMS stack. How do I retrieve the Not Accessible columns?

 

1. I use SNMPv1. While using the TrapEvent's getEnterprise API, I get the OID returned as a char string (.iso.org.dod.internet.private.enterprises....). I want to have it in its numeric form (.1.3.6.1.4...). I have not accessed the class or loaded the MIB. What should I do to get the OID in its numeric form?

 

Even if you load the MIB using some other Bean, it is loaded in a common place and used by all the other Beans. In this case, the SnmpTrapReceiver Bean which is used in the trapreceiver application has loaded the MIB. For getting the OID in the numeric form, you can use MibOperations.getSnmpOID() which takes string argument and returns the SnmpOID and then perform an SnmpOID.toString()

Questions

 

2. How do I format the string values to ensure proper setting of value types Integer and Octet String while using SnmpTarget.snmpSet (String value) and SnmpTarget.snmpSet (String value, byte type) I cannot find any list of constant values to employ in this accord.

 

You have to load the corresponding MIBs if you have not specified the type of the objects. Our API gets the type of the object from the MIB. If you do not load the corresponding MIB, you get the error Failed, MIB node unavailable for OID..x.x.x.x.x.x.x.x.x

 

For using the methods snmpSet(String) and snmpSetList(String[]) you must load the MIB.

 

snmpSet (String, byte): You have to specify the value and the type of the object. You can find the available types in the SnmpAPI class. You can make it simpler to use as in the example, snmpset.java in the examples/low_level_api_examples/snmpapps directory. Have a look at the addvarbind() method of this example. You can reuse or modify this method according to your requirements.

 

snmpSetVariable(SnmpVar) and snmpSetVariables(SnmpVar[]) : These methods also perform SET by using SnmpVar objects. You can create the SnmpVar objects as created in addvarbind method or by using SnmpVar.createVariable(String value, byte type) method. Set the corresponding OIDs using the methods setObjectID(String) or setObjectIDList(String[])

Questions

 

3. While using the SnmpPoller class, if I unplug the ethernet connector on my remote SNMP device, I receive timeout errors in the java console. However, there are no data exceptions in the Pollers result adaptor. How can I receive these timeout messages from the poller?

 

In our SnmpSession.send, we do InetAddress.getByName(peername). If it throws unknownHostException, we print the error message. However, InetAddress.getByName itself does not throw the exception even after removing the network connection for the hosts whose IP address were found before removing the connection. This is the reason for the timeout messages you get.

You need to perform poller.setSendTimeoutEvents(true). That should send timeout events when a poll fails.

Questions

 

4. If I call the SnmpTarget.setTimeout(5), does it mean I set the timeout to 5 seconds or 5 milli-seconds? And, what do you mean by "exponentially back off"?

 

The timeout unit specified in SnmpTarget class is seconds. But in the Low Level API, the timeout unit is in milliseconds. The exponential back off occurs after the first timeout, if the retry value is greater than zero. The exponential back off we have is the timeout period doubling after each retry.

 

For example, for timeout=5 seconds and retries=3,

 

Retries Request timed out

0

5 seconds

1

15 seconds

2

35 seconds

3

75 seconds

 

Questions

 

5. How do I handle the timeout events separately while performing the SNMP operations?

 

For handling timeouts, you can set the method to target.setSendTimeoutEvents() to true. This sends timeout events if the request fails.

Questions

 

6. How do I perform a GET operation in the loaded MIB by using the SnmpTarget bean?

 

You can use the SnmpTarget.snmpGet() for scalar objects and columnar objects with instance value. For retrieving the values of a table, you can either use SnmpTarget.snmpGetBulkList() or SnmpTarget.snmpGetAllList().

 

Questions

 

7. I use the SnmpTrapReceiver bean and the getUpTime() primitive to access the timestamp field of the SNMP traps. But it returns an incorrect value. How can I access the PDU timestamp and/or the time_received field ?

 

The getUpTime() method returns the timestamp value of the trap PDU, which is the value of the variable sysUpTime of the agent when the event occurs. It is not the time when the trap is received. Currently, you cannot access the time_received field of SnmpPDU. You have to calculate it inside the receivedTrap method of your application.

Questions

 

8. The TrapReceiver bean works fine in Windows but gives the java.net.BindException error in Unix.

 

It seems that the ports you have tried are already in use. In Unix environment, ports from 0 to 1023 are reserved. Only the root has the permission to use these ports. You can give any other port numbers other than 0 to 1023. In Solaris, you can try the following workaround.

 

Call the trap receiver application in the /etc/rc3 file in the Solaris machine. The Solaris machine automatically listens to the port 162 when the machine is rebooted. When it receives the traps, the information is printed on the screen. The steps to be followed are:

When the machine is rebooted, the trapreceiver listens to traps. Whenever a new trap is received, the trapreceiver application prints the trap information on the console. We also provide a sample utility (snmptrapforwarder.java) that serves this purpose. This forwards the traps from 162 to any port greater than1023.

 

Compile the program and run as shown below.

java snmptrapforwarder <port number greater than 1023 >
 

The default destination port is 2001. Set CLASSPATH and run the application in one of the init script.

Questions

 

9. When I load the AdventnetSnmp.jar in the Visual Cafe, some of the Beans have problem in loading. What should I do?

 

Load the swingall.jar to the component library and then load the AdventnetSnmp.jar. Now, you can see that all the components of AdventnetSnmp.jar is added to the component library of the Visual cafe.

Questions

 

10. I use SnmpTarget bean in an application. I can see two threads, SnmpSession() and SnmpAPI(), running after I stop using it . How do I kill these threads?

 

The SnmpTarget Bean uses SnmpSession and SnmpAPI threads. The resources are automatically garbage collected and the SnmpServer.finalize() method does the cleanup. Unfortunately JVM takes a long time to call this method. There is no major difference in explicitly calling System.gc(). In either case, it takes around 15 minutes to release the resources.

Questions

 

11. How can I use the LineGraph bean?

 

Using the LineGraph bean, you can plot the values received from a source, say a poller. The listeners of the LineGraph Bean should be notified when the values are received. The source from where the values are received should register with the ResultListener of the LineGraph Bean. For example, if the poller is the source, then poller.addResultListener(lineGraph); calls the implementation of the setResult() method and the values are plotted.

Questions

 

12. I use the SnmpTarget bean. What is the difference between setCommunity() and setWriteCommunity()?

 

The setCommunity() method sets the community string of SNMPv1 and v2c messages for authentication. The setWriteCommunity() is used for SET operations only. The default community string is "public" and the default writeCommunity string is null. When writeCommunity is null, community itself is used for SET operations. Therefore, applications should explicitly set the writeCommunity before they can use it for SET operations.

Questions

 

13. I construct an SnmpTarget instance (say targetA) to load all the MIB files that I need inside a function. In the same block, I create another instance (say targetB) that doesn't load any MIB. Can targetB "reference" the MIBs which targetA has already loaded? i.e. Can I use targetB to GET/SET MIBs that are loaded by targetA? If I call getMibOperations() from both targetA and targetB, do these two returned "MibOperations" objects point to same "loaded" MIB files?

 

All the SNMP Beans share the MibOperations instance and therefore it can be loaded once and used by all the other Beans.

 

Questions

 

14. If the original snmpBean object (targetA) that loaded the MIBs does not exist, can targetB still access these MIBs? Besides, where are these MIBs kept after they are loaded?

 

All the SNMP Beans directly or indirectly extend or use SnmpServer which acts as a store house for all these types of resources. These resources are maintained in a static hash table. Therefore, the MIBs loaded from a beanA can be shared by the other beans, even if the Bean through which the MIBs is loaded is out of scope.

Questions

 

15. I construct a MibOperations object first and load all of the MIB files I need using the MibOperations instance. Then I create an SnmpTarget object without loading any MIB files. Can this SnmpTarget instance GET/SET all the MIBs that are loaded by MibOperations object?

 

You have to load the MIBs through any of the SNMP Beans (say target.loadMibs) and not directly through the MibOperations class. Only if you load through any one of the bean, can the other Beans share it. In this case, the MibOperations is not a Bean and therefore it cannot be used by the SnmpTarget Bean.

Questions

 

16. I use SnmpTarget to perform snmpRequest. After I perform an SnmpTarget.snmpSet() operation, I understand that SnmpTarget.getErrorCode() will return me the error code. How do I get the "Error Index" corresponding to the Error Index in a PDU?

 

To get only the error index, add a result listener and get the response in setResult() method. Then, get the PDU from the ResultEvent object received in setResult() method by using getResponse() method. Now get the error index from the PDU using getErrindex() method defined in SnmpPDU class. Refer the following code snippet.

 

public void setResult(ResultEvent e){

SnmpPDU pdu=(SnmpPDU)e.getResponse();

System.out.println("Error Index :"+pdu.getErrindex()); }

Questions

 

17. In case of ADSLConProfileTable, the format is Column.length.ascii whereas in case of accessing the attributes of any other table, the format is Column.primaryKey. Why is this so?

 

In SnmpTable, column OIDs are defined by OID+Index. Index can be any type of Integer, String, IpAddress, NetAddress, etc. In the ADSL table, it is of type Octet String. It can be of varied length. The table can have more than one index. Since the index columns are not accessible, there is a need for separating index in order to know its value.

 

Let us take for example, a table with two index columns, where both are not accessible. To separate this index columns of varied length, we need to know it's length. If length is not defined, we do not know which part of OID is index 1 and index 2. So it is represented by length+values.

Questions

 

18. When I get an Snmp OID, I can get the instance string through MibOps. Let us say I have a table indexed by a string, integer, and OID. How do I break each one of these individually from the instance using the toolkit.

 

Yes, you can split the indices from the instance string. Follow the steps sequentially.

  1. Get the instance String from MibOperations class for the SnmpOID.

  2. Get the index Nodes from MibNode class.

  3. Use this as arguments to call the decodeInstanceString method.

Now you can get all the indices from the instance string. Following is the code snippet for doing the same.

 

SnmpVarBind vb = target.snmpGetNextVariableBinding();

SnmpOID roid = vb.getObjectID();

String inst = mibOps.getInstanceString(roid);

Vector indexNodes = node.getIndexes(mibOps);

Vector v = node.getSyntax().decodeInstanceString(inst,indexNodes);

StringBuffer sb = new StringBuffer();

for (int i=0;i

MibNode indexNode = (MibNode) indexNodes.elementAt(i);

SnmpVar var = (SnmpVar)v.elementAt(i);

String s = mibOps.toString( var, mibOps.getSnmpOID(indexNode.getLabel()) );

if (var instanceof SnmpString)

{
if (indexNode.getLabel().indexOf("Address") != -1)
s = (new SnmpIpAddress(var.toBytes())).toString();

}

 

note.jpg

Note: We provide the example walk_indexes.java in examples/applications directory of our package which can help you split the indexes from instance string.

 

Questions

 

19. I use WebNMS stack for SNMP v1. While adding, updating, or deleting rows, I get "no access" exception if the table contains any read-only columns. In the code, I use the addRow method in the ClippedTable class. Should these tables be handled differently?

 

It is not possible to set the value for read-only columns. Therefore, drop the read-only columns and send the request for other columns so that you can add a row to the table which contains either the RowStatus or EntryStatus column.

Questions

 

20. I have two Psion Teklogix devices with tables containing three rows of information about another network device. I am able to read only one entry in the table. How do I read each row in the table and retrieve a couple of columns (say the IP address and name)? This works fine when a manual request is made using SnmpTarget object.

 

To get the data using SnmpTable, you have to use SnmpTableListener. SnmpTableListener has the tableChanged() method which is triggered if changes are made to the table. In other words, we generate the table event in the run method of SnmpTable. Whenever it gets a row from the agent, it notifies the listener and the tableChanged event is called and the row is printed.

 

The application has to implement this SnmpTableListener for getting the generated table events. There is no need to call the run method explicitly. The setTableOID() method starts the polling of the table automatically.

 

Also, in the SnmpTable class, the getValueAt() method returns the value at the specified cell as a String data while the input is row and column index. In this case, you have to call the run method explicitly. This takes more time if there are many rows in the table. However, if you implement the listener, it generates an event after fetching each row.

Questions

 

21. Which OID should I use to set a new entry in a table? The OID of the new attribute does not exist and hence there is none that I can use.

 

Use the OID of that column of the table and then append the instance to it. For example,

ifTable.ifIndex.1
ifTable.ifIndex.2
and so on....

Here 1 and 2 are instances.

 

To create a new row in a table, you can use the snmpset example in the examples/applications directory.

 

The command for creating a new row to an example table is as follows.

 

  1. java snmpset -m ../mibs/qbsystem.mib localhost -p 8001 qbSysAgentTrapDestFilter.172.16.1.52 2 qbSysAgentTrapDestComm.172.16.1.52 newrow qbSysAgentTrapDestRowStatus.172.16.1.52 4 -d

    Here, the new instance value is 52. This adds a new row to the table.

  2. The "snmpset_without_mib" is used to set the table entries without loading the MIB. The command for creating a new row is as follows.

    java snmpset_without_mib localhost -p 8001 .1.3.6.1.2.1.25.2.1.1.11.7.1.2.172.16.1.58 INTEGER 3 .1.3.6.1.2.1.25.2.1.1.11.7.1.3.172.16.1.58 STRING hello .1.3.6.1.2.1.25.2.1.1.11.7.1.4.172.16.1.58 INTEGER 4

    This command creates a new row with the following values.

    .1.3.6.1.2.1.25.2.1.1.11.7.1.2.172.16.1.58: 3
    .1.3.6.1.2.1.25.2.1.1.11.7.1.3.172.16.1.58: hello
    .1.3.6.1.2.1.25.2.1.1.11.7.1.4.172.16.1.58: 4

Questions

 

22. Is there any limit as to the number of OIDs I can get at a time using SnmpGetList()?

 

The SnmpGetList() method sends a single request with multiple varbinds. If the number of entries exceeds a certain limit, the size of the PDU exceeds the local constraints or the maximum message size of the manager. The maximum size of the Snmp message, which the API can encode and send, is 64kb. However, it also depends on the maximum size the agent can handle.

 

If the number of entries exceeds the limit, the agent sends the manager a GetResponse-PDU with the value of error-status field "too big ". Therefore, the restriction is on the size of the PDU and not directly on the number of varbinds sent.

 

Questions

 

23. Why is that in SnmpRequestServer the OID list is not updated for further GETNEXT operations?

 

In SnmpRequestServer, we do not update the OID and therefore we do not know the response received in the callback. To update the OID, perform the following in the setResult() method of ResultListener implementation.

 

SnmpPDU pdu =(SnmpPDU)e.getResponse();//e is the ResultEvent instance
SnmpOID oid=pdu.getObjectID(0);

 

You have to form the RequestEvent with this OID for further GETNEXT operations.

 

Questions

 

24. (a) Is it true that different threads using a single instance of SnmpTarget/SnmpThread cause problems. (b) And do the APIs also create problems if each thread has its own instance of SnmpTarget. In other words, do they get/set any "global (static etc)" data that may interfere with each other?

 

(a) Yes, it is. Some threads may try to change the OID list, which is updated for each request, when one thread is constructing the PDU for OID s in the list.

(b) No, it is not a problem because it does not share any static variables.

Questions

 

25. I use the WebNMS stack. How do I retrieve the Not Accessible columns?

 

We provide the following methods in the SnmpTable class of the beans package for getting the not-accessible table columns.

 

To get the values for the nonaccessible indices:
java.lang.String[][]
getNotAccessibleIndex()

 

To get the names of the nonaccessible index columns:
java.lang.String[]
getNotAccessibleIndexColumns()

 

note.jpg

Note: Call methods setTargetHost(), loadMibs(), and setTableOID() before calling the above methods.

 

Questions

 



Copyright © 2012, ZOHO Corp. All Rights Reserved.