![]() ![]() ![]() |
Can SnmpSession automatically detect the version of the SNMP agent on the other end?
I use the low-level API to perform an SNMP GET. I want to get only the String and not the message. Also, I want the string in byte format instead of hex format. What should I do?
I use SnmpString, defined in the Snmp2 package, for both String and Octet String. While decoding a response, how do we differentiate between the two? There does not seem to be a method/field in the SnmpString attribute.
I would like to use your API in a multithreaded application to collect some data. Is WebNMS SNMP API multithread safe?
What is an OCTET in terms of bits? I am trying to determine a bandwidth tilization factor and I need to figure out how to represent an OCTET or a packet in bits.
I instantiate the SnmpAPI and SnmpSession classes and various parameters, such as remoteHost, community, etc. for the session object is set. When I call Session.open(), everything works fine but the process started by the other Web-based application does not terminate. Is this because of the SNMPSession or API objects? Do I need to call close() or stop()?
How should I specify the SET value for two objects with the SYNTAX BITS and OCTET STRING object when I want to use an OCTET STRING of length 1?
Can I perform a multiple OID query? If yes, how many OIDs can I query with a single SNMP GET?
It is understood that SnmpOID only accepts dot-formatted OID strings. I would like to request SNMP values using names and dot-formatted strings. Is there a class available that can help me maintain a database of variable OIDs and names?
I always get a return for COUNTER64 in hex format. Is there a way to get a return for COUNTER64 in decimal format without performing the manual conversion?
In view of the SnmpWebNMS getNext() facility, is there a way to detect the end of the GET rather than iterating till the end of the MIB. For example: if we do a GETNEXT on .1.3.6.1.4.1.412.1.1.1.1.1.1.47 we get .1.3.6.1.4.1.412.1.1.1.1.1.1.48 which is correct. But if we do getnext() we get .1.3.6.1.4.1.412.1.1.1.1.1.2.1 Is there a way to make this return an error instead, since we are really going to the "next item"?
When I receive a PDU from the SNMP agent, how can I differentiate between a normal String and HEX-answer?
I would like to set the OID of type EntryStatus but I cannot find this type in the SnmpAPI class. What should I do? What is the byte value for this type?
How do I set UDP port explicitly for sending GET/SET/GETNEXT request?
When I ask for 10 rows in an SNMP table, the GETBULK returns only 6 rows and the last attribute of the sixth row is null. The sixth row seem to be truncated. Why is this so?
I want to use your SNMP API to build a PDU packet. Is there a way to encode the PDU packet without sending it? I do not use UDP/IP to send packets. I use my own transport mechanism. As of now, the encoding of the PDU packet is done only when I actually send it out. Do you have a separate encoding function?
The problem is that the callback method is not invoked and deadlock occurs in the application while performing the SET operation. The table row is created in host 192.168.43.221 and the OID and values are as follows.
.1.3.6.1.4.1.6251.1.1.1.1.1.1.1.3.1.1:OCTET_STRING : 1234
.1.3.6.1.4.1.6251.1.1.1.1.1.1.1.7.1.1:INTEGER : 4 (createAndGo)
.1.3.6.1.4.1.6251.1.1.1.1.1.1.1.8.1.1:OCTET_STRING:SSSSSSSSSSSSSSSSSS
If I have more than one SnmpClient in SnmpSession, the callback method of all the SnmpClients is called whenever the session receives a response. How can I tell the SnmpSession that only one of the clients should receive the response for a particular request?
If I call the syncSend method after adding an SnmpClient to SnmpSession, it returns null and the callback method that I have implemented is called. Why is the callback called when I perform a synchronous SNMP request? How can I make the syncSend return the response PDU and prevent the callbacks from being called?
1. Can SnmpSession automatically detect the version of the SNMP agent on the other end?
The SnmpSession is used to send/receive PDUs from any SNMP peer. Therefore, while sending requests, the session simply sends the PDU to the remote host with the PDU version set to the SnmpPDU version. If the SnmpPDU version is not specified, the SnmpSession version is used. The default version is v1.
In this case, you can initially send a v1 PDU by setting the SnmpPDU version to v1. Then you can send a v2 PDU and then a v3 PDU. You can use the WebNMSSNMPv3 API for sending v1/v2/v3 requests. Depending on the response, you can find out the version of the agent. If a particular version is not supported by the agent, the request times out.
2. I use the low-level API to perform an SNMP GET. I want to get only the String and not the message. Also, I want the string in byte format instead of hex format. What should I do?
The API does not have methods to return the bytes in string format. However, the SnmpVar class has the toBytes() method which returns an array of bytes. The following code snippet gets the result in string format.
byte [] b = pdu.getVariableBinding(0).getVariable().toBytes(); String bstr = ""; for(int i=0; i < b.length ; i++ ) bstr+=" " +b[i]; System.out.println(bstr); |
3. I use SnmpString, defined in the Snmp2 package, for both String and Octet String. While decoding a response, how do we differentiate between the two? There does not seem to be a method/field in the SnmpString attribute.
The SNMP variable does not contain the Textual Convention information. DisplayString is a Textual Convention but the variable is an OCTET STRING. You need to get that from the MIB information for that MIB node, based on the OID in the variable binding. From the MibNode class, you can get the syntax for the object. When the MIB is not loaded, there is no way to distinguish.
4. I would like to use your API in a multithreaded application to collect some data. Is WebNMS SNMP API multithread safe?
If you are using the low-level API, such as SnmpSession, it is multithread safe. You need to close the session to get rid of the threads.
The high-level beans, such as SnmpTarget, are not designed for multiple threads to use simultaneously. They are lightweight objects that share underlying resources such as sockets, MIBs, etc. They have data corresponding to specific requests. Therefore, create one for each thread that needs one.
The cleanup of the underlying threads happens when the Beans are garbage collected. Therefore, you need not worry about them, although you can try and force it by calling the gc() method after your beans go out of scope.
5. What is an OCTET in terms of bits? I am trying to determine a bandwidth utilization factor and I need to figure out how to represent an OCTET or a packet in bits.
An OCTET is 8 bits. SnmpPDU.getData() returns the data to be sent or received as a byte array. The length of this array gives you the packet size in bytes.
6. I instantiate the SnmpAPI and SnmpSession classes and various parameters, such as remoteHost, community, etc. for the session object is set. When I call Session.open(), everything works fine but the process started by the other Web-based application does not terminate. Is this because of the SNMPSession or API objects? Do I need to call close() or stop()?
Both SnmpAPI and SnmpSession are threads. Stop the threads to release the resources if these objects are not used. Our API has SnmpSession.close() method to stop the session thread and SnmpAPI.close() method to stop the api thread and the session threads belonging to it.
7. How should I specify the SET value for two objects with the SYNTAX BITS and OCTET STRING object when I want to use an OCTET STRING of length 1?
Set the type of the object as SnmpAPI.BITSTRING. Give the value as a string. If you want to use a string of length 1, give a single character string without quotes.
8. Can I perform a multiple OID query? If yes, how many OIDs can I query with a single SNMP GET?
You can perform SNMP GET operation with multiple OIDs. The SnmpPDU class is used for making multiple OID request. You can make about 200 requests within a single PDU. It also depends on the agent from which you request the data.
9. It is understood that SnmpOID only accepts dot-formatted OID strings. I would like to request SNMP values using names and dot-formatted strings. Is there a class available that can help me maintain a database of variable OIDs and names?
To handle named OIDs, you need to load the corresponding MIBs. The method getSnmpOID() in MibModule and MibOperations classes accepts the name and returns the corresponding SnmpOID. Refer the javadocs of the com.adventnet.snmp.mibs package for more details.
10. I always get a return for COUNTER64 in hex format. Is there a way to get a return for COUNTER64 in decimal format without performing the manual conversion?
You can get the value of the Counter64 in decimal values. The toValue() method in the SnmpCounter64 class gives you the decimal values. This method returns an object which is a two dimensional array of type signed 64-bit long.
11. In view of the SnmpWebNMS getNext() facility, is there a way to detect the end of the GET rather than iterating till the end of the MIB. For example: if we do a GETNEXT on .1.3.6.1.4.1.412.1.1.1.1.1.1.47 we get .1.3.6.1.4.1.412.1.1.1.1.1.1.48 which is correct. But if we do getnext() we get .1.3.6.1.4.1.412.1.1.1.1.1.2.1 Is there a way to make this return an error instead, since we are really going to the "next item"?
You can try performing a walk instead of GETNEXT. For example, if you walk on the system with OID .1.3.6.1.2.1.1, it fetches upto the number of children under it stops after that. There is a method named isInSubTree() which is used to detect the end of the walk for the corresponding parent node.
12. When I receive a PDU from the SNMP agent, how can I differentiate between a normal String and HEX-answer?
By default, the API displays the value of type STRING as normal strings. However, if the string has a null character, it is interpreted as an HEX string. If you want to interpret any value as an HEX string, the method toByteString() in SnmpString class is used.
13. I would like to set the OID of type EntryStatus but I cannot find this type in the SnmpAPI class. What should I do? What is the byte value for this type?
In RFC1271-MIB, the EntryStatus is defined as follows.
EntryStatus ::= INTEGER { valid(1), createRequest(2), underCreation(3), invalid(4) } |
So to perform a SET operation, you need to specify the type as SnmpAPI.INTEGER and the value should be in the set {1,2,3,4}.
14. How do I set UDP port explicitly for sending GET/SET/GETNEXT request?
You can set the UDP port by using the method setLocalPort() in SnmpSession. The method setPort() in the SnmpTrapReceiver bean can be used to receive the traps in that port. You can also set the port using SnmpAPI. You can use any port to send traps and informrequest.
15. We would like to use a GETBULK to get several rows from our SNMP table at a time. The problem is that when I ask for 10 rows, the GETBULK returns only 6 rows and the last attribute of the sixth row is null. The sixth row seem to be truncated. Why is this so?
The number of rows you get back may be limited by the PDU size permitted by your agent, manager, or transport.
16. I want to use your SNMP API to build a PDU packet. Is there a way to encode the PDU packet without sending it? I do not use UDP/IP to send packets. I use my own transport mechanism. As of now, the encoding of the PDU packet is done only when I actually send it out. Do you have a separate encoding function?
As of now, there is no separate public method to encode the PDU. Therefore, you need to use your own encoding routines. We may in future provide an encoding routine to suite your design.
17. The problem is that the callback method is not invoked and deadlock occurs in the application while performing the SET operation. The table row is created in host 192.168.43.221 and the OID and values are as follows.
.1.3.6.1.4.1.6251.1.1.1.1.1.1.1.3.1.1:OCTET_STRING : 1234
.1.3.6.1.4.1.6251.1.1.1.1.1.1.1.7.1.1:INTEGER : 4 (createAndGo)
.1.3.6.1.4.1.6251.1.1.1.1.1.1.1.8.1.1:OCTET_STRING:SSSSSSSSSSSSSSSSSS.
In SnmpPDU, you set the community as private. In SnmpSession, it is public by default. If the authenticate (pdu, writecommunity) method returns false, SnmpSession does not call the callback. Therefore, the following method is used.
SnmpSession.setWriteCommunity(java.lang.String writeCommunity) |
18. If I have more than one SnmpClient in SnmpSession, the callback method of all the SnmpClients is called whenever the session receives a response. How can I tell the SnmpSession that only one of the clients should receive the response for a particular request?
The method "addSnmpClientWithID(SnmpClient)" provided in the SnmpSession in the WebNMS SNMP API release 3.3, helps you to do this. Instead of "addSnmpClient(SnmpClient)", use "addSnmpClientWithID(SnmpClient)" to add the SnmpClient. This method returns an integer called ClientID, which is associated with this client. Therefore, whenever an asynchronous SNMP request is sent using the "send(SnmpPDU)" method, set this clientID in the PDU using the method "setClientID(int)" in SnmpPDU. By doing this, only the callback method of the SnmpClient, which corresponds to that ID is called.
The following code snippet illustrates this feature.
SnmpSession session = new SnmpSession(api); /* where api is the SnmpAPI instance. */ session.open();
int clientID = session.addSnmpClientWithID(snmpClient); /* where snmpClient is the instance of SnmpClient. */
SnmpPDU pdu = new SnmpPDU(); /* set all relevent parameters */
pdu.setClientID(clientID); session.send(pdu); /* asynchronous SNMP request */ |
19. If I call the syncSend method after adding an SnmpClient to SnmpSession, it returns null and the callback method that I have implemented is called. Why is the callback called when I perform a synchronous SNMP request? How can I make the syncSend return the response PDU and prevent the callbacks from being called?
After an SnmpClient is added to SnmpSession, all the responses received are notified to the client(s) added and the session becomes specific only to the asynchronous requests. This problem has been fixed in the release 3.3 of WebNMS SNMP API. Now even after adding an SnmpClient, a call to "syncSend" fetches you the response PDU.
|
Note:
|
![]() ![]() ![]() |