Version
This article was written for version 6.2 of Monitor, it could work on both lower and higher version if nothing else is stated.
About
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.
Service
To send a passive result for a service using the query handler the commands looks like this:
$ mon qh query command run "[$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;monitor;some_service;0;output"
printf "@command run [$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;monitor;some_service;0;output\0" | unixcat /opt/monitor/var/rw/nagios.qh
Where
- $(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.
mon qh query command run "[$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;File_Server;Disk usage Z:;0;Disk usage Z: 25Gb|'Z:' =20.00Gb;30.00;40.00"
printf "@command run [$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;File_Server;Disk usage Z;0;Disk usage Z: 25Gb|'Z:' =20.00Gb;30.00;40.00\0" | unixcat /opt/monitor/var/rw/nagios.qh
The command output if everything is ok is
OK:No error
This result will look like this in op5 Monitor:
Multiline
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:
mon qh query command run "[$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;File_Server;Disk usages;0;Disk usage Z: 25Gb<br>Disk usage S: 20Gb<br>Disk usage I: 10Gb"
printf "@command run [$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;File_Server;Disk usages;0;Disk usage Z: 25Gb<br>Disk usage S: 20Gb<br>Disk usage I: 10Gb\0" | unixcat /opt/monitor/var/rw/nagios.qh
Footnote
- 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.
Host
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).
mon qh query command run "[$(date +%s)] PROCESS_HOST_CHECK_RESULT;File_Server;0;Server is UP"
printf "@command run [$(date +%s)] PROCESS_HOST_CHECK_RESULT;File_Server;0;Server is UP\0" | unixcat /opt/monitor/var/rw/nagios.qh
Comments
0 comments
Please sign in to leave a comment.