OP5 Monitor ["OP5 Monitor"]
["Technical Reference"]

# Manage commands

## Overview

Commands are used in various situations in OP5 Monitor. Some examples are as follows:

- Service or host checks.
- Notifications.
- Event handler commands.
- Obsession commands.

You can add custom commands and variables in your service and host configurations. For details of the monitoring object fields where you can customise commands and variables, see Host options in Manage templates and time periods and Service options in Manage templates and time periods.

### Command-line arguments

Command lines are made up mainly of a plugin name, variables, and macros.

#### Plugins

Plugins are used in commands to run checks. The list of plugins available with OP5 Monitor is listed in Plugin reference. You can also use the plugin search feature to find details of any plugins included in OP5 Monitor, including their current support status. For more information, see Introduction to plugins.

#### Variables

You can use pre-defined and custom variables in command lines. You can also create new custom variables when you are updating a host, service, or contact configuration, by clicking the Add custom variable button.

##### Custom variables

Custom variables can be used for storing custom information for hosts, services, and contacts. They can also be used as macros in command arguments and notifications.

All custom variable names are written in upper case and are prefixed with an underscore, to avoid naming conflicts with standard variables.

You can also use custom variables to create dynamic buttons. For more information, see Create a new dynamic button.

#### Macros

You can use pre-defined and custom macros in command lines.

When custom variables are used in macros, a dollar sign is always used before and after the variable name. For example, a custom variable called `_LOCATION` has a macro name of `$_LOCATION$`.

Some important macros are listed below. You can find a complete list of macros in the Naemon macro documentation.

##### USER series

The `$USER#$` series of macros is for specifying paths to plugins. You configure them in the resource configuration file: `/opt/monitor/etc/resource.cfg`.

The macros are as follows:

- `$USER1$` — the path to the main plugins directory on the OP5 Monitor server. In OP5 Monitor, this path is `/opt/plugins`.
- `$USER1$/custom` — the default path to custom plugins. You can also place any plugin that you need to be ignored by upgrades in the same directory.
- `$USER2$` — the path to plugins that require the SUID bit to be set.
- `$USER3$` — the path to OP5 Monitor specific add-ons.
- `$USER1$` to `$USER10$` are reserved for system use. You must not update their default values and you can only create new macros with names from `$USER11$` to `$USER256$`.

##### ARG series

The `$ARG#$` series of macros is for specifying command line arguments for commands created from plugins. This is useful for macro substitution, for example, passing a service template's baseline critical percentage as the third argument value, `$ARG3$`, in an SNMP plugin.

## Create a new custom variable

You create new custom variables as part of host, service, and contact configuration.

To create a custom variable:

1. Open the host, service, or contact configuration from Manage > Configure.
2. In the Custom variable field, click Add custom variable.
3. Enter the variable name in the first field and the variable value in the second field.

For more information about creating host and service configurations, see Configure a host or service in Manage hosts and services.

## Create a new dynamic button

Dynamic buttons are customisable buttons you can use to execute scripts against services. Dynamic buttons appear on a service detail page, under Service Commands. For more information, see Host or service detail page in Monitor hosts and services.

You create dynamic buttons in a service configuration by specifying two variables with the same name, prefixed with `_OP5` and an optional `H`, to hide it in the service state information, as follows:

- `_OP5H__ACTION__NAME` — the name of the button and the script the button executes.
- `_OP5H__ACCESS__NAME` — the contact groups who can see the button.

Note that the variable names need to have two underscores after the prefix, and between the prefix and the next part of the variable name. All other words in the variable after that are separated by a single underscore.

For example, to create a dynamic button to restart a service:

1. Open the service configuration in the OP5 Monitor user interface. For guidance , see Configuration entry points in Manage hosts and services.
2. In the Custom variable field, click Add custom variable.
3. Specify the name as `_OP5H__ACTION__RESTART_SERVICE`, ensuring that you enter double underscores before and after `ACTION`.
4. Specify the value as `/opt/plugins/custom/restart_service.sh`.
5. Click Add custom variable again.
6. Specify the name as `_OP5H__ACCESS__RESTART_SERVICE`.
7. Specify the value as a comma-separated list of contact groups who have access to the button, for example `support-group,windows-admins`.
8. Click Submit.
9. Click Save at the top of the configuration page.

## Import commands

You can use the OP5 Monitor Command import function to view and import new and updated plugin commands.

1. In the OP5 Monitor interface, click Manage > Configure.
2. In the Checks and notifications section, click Command import. OP5 Monitor lists plugins with new check commands and plugins with modified check commands.
3. Click the required plugin name to expand it, then select the commands to import.
4. Click Import selected commands.
5. In the confirmation prompt, click OK.

## Create and update commands

You can use the standard configuration shortcuts to copy and delete commands. For more information, see Configuration shortcuts in Introduction to configuration.

To create a new command:

1. In the OP5 Monitor interface, click Manage > Configure.
2. In the Checks and notifications section, click Commands.
3. Enter the command_name.
4. Enter the command line for the command, based on the plugin to run and any macros and variables. You can click Syntax help to expand a help section.
5. Test your command, if required:
   1. Click Test this command.
   2. Enter details of the check.
   3. Click Test this check.
6. Click Submit.
7. Click Save at the top of the configuration page.

To update a command:

1. Enter the command name in the search field and click Go.
2. Update the command details.
3. Test your command, if required:
   1. Click Test this command.
   2. Enter details of the check.
   3. Click Test this check.
4. Click Submit.
5. Click Save at the top of the configuration page.

Was this topic helpful?
Your thoughts...
How can we improve this topic?
It did not answer my question(s)
Confusing
Missing screenshot or graphics
Missing technical details
Information is out of date
Your thoughts...
Thank you for your feedback!