Data Exchange with SNMP AgentsLike 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 Modecom.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:
Review the SnmpUtils.groovy code under ...\RapidServer\RapidSuite\src\groovy\com\ifountain\rcmdb\snmp to find out the methods supported and their arguments. Listening ModeDefine SNMP Connection and Datasource1. 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 TrapsThe 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 ProcessorListening 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:
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}"; } } |
Add Comment