Class BSFMonitor

  • All Implemented Interfaces:
    ServiceMonitor

    public class BSFMonitor
    extends AbstractServiceMonitor

    This ServiceMonitor is designed to enable the evaluation or execution of user-supplied scripts via the Bean Scripting Framework (BSF). Scripts should indicate a status whose string value is one of: "OK" (service is available), "UNK" (service status unknown), "UNR" (service is unresponsive), or "NOK" (service is unavailable). These strings map into the status values defined in @PollStatus and are indicated differently depending on the run-type of the script in question (see below for details). Use cases: a) Evaluate an expression from a file in the filesystem. The result of the evaluation carries the status indication in this mode. As a special case for backward compatibility, a status code outside the set described above will be taken to convey that the service is unavailable, and the status code itself will be set as the reason code. If the scripting engine in use supports bean manipulation during an evaluation, then any entries put into the "times" bean will be returned for optional thresholding and/or persisting. If no entries exist in this bean upon the evaluation's return, then a single value describing the time window (in milliseconds) from just before the evaluation began until just after it returned will be substituted. This mode is the default if no "run-type" parameter is specified in the service definition or if this parameter's value is "eval". b) Execute a self-contained script from a file in the filesystem. The script must put an entry into the "results" HashMap bean with key "status" and a value from the above list of service status indications. If the script puts one or more entries into the "times" bean, then these key-value pairs will be returned for optional thresholding and/or persisting. If no entry exists in this bean with a key of "response-time", the overall response time will be substituted as the time from just before the script's execution to just after its completion. This mode is used if the service's definition contains a "run-type" parameter with a value of "exec". The following beans are declared in the script's execution context: map: A @Map allowing direct access to the list of parameters configured for the service at hand ip_addr: A @String representing the IPv4 or IPv6 address of the interface on which the polled service resides node_id: An int containing the unique identifying number from the OpenNMS configuration database of the node on whose interface the monitored service resides node_label: A @String containing the textual node label of the node on whose interface the monitored service resides svc_name: A @String containing the textual name of the monitored service bsf_monitor: The singleton instance of the @BSFMonitor class, useful primarily for purposes of logging via its log(String sev, String fmt, Object... args) method. The severity must be one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL. The format is a printf-style format string, and the args fill in the tokens. results: A @HashMap that the script may use to pass its results back to the @BSFMonitor. A status indication should be set into the entry with key "status", and for status indications other than "OK" a reason code should be set into the entry with key "reason". times: A @LinkedHashMap that the script may use to pass one or more response times back to the @BSFMonitor.

    Author:
    Jason Aras, Jeff Gehlbach, OpenNMS
    • Constructor Detail

      • BSFMonitor

        public BSFMonitor()