[SNMP4J] Receiving traps and SNMPv2 security

Kazantsev, Andrey V. kazantsev at axmor.com
Thu Jun 17 07:56:42 CEST 2010


Hello,

I just started to explore SNMP4J library. My first goal is to send/receive traps/notifications using SNMPv1/v2c/v3. However I can't figure out how to set (and should I set?) community string when I listening for traps? Consider my first draft:

    UdpAddress address = new UdpAddress("127.0.0.1/162");
    TransportMapping transport = new DefaultUdpTransportMapping(address, true);
    Snmp snmp = new Snmp(transport);

    OctetString localEngineID = new OctetString(MPv3.createLocalEngineID());
    USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
    SecurityModels.getInstance().addSecurityModel(usm);
    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);

    snmp.listen();

I send arbitrary trap with snmptrap (from net-snmp package):

C:\Progs\usr\net-snmp\bin>snmptrap -c public -v 2c 127.0.0.1 "" 1.3.3.3.3.3.3.3 1.2.2.2.2.2.2 s "Trap msg"

And I get following output from my Java code:

TRAP[requestID=31893, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.1.3.0 = 420 days, 9:34:12.32; 1.3.6.1.6.3.1.1.4.1.0 = 1.3.3.3.3.3.3.3; 1.2.2.2.2.2.2 = Trap msg]]

So, it's working. But I didn't specify my community when I configured SNMP trap listener, and I DID specify community when I sent trap using snmptrap (however I can set arbitrary community and all of them will be received).

Can you explain me if my code is correct? Why snmptrap forces me to specify community and SNMP4J ignores it? Maybe there is a way to specify community for SNMP4J and it will receive only traps that sent to that community?

Thank in advance.

Andrey V. Kazantsev



More information about the SNMP4J mailing list