[SNMP4J] Help me to send trap whith SNMP4J. Thanks

Frank Fock fock at agentpp.com
Tue Jun 6 21:54:33 CEST 2006


Hi Peter,

The code looks OK for sending a trap. Here Snmp.listen()
is not needed. But note that you will never receive a
response on a trap.

Check with a sniffer like Ethereal whether the trap
looks OK on the wire or check with MIB Explorer (or
another trap receiver application) if you can receive
the trap with that.

Best regards,
Frank


严 辉 wrote:
> Hi all:
>    I want to send a PDUv1 trap to server.A PDUv1 instance and a Target 
> instance have been created.
>> >/*
>> >    target.getAddress():
>> >    132.192.22.151/161 ;
>> >    pdu:
>> >    V1TRAP[reqestID=1047887225, timestamp=0:00:00.00, 
> enterprise=1.3.6.1.4.1.6884.815.3.1.1, genericTrap=0,     
> specificTrap=0, VBS[1.3.6.1.4.1.11.2.17.2.4.0 = stralarm]]
>> >*/
>     But the server dose not receive the trap. Does anyone tell me why 
> receive the trap? Thanks
>   I pasted my code at the bottom of
> this message.  Does anyone have a good example of sending traps?  Thanks
> 
> public void sendalarm(String stralarm){
>             Address targetAddress = 
> GenericAddress.parse("udp:132.192.22.151/162");
>             CommunityTarget target = new CommunityTarget();
>             target.setCommunity(new OctetString("public"));
>             target.setAddress(targetAddress);
>             target.setVersion(SnmpConstants.version1);
> 
>             PDUv1 pdu = new PDUv1();
>             pdu.setType(PDU.V1TRAP);
> 
>             OID OVO_STRING_TYPE_OID = new OID(OVO_STRING_TYPE);
>             OID OVO_ALARM_LEVEL_OID = new OID(OVO_ALARM_LEVEL);
>             OID BOCO_ENTERPRISE_OID = new OID(BOCO_ENTERPRISE);
> 
>             VariableBinding vb = new VariableBinding();
>             vb.setOid(OVO_STRING_TYPE_OID);
>             vb.setVariable(new OctetString(stralarm));
>             pdu.add(vb);
>             vb.setOid(OVO_ALARM_LEVEL_OID);
>             vb.setVariable(new OctetString("Critical"));
>             pdu.add(vb);            
> pdu.setEnterprise(BOCO_ENTERPRISE_OID);             try {
>                 DefaultUdpTransportMapping udpTransportMap=new 
> DefaultUdpTransportMapping();
>                 Snmp snmp = new Snmp(udpTransportMap);
>                 ResponseEvent response =  snmp.send(pdu, target);
>                 System.out.println("pdu:"+pdu);
>                 System.out.println("response:"+response);
>                 snmp.close();
>             } catch (Exception e) {
>               System.out.println(e);
>                 }
> }
> 
> 
> Best regards,
> Peter
> 
> _________________________________________________________________
> 免费下载 MSN Explorer:   http://explorer.msn.com/lccn/ 
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list