[SNMP4J] RE: Trying to send out SNMP Trap

Jim Chan jchan at incognito.com
Mon Mar 17 22:05:20 CET 2008


Hi,

I've been playing around with SNMP4J for the last week and I am trying to figure out how to register SNMP notifications and statistics.

What I've done so far:

Server side:

I used MIB designer to create a MIB of one Counter32 object type and one NotificationType.  The MIB is well formed since MIB explorer can parse it.

I used AgentPro to generate source code from the MIB.  It created one managed object and one notification event method.  I registered the managed objects with the server using generated source.  I modified the TestAgent class to use a Timer to call fireTrap().

  public static final OID oidTestCounter32 = 
    new OID(new int[] { 1,3,6,1,4,1,3606,7,18,1,1,1,0 });

  public static final OID oidTestTrap =
    new OID(new int[] { 1,3,6,1,4,1,3606,7,18,5,1,2 });  

  protected void registerManagedObjects()
  {      
    MOScalar ismpNumberOfCompServices = new MOScalar(oidTestCounter32, 
        MOAccessImpl.ACCESS_READ_ONLY, new Counter32(100)); 
    
    try
    {    
      server.register(ismpNumberOfCompServices, getDefaultContext());          
    }
    catch (DuplicateRegistrationException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  public void fireTrap()
  {
    notificationOriginator.notify(
      new OctetString(), oidTestTrap, new VariableBinding[0]);
  }

Client Side:

  private static class TrapPrinter implements CommandResponder
  {
    public synchronized void start()
    {
      try
      {
        UdpAddress address = new UdpAddress("127.0.0.1/162");
        TransportMapping transport = new 
          DefaultUdpTransportMapping(address);
        Snmp snmp = new Snmp(transport);
        snmp.addCommandResponder(new TrapPrinter());
        transport.listen();        
        try
        {
          wait();
        }
        catch (InterruptedException e)
        {
          e.printStackTrace();
        }        
      }      
      catch (IOException e)
      {
        e.printStackTrace();
      }   
    }
    
    public synchronized void processPdu(CommandResponderEvent e) 
    {
      PDU command = e.getPDU();
      if (command != null) 
      {
         System.out.println("***********" + command.toString());
      }
      notifyAll();
    }
  }


The stack trace from the server indicates that trap was sent:

2008-20-17 13:03:17 [INFO] <Timer-0> Firing SNMP trap 1.3.6.1.4.1.3606.7.18.5.1.2   
2008-20-17 13:03:17 [INFO] <Timer-0> Notification 1.3.6.1.4.1.3606.7.18.5.1.2 issued with [1.3.6.1.4.1.3606.7.18.1.2.1.0 = 88]
2008-20-17 13:03:17 [DEBUG] <Timer-0> VACM access requested for context=, securityName=SHADES, securityModel=3, securityLevel=3, viewType=0, OID=1.3.6.1.4.1.3606.7.18.5.1.2
2008-20-17 13:03:17 [DEBUG] <Timer-0> Found group name 'v3group' for secName 'SHADES and secModel 3
2008-20-17 13:03:17 [DEBUG] <Timer-0> Got views [DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.3.3,values=[1, fullReadView, fullWriteView, fullNotifyView, 3, 1]] for group name 'v3group'
2008-20-17 13:03:17 [DEBUG] <Timer-0> Matching view found for group name 'v3group' is 'fullNotifyView'
2008-20-17 13:03:17 [DEBUG] <Timer-0> Access allowed for view 'fullNotifyView' by subtree 1.3 for OID 1.3.6.1.4.1.3606.7.18.5.1.2
2008-20-17 13:03:17 [DEBUG] <Timer-0> VACM access requested for context=, securityName=SHADES, securityModel=3, securityLevel=3, viewType=0, OID=1.3.6.1.4.1.3606.7.18.1.2.1.0
2008-20-17 13:03:17 [DEBUG] <Timer-0> Found group name 'v3group' for secName 'SHADES and secModel 3
2008-20-17 13:03:17 [DEBUG] <Timer-0> Got views [DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.3.3,values=[1, fullReadView, fullWriteView, fullNotifyView, 3, 1]] for group name 'v3group'
2008-20-17 13:03:17 [DEBUG] <Timer-0> Matching view found for group name 'v3group' is 'fullNotifyView'
2008-20-17 13:03:17 [DEBUG] <Timer-0> Access allowed for view 'fullNotifyView' by subtree 1.3 for OID 1.3.6.1.4.1.3606.7.18.1.2.1.0
2008-20-17 13:03:17 [DEBUG] <Timer-0> RFC3414 §3.1.4.b Outgoing message is not encrypted
2008-20-17 13:03:17 [DEBUG] <Timer-0> Adding cache entry: StateReference[msgID=1890325769,pduHandle=PduHandle[1564352329],securityEngineID=,securityModel=org.snmp4j.security.USM at e7f6eb,securityName=SHADES,securityLevel=1,contextEngineID=,contextName=]
2008-20-17 13:03:17 [DEBUG] <Timer-0> Running pending sync request with handle PduHandle[1564352329] and retry count left 10
2008-20-17 13:03:17 [DEBUG] <Timer-0> Sending message to 192.168.75.108/162 with length 61: 30:3b:02:01:03:30:11:02:04:70:ac:15:09:02:03:00:ff:ff:04:01:04:02:01:03:04:10:30:0e:04:00:02:01:00:02:01:00:04:00:04:00:04:00:30:11:04:00:04:00:a6:0b:02:01:00:02:01:00:02:01:00:30:00

Stack Trace from the client indicates it received the trap but an error occurred:

Mar 17, 2008 1:20:12 PM org.snmp4j.log.JavaLogAdapter log
INFO: UDP receive buffer size for socket 192.168.75.108/162 is set to: 8192
Mar 17, 2008 1:20:20 PM org.snmp4j.log.JavaLogAdapter log
SEVERE: RFC3412 §7.2.4 - Unsupported security model: 3

I then tried replacing the notification target on the server with :

  targetMIB.addTargetParams(
        new OctetString("v2c"), MessageProcessingModel.MPv2c,
        SecurityModel.SECURITY_MODEL_SNMPv2c, new OctetString("cpublic"),
        SecurityLevel.NOAUTH_NOPRIV, StorageType.permanent);

But then the server couldn't send out the trap anymore

2008-02-17 14:03:09 [INFO] <Timer-0> Firing SNMP trap 1.3.6.1.4.1.3606.7.18.5.1.2   
2008-02-17 14:03:09 [INFO] <Timer-0> Notification 1.3.6.1.4.1.3606.7.18.5.1.2 issued with [1.3.6.1.4.1.3606.7.18.1.2.1.0 = 88]
2008-02-17 14:03:09 [DEBUG] <Timer-0> VACM access requested for context=, securityName=cpublic, securityModel=2, securityLevel=1, viewType=0, OID=1.3.6.1.4.1.3606.7.18.5.1.2
2008-02-17 14:03:09 [DEBUG] <Timer-0> Found group name 'v1v2group' for secName 'cpublic and secModel 2
2008-02-17 14:03:09 [DEBUG] <Timer-0> Got views [DefaultMOMutableRow2PC[index=9.118.49.118.50.103.114.111.117.112.6.112.117.98.108.105.99.0.1,values=[1, fullReadView, fullWriteView, fullNotifyView, 3, 1]] for group name 'v1v2group'
2008-02-17 14:03:11 [WARN] <Timer-0> Access denied by VACM for 1.3.6.1.4.1.3606.7.18.5.1.2

I am stumped right now on how to send out a trap/inform.  I am probably not configuring the traps correctly.  Any help would be greatly appreciated.  Thanks.

Jim Chan
 



More information about the SNMP4J mailing list