[SNMP4J] Creating V3 Trap using SNMP4j not showing variable binding at Trap Receiver
~Kanagavelu~
skanagavelu at gmail.com
Wed Mar 30 13:17:09 CEST 2011
Hi,
I found the issue, I shoud use TimeTicks for SysUpTime.
I used OctetString with Date :(
Thanks, :)
Velu.
On Tue, Mar 29, 2011 at 3:05 PM, ~Kanagavelu~ <skanagavelu at gmail.com> wrote:
> Hi Snmp4j,
>
> Im trying to send V3 trap to a trap receiver using the below code.
> Trap receiver is receiving V3 trap, but it doesn't show any Variable
> bindings.
> Kindly reqesting you please guide me where/what i am missing?
>
>
> public void sendTrap_Version3() {
>
> //TrasportMapping
> TransportMapping transport;
> try {
> transport = new DefaultUdpTransportMapping();
> transport.listen();
>
> //Creating SNMP object
> snmp = new Snmp(transport);
>
> //Creating USM
> USM usm = new USM(SecurityProtocols.getInstance(), new
> OctetString(MPv3.createLocalEngineID()), 0);
> SecurityModels.getInstance().addSecurityModel(usm);
>
> // Add user to the USM
> snmp.getUSM().addUser(
> new OctetString("MD5DES"),
> new UsmUser(new OctetString("MD5DES"), AuthMD5.ID, new
> OctetString("MD5DESUsrAuthPwd"), PrivDES.ID,
> new OctetString("MD5DESUsrPrivPwd")));
>
> // Create the target
> Address targetAddress = GenericAddress.parse("udp:
> 10.120.7.107/162");
> UserTarget target = new UserTarget();
> target.setAddress(targetAddress);
> target.setRetries(3);
> target.setTimeout(5000);
> target.setVersion(SnmpConstants.version3);
> target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
> target.setSecurityName(new OctetString("MD5DES"));
>
> // Create PDU
> ScopedPDU pdu = new ScopedPDU();
>
> pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new
> OctetString(new Date().toString())));
> pdu.add(new
> VariableBinding(SnmpConstants.snmpTrapOID,SnmpConstants.linkDown));
> pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new
> IpAddress("127.3.4.1")));
> pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.2.2.1.1.1"),
> new Integer32(1)));
>
> pdu.setType(ScopedPDU.TRAP);
> snmp.send(pdu, target);
>
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> }
>
More information about the SNMP4J
mailing list