This article was written for version 6.2 of Monitor, it could work on both lower and higher version if nothing else is stated.
This article describes how to use the query handler function of mon to send passive results to OP5 Monitor. These types of passive results can be used in scripts that are not scheduled by OP5 Monitor to perform checks.
To send a passive result to OP5 Monitor we use the command 'mon qh query command run' or alternatively by writing directly to the Nagios query handler socket. Both methods are described in this how-to. The use of the mon command is more useful as a debugging tool. For working implementations where passive results are sent to the OP5 monitor, using sockets is preferred.
To send a passive result for a service using the query handler the commands looks like this:
- $(date +%s) generates a timestamp. Note that the space between the timestamp and the name of the command is significant. Leaving it out will result in an error
- PROCESS_SERVICE_CHECK_RESULT is the name of the command
- 'monitor' is the host for which to submit a passive check
- 'some_service' is the name of the service on the host.
- '0' is the check result
- 'output' is the plugin output
- The \0 after output when using the socket must be there.
In this example we will send a result to the service 'Disk usage Z:' on host 'File_server'. The check result is 'OK' with "Disk usage Z: 25Gb" as output and "'Z:' =20.00Gb;30.00;40.00" as performance output1 for building graphs.
The command output if everything is ok is
This result will look like this in op5 Monitor:
It is possible to send in passive results with multiline support. To do this we need to change the escape_html_tags=1 to escape_html_tags=0 in the file /opt/monitor/etc/cgi.cfg
To send a multiline result to op5 Monitor use the <br> tag in the output. Example:
- The performance output for the service check uses semicolon as a separator for separating results with warning and critical threshold, the same as the query handler uses to separate it's input values. This is not an issue, as the query handler stops looking at semicolons after the output starts.
It is also possible to do this for a host checks by replacing PROCESS_SERVICE_CHECK_RESULT with PROCESS_HOST_CHECK_RESULT (and there is no longer a need to specify a service).