"getRequest() of SNMPGet: Start SNMP V" + version +
" GET request for SNMP agent on \"" + remoteHost +
"\" at port \"" + port + "\".");
while (previousOID.compareTo("end") != 0) {
SnmpRequest request = null;
if (walk) {
// Walk request
//
request = session.snmpGetNextRequest(null, list);
} else {
// Get request
//
request = session.snmpGetRequest(null, list);
}
// Check for a timeout of the request
//
boolean completed =
request.waitForCompletion((maxRetries + 1) * timeOut);
if (completed == false) {
if (connectStatus.compareTo("reqTimeout") != 0) {
System.out.println(
"getRequest() of SNMPGet: Request timed out, " +
"check reachability of agent.");
// Print request
//
System.out.println(
"getRequest() of SNMPGet: Request= " +
request.toString() + ".");
rc = 1;
} else {
System.out.println(
"getRequest() of SNMPGet: Request timed out as expected.");
}
}
if (rc == 0 && completed) {
System.out.println(
"getRequest() of SNMPGet: Finish SNMP V" +
version + " GET request.");
// Now we have a response. Check if the response contains an error
//
String errorStatus = SnmpRequest.snmpErrorToString(
request.getErrorStatus());
if (errorStatus.compareTo("noError") != 0) {
System.out.println(
"getRequest() of SNMPGet: Error status= " +
errorStatus + ".");
System.out.println(
"getRequest() of SNMPGet: Error index= " +
request.getErrorIndex() + ".");
if (errorStatus.compareTo(connectStatus) == 0) {
System.out.println(
"getRequest() of SNMPGet: Get request failed as " +
"expected with " + connectStatus + " status.");
} else {
if (walk && errorStatus.compareTo("noSuchName") == 0) {
System.out.println(
"getRequest() of SNMPGet: Get request failed as " +
"expected with " + connectStatus + " status.");
} else {
System.out.println(
"getRequest() of SNMPGet: Get request should " +
"fail with " + connectStatus + " status.");
rc = 1;
}
}
previousOID = "end";
} else {
// Now we shall display the content of the result
//
SnmpVarBindList resp = request.getResponseVarBindList();
System.out.println("getRequest() of SNMPGet: Result=");
String tmpOID = "";
String realOID = "";