Working With SNMP Traps

Table of Contents

Data Exchange with SNMP Agents

Like an SNMP Manager, RapidCMDB platform supports a small set of commands to exchange information with the SNMP agents. Some commands, such as GET, GETNEXT, SET are initiated by RapidCMDB. This is the polling mode where the SNMP agents or other SNMP Managers are polled for information by RapidCMDB. RapidCMDB also supports receiving TRAP messages from SNMP Agents. This is the listening mode.

Polling Mode

com.ifountain.rcmdb.snmp.SnmpUtil.groovy implements the commands you will need to retrieve information from SNMP Agents or other SNMP Managers. Follow the following steps to utilize these commands in your scripts:

  1. Write an on-demand or scheduled script
  2. Import the SnmpUtils class by inserting the following line at the top of your script:
    import com.ifountain.rcmdb.snmp.SnmpUtils
  3. Start invoking the static methods of the SnmpUtils class, like:
    def wlc = WirelessManager.get(name:"WM1")  // WirelessManager is a model class that stores information such as oid, community, SNMPversion, etc.
    def s = SnmpUtils.get(wlc.ipOrName, wlc.oid3, wlc.community, SnmpUtils.VERSION_2c)
    
    // read subtree and process each (snmpOut) ...
    SnmpUtils.getSubtree(sw,cdpOID,readCommunity,SnmpUtils.VERSION_2c).each { snmpOut ->
        ...
    }

Review the SnmpUtils.groovy code under ...\RapidServer\RapidSuite\src\groovy\com\ifountain\rcmdb\snmp to find out the methods supported and their arguments.

Listening Mode

Define SNMP Connection and Datasource

1. Go to the RapidCMDB admin UI  (http://....../RapidSuite/admin.gsp) to define one or more SNMP connections. This is where you will specify a name, the host and port for the SNMP Manager you will be activating within RapidCMDB which will be listening for the SNMP traps.

2. Define an SNMP datasource which will wrap the SNMP connection. 

SNMP datasource will be listening for the SNMP traps at the specified port. 

Create a Listening Script to Process Traps

The logic for processing the SNMP traps will be implemented in a listening script, which will be listening to the SNMP Datasource you have just created. When the SNMP datasource receives a trap, it will be passed into the listening script to be processed.

Add a listening script and select the corresponding SNMP datasource you have created. Script File field should contain the path information for your script file (i.e. mySNMPProcessor.groovy) in the RapidCMDB/scripts directory.

Implement the Listening Trap Processor

Listening scripts are special scripts that are registered with the external system via the RapidCMDB listening datasource framework Therefore, they need to implement some methods so that they can interact properly with the framework.

The 4 methods that each listening script must implement are: 

  • getParameters(): any configuration parameters that define how the subscription to the external system must be set up are returned in a property map
  • init(): any itialization work that must be done before subscription starts
  • cleanUp(): any finalization after the subscription is ended
  • update(Map trap): this method will be called by the RapidCMDB framework as the external system notifies RapidCMDB of any changes to the system. You will access the properties of the passed in notification in the form of a map object and implement your logic.

mySNMPProcessor.groovy

import datasource.*

// No parameters are used by the SNMP Datasource. Therefore, return an empty map.
def getParameters(){
   return [:]
}

// no need for init processing for this example
def init(){

}

// no need for cleanup processing for this example
def cleanUp(){

}

// a sample implementation where we create an Event based on the trap values. Device and Event are  
// other RapidCMDB modeled classes used in this example.
// trap has an array of Varbinds whose values are available for processing as shown 
// in the sample script below:
def update(trap){
	def currentTime = System.currentTimeMillis();
	def deviceId = trap.Varbinds[0].Value
	def eventType = trap.Varbinds[1].Value;
	def severity = trap.Varbinds[2].Value;
	def customerid = trap.Varbinds[6].Value;
	def source = trap.Agent;
	switch(eventType) {
		 case "HardDown" :
		 case "Down" :
		 case "Up" :
			def device = Device.get(deviceid:deviceId, customerid:customerid);
		   	def ipGateway = device.ipGateway;
		   	def jurisdiction = device.jurisdiction;
		   	Event.add("rstime":currentTime, "deviceid":deviceId, "eventname":eventType,
 "severity":severity, "ipgateway":ipGateway, "jurisdiction":jurisdiction, "source" :source,
 "customerid":customerid);
		   	device.status = eventType;
		   	break;
		 default: println "Need to implement trap code for new event type ${eventType}";
	 }
}
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.