Package com.tailf.dp
Class DpSnmpNotifier
- All Implemented Interfaces:
Runnable
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
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Method Summary
Modifier and TypeMethodDescriptionint
getFD()
file descriptorThe inform callback.The notify_init.xml notify name.The worker socket which is connected to ConfD/NCS.void
send
(String notification, SnmpVarbind[] varbinds) Send SNMP notification.void
send
(String notification, SnmpVarbind[] varbinds, Integer ref) Send SNMP notification with the option to receive an Inform Response.void
setFD
(int fd) void
void
setSourceAddress
(ConfIP sourceIP) Set the source IP address to be bound when sending notifications using the send() method.Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Method Details
-
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 throughDp.createSnmpNotifier(String, String, Object)
. -
setSocket
-
getFD
public int getFD()file descriptor -
setFD
public void setFD(int fd) -
setSourceAddress
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
The notify_init.xml notify name. -
getContextName
-
getInformCb
The inform callback. null means no callback. -
send
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
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 bindingsref
- a reference provided by the caller. This reference is provided provided in the callback methods onDpSnmpInformResponseCallback
- Throws:
ConfException
- Since:
- 3.2.0
-