[SNMP4J] SNMP4J
Eduardo Cardone
ecardone at hynet.com.ar
Fri Apr 21 23:00:59 CEST 2006
Frank, I need your help here. I need to write an application that send
to 15 devices a lot of OIDs to poll. I'm trying to send one V1 PDU to
each device with all the OIDs defined by the user. It works OK, but I
have a problem when the user put a wrong OID in the list.
For example,
OID1= 1.3.6.1.2.1.25.2.3.1.5.1
OID2= 1.3.6.1.2.1.25.2.3.1.5.2
OID3= 1.3.6.1.2.1.25.2.3.1.5.5
But OID3 does not exist in the device.
In this example, when this happens the device return "null" for every
OID and NOT just for the wrong one.
I tryed to use GETNEXT but this command didn't return the OID that I try
to query, it return (like the name) the next element.
Can you point me any ideas?
Beste regards, Eduardo.-
<<<<<<< CODE >>>>>>>>
public void doSnmpQuery(){
if(snmpDev != null){
Address targetAddress =
GenericAddress.parse("udp:"+snmpDev.ipInfo.getIpAdrress()+"/"+snmpDev.sn
mpParam.puerto);
//logger.info("Server:"+targetAddress.toString());
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(snmpDev.snmpParam.comunidad));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1000);
// target.setVersion(SnmpConstants.version1);
target.setVersion(snmpDev.snmpParam.version - 1);
TransportMapping transport;
try{
transport = new DefaultUdpTransportMapping();
transport.listen();
}catch(IOException e){
logger.error("IOException al crear el transport",e);
return;
}
Snmp snmp = new Snmp(transport);
PDU responsePDU = null;
responsePDU = sendSnmpQuery(target, snmpDev.oidList,snmp);
// responsePDU = sendSnmpQuery(target,
((snmpOID)snmpDev.oidList.elementAt(i)).getOID(),snmp);
if (responsePDU == null) {
if (lastStatus.equals("PDU Time-out")) {
// logger.info("Error en OID ID: "+
((snmpOID)snmpDev.oidList.elementAt(i)).getQueryID()+" -- Query Timed
out");
lastStatus = "";
}
}
if (responsePDU.getErrorStatus() > 0) {
logger.info("Error:" + responsePDU.getErrorStatusText());
}
else {
// No hubo error. Imprimo el PDU.
logger.info("Respuesta OK:" + responsePDU.toString());
}
}
return;
}
private PDU sendSnmpQuery(CommunityTarget target,Vector oidList,Snmp
snmp){
// setting up target
// creating PDU
PDU pdu = new PDU();
//logger.info("Cargando OID:"+oid);
for(int i=0;i<oidList.size();i++){
pdu.add(new VariableBinding(new
OID(((snmpOID)oidList.elementAt(i)).getOID())));
}
pdu.setType(PDU.GET);
ResponseEvent response;
try {
//logger.info("Enviando PDU:"+pdu.toString());
response = snmp.send(pdu,target);
if (response.getResponse() == null) {
// request timed out
logger.error("PDU Timed-out:"+pdu.toString());
lastStatus = "PDU Time-out";
return null;
}
else {
// logger.info("Received response from: "
+response.getPeerAddress());
// dump response PDU
logger.info("Respuesta OK:" + response.getResponse());
System.out.println(response.getResponse());
return response.getResponse();
}
}
catch (IOException e) {
logger.error("IOException al enviar el PDU", e);
return null;
}
}
<<<<<<< /CODE >>>>>>>>
<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>
Hynet S.A.
Eduardo Cardone ecardone at hynet.com.ar
www: http://www.hynet.com.ar
Dir.: Av. Presidente Julio A. Roca 620 piso 12
C1067ABO - Ciudad de Buenos Aires - Argentina
Tel.: 54 (11) 5128-1000
Fax: 54 (11) 5128-1001
<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>
More information about the SNMP4J
mailing list