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
Constructor and Description |
---|
BSFMonitor() |
Modifier and Type | Method and Description |
---|---|
void |
log(String level,
String format,
Object... args) |
PollStatus |
poll(MonitoredService svc,
Map<String,Object> map)
This method is the heart of the plug-in monitor.
|
getEffectiveLocation, getKeyedBoolean, getKeyedInstance, getKeyedInteger, getKeyedLong, getKeyedObject, getKeyedString, getRuntimeAttributes, getServiceProperties
public PollStatus poll(MonitoredService svc, Map<String,Object> map)
This method is the heart of the plug-in monitor. Each time an interface requires a check to be performed as defined by the scheduler the poll method is invoked. The poll is passed the service to check.
By default when the status transition from up to down or vice versa the framework will generate an event. Additionally, if the polling interval changes due to an extended unavailability, the framework will generate an additional down event. The plug-in can suppress the generation of the default events by setting the suppress event bit in the returned integer.
NOTE: This method may be invoked on a Minion, in which
case certain bean and facilities will not be available. If any state related
information is required such as agent related configuration, it should retrieved
by the ServiceMonitor.getRuntimeAttributes(MonitoredService, Map)
.
svc
- Includes details about to the service being monitored.map
- Includes the service parameters defined in poller-configuration.xml and those
returned by ServiceMonitor.getRuntimeAttributes(MonitoredService, Map)
.PollStatus.SERVICE_AVAILABLE
,
PollStatus.SERVICE_UNAVAILABLE
,
PollStatus.SERVICE_AVAILABLE
,
PollStatus.SERVICE_UNAVAILABLE
Copyright © 2021. All rights reserved.