Why is the last index missing from the query when using snmp4j instead of NET-SNMP?

74 Views Asked by At

Here is the snmp4j result image When I use NET-SNMP, I can get the total data,but when I use snmp4j,I find that last data is missing. It only return 8193.and getnext 8193 the responseEvent.getResponse() is null . What is the reason? The NET-SNMP command is: snmpwalk -v 2c -c 'password' ip 1.3.6.1.2.1.31.1.1.1.7 Here is the NET-SNMP result Here is the snmp4j code :

Snmp snmp = SnmpComunication.getSession(snmpTarget.getSnmpVersion());
Target target = SnmpComunication.getSnmpTarget(snmp, snmpTarget, false);
Map<String, String> resultMap = new HashMap<String, String>();
try {
PDU pdu = null;
 if (snmpTarget.getSnmpVersion() == MessageProcessingModel.MPv3) {
 pdu = new ScopedPDU();
 } else {
 pdu = new PDU();
}
pdu.setType(PDU.GETNEXT);
OID targetOId = new OID(oid);
 pdu.add(new VariableBinding(targetOId));
 boolean matched = true;
while (matched) {
ResponseEvent responseEvent = snmp.send(pdu, target);
if (responseEvent == null || responseEvent.getResponse() == null) {
log.warn(“result is null!responseEvent:{},pdu:{}”,
 JsonUtil.obj2Json(responseEvent),
 JsonUtil.obj2Json(pdu.getVariableBindings()));
break;
}
PDU response = responseEvent.getResponse();
String nextOid = null;
List<? extends VariableBinding> variableBindings = response.getVariableBindings();
for (int i = 0; i < variableBindings.size(); i++) {
VariableBinding variableBinding = variableBindings.get(i);
nextOid = variableBinding.getOid().toDottedString();
 if (nextOid.length() > oid.length() && resultMap.containsKey(nextOid.substring(oid.length() + 1))) {
 log.info(“matched false! oid:{} have same subOid:{}”, oid, nextOid);
 matched = false;
 break;
 }
if (!nextOid.startsWith(oid)) {
log.warn(“matched false!nextOid:{},oid:{}”,nextOid,oid);
 matched = false;
 break;
} else {
String varString = variableBinding.getVariable().toString();
log.info(“current oid:{},value:{}”,nextOid.substring(oid.length() + 1),varString);
resultMap.put(nextOid.substring(oid.length() + 1), varString);
}
}
if (!matched) {
break;
 }
pdu.clear();
pdu.add(new VariableBinding(new OID(nextOid)));
log.info(“next oid:{}”,nextOid);
}
return resultMap;
} catch (Exception e) {
 }
 return null;
0

There are 0 best solutions below