[SNMP4J] Sending SNMP Traps using snmp4j
Frank Fock
fock at agentpp.com
Tue Apr 25 01:23:03 CEST 2006
Hi DeyB,
To send a SNMPv1 trap you can use the following example
(and/or take a look at the JavaDoc of the Snmp class):
// set target address
targetAddress =
GenericAddress.parse(System.getProperty("snmp4j.test.targetAddress",
"udp:127.0.0.1/161"));
TransportMapping transport;
if (targetAddress instanceof UdpAddress) {
transport = new DefaultUdpTransportMapping(new
UdpAddress("0.0.0.0/12000"));
}
else {
transport = new DefaultTcpTransportMapping();
}
snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(),
new
OctetString(((MPv3)snmp.getMessageProcessingModel(
MessageProcessingModel.MPv3)).createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();
PDUv1 pdu = new PDUv1();
pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.4976.99999.1.0"),
new Counter32(124445334)));
pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.4976.99999.2.0"),
new Counter64(12432624566l)));
pdu.setType(PDU.V1TRAP);
pdu.setEnterprise(new OID("1.3.6.1.4.1.4976.99999"));
pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC);
pdu.setSpecificTrap(4976);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setVersion(SnmpConstants.version1);
snmp.send(pdu, target);
Best regards,
Frank
Dey, Barnali wrote:
> Is there any sample code that shows people how to use SNMP4J to send out
> SNMP traps?
>
> i.e. how to construct PDU from the MIB and send it out to the
> destination hosts.
>
> Thanks,
> DeyB
>
>
>
>
> _______________________________________________
> 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