[SNMP4J] Receiving snmpv3 trap using custom listener [How to?]

simon sew simonsew2000 at hotmail.com
Tue Jun 16 11:36:53 CEST 2009




Hi there,

I’ve just started learning about SNMP4j.

 

Currently I have this problem.

I would like to integrate the SNMP4j into my existing
application.

The problem now is that we have already have an existing
TCP/UDP listener.

If possible, we would like to keep it as usual.

 

I tried to bypass your listener and it works for snmp v1 and
v2c.

However when I tried with v3. It wont work. I can received
the log but it didn’t get processed.

 

Could you redirect me into the correct path.

 

Regards,

Simon

 

P/S : Here is some of the my code. (Sorry for my bad
English)

 

           
threadPool = ThreadPool.create("Trap", 2);

           
dispatcher = new
MultiThreadedMessageDispatcher(threadPool,

                       
new
MessageDispatcherImpl());

           
listenAddress =
GenericAddress.parse(System.getProperty(

                       
"snmp4j.listenAddress", "udp:0.0.0.0/0"));

 

           
if (listenAddress instanceof UdpAddress) {

                 
transport = new
DefaultUdpTransportMapping(

                             
(UdpAddress) listenAddress);

           
} else {

                 
transport = new
DefaultTcpTransportMapping(

                             
(TcpAddress) listenAddress);

           
}

 

           
snmp = new Snmp(dispatcher, transport);

           
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());

           
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());

 

     
    SecurityProtocols.getInstance().addDefaultProtocols();

           
byte[] localEngineID
= ((MPv3) snmp.getMessageProcessingModel(MessageProcessingModel.MPv3)).createLocalEngineID();

           
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(

                       
localEngineID), 0);

           
SecurityModels.getInstance().addSecurityModel(usm);

           
snmp.setLocalEngine(localEngineID,
0, 0);

 

           
usm.addUser(

                       
new OctetString("simon_user"),

                       
new UsmUser(new OctetString("simon_user"),

                       
AuthMD5.ID, 

                       
new OctetString("simon_password"),

                       
PrivDES.ID, 

                       
new OctetString("simon_des")));

           
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());

 

           
snmp.addCommandResponder(this);

 

           
//I use this to bypass the listener (works for v1,v2c not v3)

                       
((DefaultUdpTransportMapping) transport).fireProcessMessage(

                                   
new
UdpAddress(InetAddress.getByName("192.168.2.157"), 162),

                                   
bis);

 

                               
...

     
      public void
processPdu(CommandResponderEvent event) {

                               
….


_________________________________________________________________
Join the Fantasy Football club and win cash prizes here!
http://fantasyfootball.malaysia.msn.com


More information about the SNMP4J mailing list