BSF detector The BSF Detector lets you run arbitrary scripts using the Bean Scripting Framework to determine the existence of a service. This can be a script written in any of the languages BSF supports. The only requirement is that the script returns the string OK if it passes. The BSF Detector passes the map, ip_addr, svc_name, and results variables as beans to the script. Detector facts Implementation org.opennms.netmgt.provision.detector.bsf.BSFDetector Configuration and Use Table 1. Parameters for the BSF detector Parameter Description Required Default value fileName The path to the file on the OpenNMS server which contains the BSF-compatible script to run. optional langClass The short name of the language the script is written in. Choices: jython, beanshell, groovy, etc. optional bsfEngine The BSF engine to use when running the script. Choices: * bsh.util.BeanShellBSFEngine * org.codehaus.groovy.bsf.GroovyEngine * org.apache.bsf.engines.jython.JythonEngine optional fileExtensions A comma-separated list of file extensions to consider a valid script for this BSF instance. optional runType Mode to run the BSF script. Choices: * eval - expects the script to print the OK/NOK status for validation * exec - expects the script to manipulate the provided results hashmap directly optional eval Avoid non-character names for parameters to avoid problems in the script languages. Timeout and Retry The BSFDetector does not perform any timeout or retry processing on its own. If you require retry and/or timeout behavior, you must implement it in the script itself. Requirements for the script (run-types) Depending on the run-type, the script must provide its results in different ways. For minimal scripts with simple logic, a run-type of eval is the easiest option. Scripts running in eval mode must return a string matching a status code of OK or NOK. A script with more than one line of logic requires a run-type of exec. Scripts running in exec mode need not return anything, but they have to add a status entry with a status code to the results object. Additionally, the results object can also carry a "reason":"message" entry that is used in non OK states. Commonly used language settings The BSF detector supports many languages. The following table provides the required setup for commonly used languages. Table 2. BSF language setups Language lang-class bsf-engine required library BeanShell beanshell bsh.util.BeanShellBSFEngine supported by default Groovy groovy org.codehaus.groovy.bsf.GroovyEngine groovy-all-[version].jar Jython jython org.apache.bsf.engines.jython.JythonEngine jython-[version].jar Example configurations BeanShell example BeanShell example <detector name="MinimalBeanShell" class="org.opennms.netmgt.provision.detector.bsf.BSFDetector"> <parameter key="bsfEngine" value="bsh.util.BeanShellBSFEngine"/> <parameter key="langClass" value="beanshell"/> <parameter key="fileName" value="/opt/opennms/etc/scripts/MinimalBeanShell.bsh"/> <parameter key="runType" value="eval"/> </detector> BeanShell example MinimalBeanShell.bsh script file File testFile = new File("/tmp/TestFile"); if (testFile.exists()) { return "OK"; } else { results.put("reason", "file does not exist"); return "NOK"; } Groovy example Groovy example for run-type eval <detector name="MinimalGroovy" class="org.opennms.netmgt.provision.detector.bsf.BSFDetector"> <parameter key="bsfEngine" value="org.codehaus.groovy.bsf.GroovyEngine"/> <parameter key="langClass" value="groovy"/> <parameter key="fileName" value="/opt/opennms/etc/scripts/MinimalGroovy.groovy"/> <parameter key="runType" value="eval"/> </detector> Groovy example MinimalGroovy.groovy script file for run-type eval File testFile = new File("/tmp/TestFile"); if (testFile.exists()) { return "OK"; } else { results.put("reason", "file does not exist"); return "NOK"; } Groovy example for run-type exec <detector name="MinimalGroovy" class="org.opennms.netmgt.provision.detector.bsf.BSFDetector"> <parameter key="bsfEngine" value="org.codehaus.groovy.bsf.GroovyEngine"/> <parameter key="langClass" value="groovy"/> <parameter key="fileName" value="/opt/opennms/etc/scripts/MinimalGroovy.groovy"/> <parameter key="runType" value="exec"/> </detector> Groovy example MinimalGroovy.groovy script file for run-type exec def testFile = new File("/tmp/TestFile"); if (testFile.exists()) { results.put("status", "OK") } else { results.put("reason", "file does not exist"); results.put("status", "NOK"); } Jython example The Jython (Java implementation of Python) language requires an additional library. Copy a compatible jython-x.y.z.jar into the opennms/lib folder and restart Horizon to make Jython available for the BSF Detector. Jython example for run-type exec <detector name="MinimalJython" class="org.opennms.netmgt.provision.detector.bsf.BSFDetector"> <parameter key="bsfEngine" value="org.apache.bsf.engines.jython.JythonEngine"/> <parameter key="langClass" value="jython"/> <parameter key="fileName" value="/opt/opennms/etc/scripts/MinimalJython.py"/> <parameter key="runType" value="exec"/> </detector> Jython example MinimalJython.py script file for run-type exec from java.io import File if (File("/tmp/TestFile").exists()): results.put("status", "OK") else: results.put("reason", "file does not exist") results.put("status", "NOK") We have to use a run type of exec here because Jython chokes on the import keyword in eval mode. BGP Session Detector DNS Service Detector