[SNMP4J] Sending SNMP Traps using snmp4j

Frank Fock fock at agentpp.com
Wed Apr 26 01:00:32 CEST 2006


Hi Alex,

I would recommend using a single Snmp instance and a single
USM. Then you can add all the user/password combinations
to that USM. If you are using the same username with
different passwords on different devices (which breaks
SNMPv3 recommended practices) then you have to use localized
users.

Best regards,
Frank

Alex Chen wrote:
> I tried to do the same thing and Frank pointed me to the code in
> org.snmp4j.tools.console.SnmpRequest.java.  It is very useful.
> 
> Thanks for the great job, Frank.
> 
> My current problem is that I want to be able to send the same V2 trap to
> different V3 targets.
> Each client has its own user and password and authentication protocol,
> i.e. MD5/SHA.
> 
> I create a TargetContext to wrap each Target with its own Snmp object
> with all the user name and authentication stuff.
> 
> When I send a trap, I loop through each target context and let the
> context gets its own Target and Snmp to send the trap.
> 
> If there is only one target, the code works fine as before, regardless
> of which target I use.
> If there are two targets, I got an
> SnmpContants.SNMPv3_USM_UNKNOWN_SECURITY_NAME error even when it tries
> to send trap to the first one.
> 
> Error while trying to send request: Message processing model 3 returned
> error: 1404
> org.snmp4j.MessageException: Message processing model 3 returned error:
> 1404
> 	at
> org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:420)
> 	at org.snmp4j.Snmp.sendMessage(Snmp.java:955)
> 	at org.snmp4j.Snmp.send(Snmp.java:794)
> 	at org.snmp4j.Snmp.send(Snmp.java:758)
> 
> Is what I am trying to do supported in Snmp4j?
> 
> -----Original Message-----
> From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On
> Behalf Of Frank Fock
> Sent: Monday, April 24, 2006 4:23 PM
> To: Dey, Barnali
> Cc: snmp4j at agentpp.org
> Subject: Re: [SNMP4J] Sending SNMP Traps using snmp4j
> 
> 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