---
title: "Sending results using mon query handler"
description: "Sending passive results to OP5 Monitor using the mon query handler allows checks from unscheduled scripts. The guide explains using mon commands or sockets to submit service and host check results, including multiline and performance data support."
url: "https://docs.itrsgroup.com/docs/faq/op5/360020252213-op5-monitor-sending-results-using-mon-query-handler/index.html"
---
*Solutions provided by the OP5 Monitor Community for the benefit of other clients. These solutions or documents are NOT maintained, tested, or supported by ITRS Client Services and are provided as written by the original submitter.*

## Version

This article was written for version 6.2 of Monitor. It could work on both lower and higher versions 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 write 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 OP5 Monitor, using sockets is preferred.

## Service

To send a passive result for a service using the query handler, the commands look like this:

**mon**

```
$ mon qh query command run "[$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;monitor;some_service;0;output"
```

**Socket**

```
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**

```
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"
```

**Socket**

```
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 passive results with multiline support. To do this, we need to change `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 tag in the output. Example:

**mon**

```
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"
```

**Socket**

```
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

1. The performance output for the service check uses a semicolon as a separator for separating results with warning and critical thresholds, the same as the query handler uses to separate its 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 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**

```
mon qh query command run "[$(date +%s)] PROCESS_HOST_CHECK_RESULT;File_Server;0;Server is UP"
```

**Socket**

```
printf "@command run [$(date +%s)] PROCESS_HOST_CHECK_RESULT;File_Server;0;Server is UP\0" | unixcat /opt/monitor/var/rw/nagios.qh
```


