[SNMP4J] Sending v2 and v3 SNMP traps

Keary Parinis kpc7335e at yahoo.com
Mon Aug 8 04:29:55 CEST 2005


Hi,

I went through the console tools and SNMP class documenation.  I am able
to send SNMP version 1 traps to HP Openview w/out a problem.  I can't
seem to get SNMP v2 traps to send.  I pasted my code at the bottom of
this message.  Does anyone have a good example of sending v2 and v3
traps?  Thanks.

TransportMapping transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
CommunityTarget cTarget = new CommunityTarget();
cTarget.setAddress(target);
cTarget.setCommunity(new OctetString("public"));
cTarget.setRetries(2);
cTarget.setTimeout(1500);
cTarget.setVersion(SnmpConstants.version2c);
snmp.listen();
PDU pduV2 = new PDU();
pduV2.add(new VariableBinding(SnmpConstants.snmpTrapEnterprise, new OID
("1.3.6.1.4.1.37")));
pduV2.add(new VariableBinding(SnmpConstants.snmpTrapAddress));
pduV2.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID
("1.3.6.1.4.1.37.0.78")));
pduV2.add(new VariableBinding(SnmpConstants.snmpTrapCommunity, new
OctetString("public")));
pduV2.add(new VariableBinding(new OID("1.3.6.1.4.1.37.0.78"), new
OctetString("Version 2 Trap")));
pduV2.setType(PDU.TRAP);
 //this response returns null
ResponseEvent response = snmp.send(pduV2,cTarget, transport);
System.out.println(pduV2);
System.out.println(response);
snmp.close();




More information about the SNMP4J mailing list