From OpenNMS
Contents |
BSFMonitor - Bean Scripting Framework Monitor
Introduction
The BSFMonitor allows one to utilize any supported BSF supported scripting language to write OpenNMS Monitors. This allows you to leverage the flexibility of a scripting language to develop limited monitors, as well as prototype monitors which are later ported to pure Java. The advantage to the BSFMonitor over the GPMonitor is their is no overhead to fork(2) and run the script, as well as access to all the internal OpenNMS methods and classes.
Things to Consider
Remember that these scripts are running inside the jvm, so any language extensions that compile into object code for the platform will not be usable. An example of this shortcoming is the inability to use scripting language extensions that wrap native system libraries.
Even though the BSFMonitor does not have the overhead of fork(2) it was not designed to scale. Several liberties were taken with the design to really optimize for prototyping monitors that would later be ported to native java, or were only going to run against a limited number of nodes. BSFMonitor makes no attempts to compile or cache your scripts on startup and each time the monitor is run the script is read from the file system and recompiled.
You will need to manually copy the BSF runtime support for your particular language choice into $OPENNMS_HOME/lib in order to get BSFMonitor to recognize it.
Writing Scripts
BSFMonitor was written in a way to hide much of the OpenNMS internal object's and classes to simplify writing a script. All data available from the monitor are passed in a strings, integer and a hash. and to return data to the monitor you simply return a string. The string will either be "OK" or the reason for why the service is down.
Variables passed into the script are as follows:
- map - a Map object that contains all the various parameters passed to the monitor from the service definition in the poller-configuration.xml file
- ip_addr - the IP address that is currently being polled.
- node_id - the Node ID of the node the ip_addr belongs to
- node_label - this nodes label
- svc_name - the name of the service that is being polled
Examples
Scripts
Configuration
<service name="bsf-test" status="on" user-defined="false" interval="300000">
<parameter key="file-name" value="/opt/opennms/scripts/test.groovy" />
<parameter key="lang-class" value="groovy" />
<parameter key="bsf-engine" value="org.codehaus.groovy.bsf.GroovyEngine" />
<parameter key="file-extensions" value="groovy,gy" />
<parameter key="script_option" value="test123" />
</service>






