[SNMP4J] receiving a trap

snmp girl snmp.girl at gmail.com
Tue Apr 15 14:41:33 CEST 2008


Hi,
I wrote a program in order to receive traps , here u find the code:
#

import org.snmp4j.*;
import org.snmp4j.event.*;
import org.snmp4j.smi.*;
import org.snmp4j.transport.*;
import java.io.*;

import org.snmp4j.util.*;

public class Receivetrap {
    public static void main(String[] args)throws IOException {
    {
        Address targetAddress = GenericAddress.parse("udp:127.0.0.1/162");
        TransportMapping transport = new
DefaultUdpTransportMapping((UdpAddress) targetAddress);
        Snmp snmp = new Snmp(transport);

       snmp.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);


    }
    }
}
#

my problem is how can I print the contain of the trap

thanks a lot



More information about the SNMP4J mailing list