---
title: "Running a reverse or negated service check"
description: "Reverse or negated service checks return opposite result codes for monitoring conditions like bandwidth thresholds. The Negate plugin enables this by running checks from /opt/plugins and optionally changing output text with the -s flag."
url: "https://docs.itrsgroup.com/docs/faq/op5/9222590340509-op5-monitor-running-a-reverse-or-negated-service-check/index.html"
---
Some scenarios require the use of a reverse or negated service check. An example of this would be when monitoring network bandwidth to ensure it is meeting certain specifications, such as returning OK when the bandwidth is at 500 Mbps and returning a WARNING when the bandwidth dips below 400 Mbps.

## The Negate plugin

The [Negate plugin](https://docs.itrsgroup.com/docs/op5-monitor/current/topics/plugins/plugin-reference.html#negate) will be useful in instances like this as it is able to reverse or negate the result code being returned by a regular check.

## Considerations

The plugin has some considerations that need to be taken into account when being used.

1. The negate plugin can only run plugins located in the */opt/plugins* directory. This is for security concerns, to prevent users from using it to run system commands (such as though that are run through *sudo*). An error will be shown if the plugin being run is not in the */opt/plugins* directory.

```
[root@op5-system ~]# asmonitor /opt/plugins/negate "$(which cat) /etc/passwd"
negate: Can only be used with plugins from /opt/plugins/
```

2. The plugin, by default, only changes the result code of the plugin it is negating.

On a normal run of check\_ping, the result code is '2', corresponding to CRITITCAL.

```
[root@op5-system ~]# asmonitor /opt/plugins/check_ping -H 172.16.20.69
CRITICAL - 172.16.20.69: rta nan, lost 100%|rta=0.000ms;200.000;500.000;0; pl=100%;40;80;;
[root@op5-system ~]# echo $?
2
```

When run through the negate plugin, the result code is changed but the output text is not.

```
[root@op5-system ~]# asmonitor /opt/plugins/negate /opt/plugins/check_ping -H 172.16.20.69
CRITICAL - 172.16.20.69: rta nan, lost 100%|rta=0.000ms;200.000;500.000;0; pl=100%;40;80;;
[root@op5-system ~]# echo $?
0
```

3. Changing the plugin's output text can be done by specifying the *-s* flag.

The examples in #2 show that the text output is CRITICAL regardless of running the negate plugin. When specifying *-s*, the text output is changed to match the negated result code.

```
[root@op5-system ~]# asmonitor /opt/plugins/negate -s /opt/plugins/check_ping -H 172.16.20.69
OK - 172.16.20.69: rta nan, lost 100%|rta=0.000ms;200.000;500.000;0; pl=100%;40;80;;
[root@op5-system ~]# echo $?
0
```

Note that this will only work for text output in UPPERCASE.


