[SNMP4j] getTable Issues [a] version1 vs version2c [b] null pointer
Mystery Guest
fw58959 at hotmail.com
Fri Dec 2 10:11:22 CET 2005
Hello,
I am relatively new to Java but have some experience with networking.
I have written some sample Java programs using SNMP4J that do both
synchronous and asynchronous GET requests and these have worked well.
I am now trying my hand at a synchronous table get and I have run
into a couple of problems. The first problem I managed to solve but
the second one has me stumped at the moment and I am hoping that
someone could point me in the right direction to resolve it.
OS: Solaris 10 as a VMWare guest
Java: Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
SNMP4J: 1.6b
A. The first issue was that my getTable call was returning a status code
which implied a timeout. A snoop of the interface showed the
request going out and a response coming back. It was then that I noticed
I had set my version to 1 [ target.setVersion(SnmpConstants.version1); ]
If I changed the version to 2c then I started getting results I expected.
Could anyone explain why this would be so?
B. Now my getTable call is working and I am printing out the data from
each TableEvent. However, at the 19th TableEvent I am getting a
null pointer exception. The table event status code is 0 and a snoop
shows the data being returned so I am at a bit of a loss to figure out
where I have gone wrong. I think my code is OK otherwise I would have
expected a problem on the first iteration. If anyone has any hints
I would greatly appreciate it.
Output:
sol10a-colin[4]% ./runit SnmpTestTable
----- Start of Table Event -----
Table event status = 0
Index = 1
Number of columns = 11
1,"FastEthernet0/1",6,1500,100000000,"00:0d:ed:75:8f:81",1,1,0:00:45.76,2561384523,9262716
----- End of Table Event -----
----- Start of Table Event -----
Table event status = 0
Index = 2
Number of columns = 11
2,"FastEthernet0/2",6,1500,100000000,"00:0d:ed:75:8f:82",1,1,0:00:44.68,4046297721,1826102036
----- End of Table Event -----
.... snip ....
----- Start of Table Event -----
Table event status = 0
Index = 18
Number of columns = 11
18,"FastEthernet0/22",6,1500,100000000,"00:0d:ed:75:8f:96",1,1,0:00:44.78,1125561467,105822311
----- End of Table Event -----
----- Start of Table Event -----
Table event status = 0
Index = 19
Number of columns = 11
Exception in thread "main" java.lang.NullPointerException
at SnmpTestTable.main(SnmpTestTable.java:77)
Code Snippet:
// send request
List tableEventList = tableUtils.getTable(target, oidIfTable, null,
null);
// dump what we have received
Iterator tableEventIter = tableEventList.iterator();
while (tableEventIter.hasNext()) {
TableEvent tableEvent = (TableEvent)tableEventIter.next();
System.out.println(" ");
System.out.println("----- Start of Table Event -----");
System.out.println("Table event status = "+tableEvent.getStatus());
System.out.println("Index = "+tableEvent.getIndex());
System.out.println("Number of columns = " +
tableEvent.getColumns().length);
for ( int i = 0; i<tableEvent.getColumns().length; i++) {
Variable v = tableEvent.getColumns()[i].getVariable(); <== Fails
here
String value = v.toString();
switch (v.getSyntax()) {
.... the rest of this code comes from the...
.... SNMP4J sample console code in the method ...
.... CVSTableListener ....
I hope this isn't too long and that I have provided enough information.
Many thanks in advance.
./Colin
More information about the SNMP4J
mailing list