Package com.tailf.dp

Class DpSnmpNotifier

Object
Thread
com.tailf.dp.DpSnmpNotifier
All Implemented Interfaces:
Runnable

public class DpSnmpNotifier extends Thread
The application can send SNMP notifications and inform requests.

This class implements SNMP notification. The purpose of this class to provide a mechanism for sending SNMP notifications.

Example: 1 - Send SNMP V1 Notification.

  // int port = Conf.PORT for ConfD or Conf.NCS_PORT for NCS
  Socket s1 = new Socket("localhost", port);
  Dp dp1 = new Dp("snmp_MYNAME", s1);
  // Create notification notifier.
  // std_v1_trap must exist in notify_init.xml.
  DpSnmpNotifier notifier1 = dp1.createSnmpNotifier("std_v1_trap",
                                                    "");

  // Sense a cold start notification.
  notifier1.send("coldStart", new SnmpVarbind[] {});
 
Example 2: - Send SNMP Inform Request Using the following Snmp inform response callback:
  public class MySnmpInformResponseCallback {

      @SnmpInformResponseCallback(callPoint = "snmp_inform",
                              callType = { SnmpInformResponseCBType.TARGETS })
      public void targets(Integer ref, ConfETuple[] targets)
      throws DpCallbackException {
          // Add implementation here
      }

      @SnmpInformResponseCallback(callPoint = "snmp_inform",
                              callType = { SnmpInformResponseCBType.RESULT })
      public void result(Integer ref, ConfETuple target, Boolean gotResponse)
      throws DpCallbackException {
          // Add implementation here
      }
  }
 
We can send an Snmp inform
  // int port = Conf.PORT for ConfD or Conf.NCS_PORT for NCS
  Socket s2 = new Socket("localhost", port);
  Dp dp2 = new Dp("snmp_MYNAME", s2);
  // Register callback handling targets and result.
  MySnmpInformResponseCallback myCb = new MySnmpInformResponseCallback();

  // Create notification notifier. std_v2_notification must exist in
  // notify_init.xml and support V2
  DpSnmpNotifier notifier2 =
      dp2.createSnmpNotifier("std_v2_notification",
                             "", myCb);
  // Send SNMP inform request.
  // notif1 must exist in a MIB in the configuration.
  notifier2.send("notif",
                 new SnmpVarbind[] {
                 new SnmpVarbind("Integer32", new ConfInt32(32))},
                 10);
 
Since:
3.2.0
  • Method Details

    • getSocket

      public Socket getSocket()
      The worker socket which is connected to ConfD/NCS. This socket will be used for sending SNMP notifications to ConfD/NCS. Set when allocated by Dp through Dp.createSnmpNotifier(String, String, Object) .
    • setSocket

      public void setSocket(Socket socket)
    • getFD

      public int getFD()
      file descriptor
    • setFD

      public void setFD(int fd)
    • setSourceAddress

      public void setSourceAddress(ConfIP sourceIP)
      Set the source IP address to be bound when sending notifications using the send() method. If the sourceIP is null the source address is chosen by the IP stack of the OS.
      Parameters:
      sourceIP - ConfIPv4 or ConfIPv6 address
    • getNotifyName

      public String getNotifyName()
      The notify_init.xml notify name.
    • getContextName

      public String getContextName()
    • getInformCb

      public DpSnmpInformResponseCallback getInformCb()
      The inform callback. null means no callback.
    • send

      public void send(String notification, SnmpVarbind[] varbinds) throws ConfException
      Send SNMP notification. Sends a notification to the management targets defined for 'notifyTarget' in the snmpNotifyTable in SNMP-NOTIFICATION-MIB from the specified context. If no NotifyName is specified (or if it is ""), the notification is sent to all management targets. If the empty string is used as notification name, the notification to send is constructed from the varbinds array alone, which must then contain a value for the snmpTrapOID variable.
      Parameters:
      notification - is the notification name. For example "coldStart" or "warmStart". This symbolic name of a notification must be defined in a MIB that is loaded into the agent.
      varbinds - An array of variable bindings
      Throws:
      ConfException
      Since:
      3.2.0
    • send

      public void send(String notification, SnmpVarbind[] varbinds, Integer ref) throws ConfException
      Send SNMP notification with the option to receive an Inform Response. Sends a notification to the management targets defined for 'notifyTarget' in the snmpNotifyTable in SNMP-NOTIFICATION-MIB from the specified context. If no NotifyName is specified (or if it is ""), the notification is sent to all management targets. If the empty string is used as notification name, the notification to send is constructed from the varbinds array alone, which must then contain a value for the snmpTrapOID variable.
      Parameters:
      notification - is the notification name. For example "coldStart" or "warmStart". This symbolic name of a notification must be defined in a MIB that is loaded into the agent.
      varbinds - an array of variable bindings
      ref - a reference provided by the caller. This reference is provided provided in the callback methods on DpSnmpInformResponseCallback
      Throws:
      ConfException
      Since:
      3.2.0