[SNMP4J] Help(In receiving traps)

Dheeraj Joshi M dheeraj at tataelxsi.co.in
Sat Jul 4 10:40:38 CEST 2009


Hi, I am new to SNMP and stuffs related to it.
 
I want to create a SNMP trap receiver which receives the trap and processes its information to database.
 
I am right now trying to get traps from the simulator. For that i got a code it is,
 
class SNMPGet
{
    void get()
    {
        try
        {
            Address targetAddress = GenericAddress.parse("udp:127.0.0.1/162");
            TransportMapping transport = new DefaultUdpTransportMapping();
            Snmp snmp = new Snmp(transport);
            USM usm = new USM(SecurityProtocols.getInstance(),
                     new OctetString(MPv3.createLocalEngineID()), 0);
            SecurityModels.getInstance().addSecurityModel(usm);
            transport.listen();
            CommandResponder trapPrinter = new CommandResponder() 
            {
                public synchronized void processPdu(CommandResponderEvent e) 
                {
                    PDU command = e.getPDU();
                    if (command != null) 
                    {
                        System.out.println(command.toString());
                    }
                }
            };
            snmp.addCommandResponder(trapPrinter);
           }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
            
    }
}
 
When i run this code nothing is working. It gives build successful.
I am listening to port 162 of localhost. and simulator is also in the localhost.
 
What mistake in the code i am doing?
Why no traps are received.
I can process the PDU's only if i get them.
 
Please help, is there any addition i need to do to the code?
 
And one more stuff why targetaddress is never used in the code?
Is that is the problem?
 
Waiting for a help.
Regards,
Dheeraj Joshi M




More information about the SNMP4J mailing list