[SNMP4J] Request for help with the GETBULK request
Kulkarni, Aditya (Aditya)
kulkarni8 at avaya.com
Tue Aug 18 09:44:23 CEST 2009
Hello,
I have this problem with the GETBULK request. The response I receive is
empty.
The following is my code:
public class SimpleSnmpProgram {
public static void main(String args[]) {
System.out.println("Please enter the ip address of the SNMP agent to
be monitored:");
String ip=get_line();
ip="udp:"+ip+"/161";
Address targetAddress = GenericAddress.parse(ip);
TransportMapping transport = null;
try {
transport = new DefaultUdpTransportMapping();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Snmp snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(), new
OctetString(MPv3
.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
try {
snmp.listen();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version2c);
PDU pdu1 = new PDU();
pdu1.add(new VariableBinding(new OID("1.3.6.1.2.1.1.1")));
pdu1.add(new VariableBinding(new OID("1.3.6.1.2.1.1.2")));
pdu1.add(new VariableBinding(new OID("1.3.6.1.2.1.1.3")));
pdu1.add(new VariableBinding(new OID("1.3.6.1.2.1.1.4")));
pdu1.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5")));
pdu1.add(new VariableBinding(new OID("1.3.6.1.2.1.1.6")));
pdu1.add(new VariableBinding(new OID("1.3.6.1.2.1.1.7")));
pdu1.add(new VariableBinding(new OID(".1.3.6.1.2.1.4.14")));
pdu1.setType(PDU.GETBULK);
ResponseEvent event1 = null;
try {
event1 = snmp.send(pdu1, target);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (event1.getResponse() != null){
System.out.println("Response received from "+event1.getPeerAddress());
System.out.println("The System.Mib2 response is:");
System.out.println(event1.getResponse()+" and the request is
"+event1.getRequest());
Pattern p = Pattern.compile(" = ");
String str[] = p.split(event1.getResponse().toString());
for (int i = 1; i < str.length - 1; i++) {
// System.out.println(str[i]);
// System.out.println(str[i].indexOf(";"));
System.out.println(str[i].substring(0, str[i].indexOf(";")));
}
SysMib2 Obj1 = new SysMib2();
Obj1.setDescr(str[1].substring(0, str[1].indexOf(";")));
Obj1.setObjectID(str[2].substring(0, str[2].indexOf(";")));
Obj1.setUpTime(str[3].substring(0, str[3].indexOf(";")));
Obj1.setContact(str[4].substring(0, str[4].indexOf(";")));
Obj1.setName(str[5].substring(0, str[5].indexOf(";")));
Obj1.setLocation(str[6].substring(0, str[6].indexOf(";")));
Obj1.setServices(str[str.length - 1].substring(0,
str[str.length - 1].indexOf("]")));
System.out.println("The Object created is:"+Obj1.sysName);
}
else {
System.out.println("No Response Received. Request Timed Out");
}
}
Thanks and Regards,
Aditya
More information about the SNMP4J
mailing list