By default the SNMP Adaptor in Multi-Protocol agent supports Attribute Change Notifications. Notification will be sent to the designated recipients on any event happening on the Agent side. Change of a value in a particular attribute would generate a Trap and sent it across to the Managers. To know more about Notifications in JMX refer Sending Notifications from MBeans.
From now, SNMP Adaptor also supports Multi varbinds in Notifications. Notifications, according to this feature, will be generated and sent to the Managers for a particular varbind. This Notification will contain few other varbinds for which also the Manager would like to know the status. This has to be defined in the Agent in prior and thus the feature facilitates the generation of Notifications for multi-varbinds. To know benefits offered by Traps and Notifications in Standalone SNMP Agents refer Sending Traps and Notifications in Standalone SNMP Agent.
Steps Involved for implementing this feature
Please follow the steps given below to know about the feature implementation.
Note : Traps will be generated only if the TRAP TYPE CONSTRUCT is defined for that particular variable.
Let us assume that we are trying to send a Notification for the AdiskTable of the Agent-Sample-MIB.
By default the code gets generated as follows in the AdiskEntryExt.java file which stores the details of Notifications.
/**
* Handles the JMX Set Request for adiskName
* @param String
* @throws AgentException on error
*/
public synchronized void setAdiskName (String value )
throws AgentException {
// fill up with necessary processing
Object oldValue = adiskName;
super.setAdiskName(value);
Notification acn = new AttributeChangeNotification( hdlr.getClass().getName(),
++sequenceNumber,
new Date().getTime(),
"AttributeChanged for AdiskName",
"AdiskName",
value.getClass().getName(),
oldValue,
value);
try{
AdventNetJMXAgent.getNotifHandler(hdlr).sendNotification(acn);
}
catch(Exception e)
{
utils.debugPrintLow("Exception occured while sending trap");
}
}
This code is actually for Attribute Change Notifications. Since we require multi-varbind support in Notifications this code has to be commented. Comment the lines highlighted above and add the following piece of code in place of that.
hdlr.agent.sendTableNotification();
By adding this code the particular method sendTableNotification in the Main file will be called. The sendTableNotification method that gets generated in the Main file by default appears as follows. A similar code gets generated for a scalar group.
public void sendTableNotification ()
{
Vector varbindVector = new Vector();
Integer [] indexes={new Integer("1")};
varbindVector.addElement(trapHelper.getVarBind
("AGENT_SAMPLE_MIB_JMX:type=AgentSystemInstrumentExt","AgentSystem",
"AgentLocation"));
varbindVector.addElement(trapHelper.getVarBind
("AGENT_SAMPLE_MIB_JMX:type=UtilitiesInstrumentExt","UtilitiesXXX",
"AgentNetstat"));
varbindVector.addElement(trapHelper.getVarBind
("AGENT_SAMPLE_MIB_JMX:type=AclTable","AclTable","AclManagers",indexes));
tableNotifications(varbindVector);
}
Codes for sending Notifications with MultiVarbind Support should be added in the place specified above. Sample details have been given here.
"AGENT_SAMPLE_MIB_JMX:type=
AgentSystemInstrumentExt";
"AGENT_SAMPLE_MIB_JMX:type=
UtilitiesInstrumentExt";
"AGENT_SAMPLE_MIB_JMX:type=AdiskTable";
"AGENT_SAMPLE_MIB_JMX:type=AclTable";
Integer [] indexes={new Integer("1")};
varbindVector.addElement(trapHelper.getVarBind
("AGENT_SAMPLE_MIB_JMX:type=
AgentSystemInstrumentExt","AgentSystem",
"AgentLocation"));
varbindVector.addElement(trapHelper.getVarBind
("AGENT_SAMPLE_MIB_JMX:type=
UtilitiesInstrumentExt","UtilitiesXXX",
"AgentNetstat"));
varbindVector.addElement(trapHelper.getVarBind
("AGENT_SAMPLE_MIB_JMX:type=AclTable",
"AclTable","AclManagers",indexes));
The trapHelper class in this code helps in forming SnmpVarbinds using the parameters Object Name, Object Group and the Node Name. These snmpVarbinds are formed as a vector and parsed in the sendTableNotification method present in the main file.
A generic event type, Notification can signal any type of management event. The notification event may be used directly or sub-classed, depending on the information which needs to be conveyed with the event. Following are the subclasses of Notification which are supported by the Snmp Adaptor
AttributeChangeNotification
MonitorNotification
TableMonitorNotification
AttributeChangeNotification is sent whenever there is a change in the Attribute value. AttributeChangeNotification exposes some methods to find the following parameters.
Attribute name - Name of the attribute
Attribute type - Data type of the attribute
New value - The changed value of the attribute
Old value - The actual value of the attribute
Monitor Notification provides definitions of the Notifications sent by monitor MBeans. The following are the conditions in which Monitor Notification is sent.:
Common to all kind of monitors: The observed object is not registered in the MBean server. The observed attribute is not contained in the observed object. The type of the observed attribute is not correct. Any exception (except the cases described above) occurs when trying to get the value of the observed attribute.
Common to the counter and the gauge monitors: The threshold high or threshold low are not of the same type as the gauge (gauge monitors). The threshold or the offset or the modulus are not of the same type as the counter (counter monitors).
Counter monitors only: The observed attribute has reached the threshold value.
Gauge monitors only:
The observed attribute has exceeded the threshold high value.
The observed attribute has exceeded the threshold low value.
String monitors only:
The observed attribute has matched the "string to compare" value.
The observed attribute has differed from the "string to compare" value.
TableMonitorNotification is sent whenever there is a change in the instance value of a column. TableMonitorNotification exposes some methods to find the following parameters
Observed Attribute - The observed attribute of this Monitor Notification
Observed Column - The observed column of this Monitor Notification
Observed Object - The observed object of this Monitor Notification