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

严 辉 gooddoog at hotmail.com
Tue Jun 6 03:09:26 CEST 2006


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/  




More information about the SNMP4J mailing list