[SNMP4J] Sending v2 and v3 SNMP traps
Keary Parinis
kpc7335e at yahoo.com
Tue Aug 9 15:38:15 CEST 2005
I am now able to send v2 traps. Frank's comments helped me jump the
last hurdle (Thanks man!). I was not setting sysUpTime and snmpTrapOID
in the correct order. I had a bit of trouble setting sysUpTime. First
I tried to set it to a new 32UnsignedInteger with a long value of the
current system time. I received a run-time error saying I must use a
32UnsignedInteger(I was using one). I then left it null and the trap
wouldn't send. It worked fine when I set it to 0.
Now that I have version 2 traps down, I'll move on to version 3
tomorrow. If anyone has a good example, I'd appreciate it.
Keary
> Hi,
>
> v2c notifivations do not have the snmpTrapEnterprise and
> snmpTrapAddress fields. The first two variable bindings must
> be sysUpTime.0 and snmpTrapOID.0.
>
> Best regards,
> Frank
>
>
> Keary Parinis wrote:
>
> >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();
> >
> >_______________________________________________
> >SNMP4J mailing list
> >SNMP4J at agentpp.org
> >http://lists.agentpp.org/mailman/listinfo/snmp4j
> >
> >
> >
> >
>
>
More information about the SNMP4J
mailing list