comtarget.setAddress(new UdpAddress(ipAddress + "/" + Settings.getInt("snmp.port", 161)));
comtarget.setRetries(2);
comtarget.setTimeout(1000);
// Create the PDU object
// Create Snmp object
Snmp snmp = new Snmp(transport);
// Iterating over map
for (Entry<Object, Object> entry : p.entrySet()) {
oidValue = entry.getValue().toString();
descr = entry.getKey().toString();
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(oidValue)));
pdu.setRequestID(new Integer32(1));
pdu.setType(PDU.GET);
try {
response = snmp.get(pdu, comtarget);
} catch (IOException e) {
}
// Process Agent Response
if (response != null) {
PDU responsePDU = response.getResponse();
if (responsePDU != null) {
int errorStatus = responsePDU.getErrorStatus();
int errorIndex = responsePDU.getErrorIndex();
String errorStatusText = responsePDU.getErrorStatusText();
if (errorStatus == PDU.noError) {
String resp = (String) responsePDU.getVariableBindings().toString();
// Split answer into OID and description
String[] helperArray = resp.replaceAll("[\\[|\\]]", "").split(" = ");
if (helperArray.length > 1) {
oid.put(descr, helperArray[1]);
//count++;
} else {
Logger.debug("SNMP: Request failed" + ": Error status = " + errorStatus + ": Error sndex = " + errorIndex + ": Error text = " + errorStatusText);
}
} else {
Logger.debug("SNMP: GetNextResponse PDU is null");
}
} else {
Logger.debug("SNMP: Timeout");
}
}
}
try {
snmp.close();
} catch (IOException e) {
Logger.error("SNMP: couldn't close connection");
}
return oid;
}