---
title: "Custom Notification Methods"
description: ""
url: "https://docs.itrsgroup.com/docs/opsview/6.11.7/monitoring/notifications/customized-notification-methods/index.html"
---
You may want to use an existing Nagios Core notification script in Opsview Monitor.

## Adding and writing your notification method

If a new notification script is required for a custom notification method, do the following:

  1. Check the notification script for any dependencies. This may require additional software to be installed on the Opsview Monitor Orchestrator server and Collector.
  2. [Test the notification script](#testing-notification-scripts).
  3. Install your script with the `orchestratorimportscripts` helper tool on the Opsview Orchestrator server as the opsview user.

```
sudo -u opsview /opt/opsview/orchestrator/bin/orchestratorimportscripts notifications /path/to/notificationscript [-e COMMAND_LINE_ARGS|STDIN_ARGS]
```


**Note**


When importing notification scripts, set the execution style (`-e`) to `STDIN_ARGS` only if they are compatible with the secure args feature, which is recommended as a more secure mechanism for passing arguments to scripts. For more information, see [Secure Arguments](https://docs.itrsgroup.com/docs/opsview/6.11.7/configuration/secure-arguments/index.html).



  4. Go to **Configuration** and click [Apply Changes](https://docs.itrsgroup.com/docs/opsview/6.11.7/configuration/apply-changes/index.html) to finish the installation of the notification script. This will make the notification script available to execute on all configured Collectors.

To add a custom notification method, follow these steps:

  1. Go to **Configuration > Notification Methods**, and then click **Add New** to set the appropriate configuration.
  2. User accounts that use this notification method must have it selected in at least one notification profile.
  3. Go to **Configuration > [Apply Changes](https://docs.itrsgroup.com/docs/opsview/6.11.7/configuration/apply-changes/index.html)** to make the new setup live.
  4. Cause a failure to test that the notification is sent.

### Name

The name of your Notification Method.

### Enable

This determines whether the Notification Method is enabled or not.

### Run on

Should the Notification Method execute on the [Orchestrator system or Collector systems](https://docs.itrsgroup.com/docs/opsview/6.11.7/monitoring/notifications/notification-methods/index.html#notification-method-run-on-option).

### Command

Command to run when the Notification Method executes.

### User variables

Comma separated list of variables that must be provided by a user when setting up the Notification Method.

### Writing your own notification script

Your notification script should be written to expect any input regarding the notification alert from Nagios Core via environment variables, see [Macro Availability Chart](https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/macros.html).

The only environment variables available for Notification Methods are:

- NAGIOS_CONTACTALIAS
- NAGIOS_CONTACTEMAIL
- NAGIOS_CONTACTGROUPLIST
- NAGIOS_CONTACTNAME
- NAGIOS_CONTACTPAGER
- NAGIOS_HOSTACKAUTHOR
- NAGIOS_HOSTACKCOMMENT
- NAGIOS_HOSTADDRESS
- NAGIOS_HOSTALIAS
- NAGIOS_HOSTATTEMPT
- NAGIOS_HOSTDOWNTIME
- NAGIOS_HOSTDURATION
- NAGIOS_HOSTGROUPALIAS
- NAGIOS_HOSTGROUPNAME
- NAGIOS_HOSTNAME
- NAGIOS_HOSTNOTIFICATIONNUMBER
- NAGIOS_HOSTOUTPUT
- NAGIOS_HOSTPROBLEMID
- NAGIOS_HOSTSTATE
- NAGIOS_HOSTSTATEID
- NAGIOS_HOSTSTATETYPE
- NAGIOS_LASTHOSTCHECK
- NAGIOS_LASTHOSTDOWN
- NAGIOS_LASTHOSTPROBLEMID
- NAGIOS_LASTHOSTSTATE
- NAGIOS_LASTHOSTSTATECHANGE
- NAGIOS_LASTHOSTUNREACHABLE
- NAGIOS_LASTHOSTUP
- NAGIOS_LASTSERVICECHECK
- NAGIOS_LASTSERVICECRITICAL
- NAGIOS_LASTSERVICEOK
- NAGIOS_LASTSERVICEPROBLEMID
- NAGIOS_LASTSERVICESTATE
- NAGIOS_LASTSERVICESTATECHANGE
- NAGIOS_LASTSERVICEWARNING
- NAGIOS_LASTSTATECHANGE
- NAGIOS_LONGDATETIME
- NAGIOS_LONGHOSTOUTPUT
- NAGIOS_LONGSERVICEOUTPUT
- NAGIOS_NOTIFICATIONAUTHOR
- NAGIOS_NOTIFICATIONCOMMENT
- NAGIOS_NOTIFICATIONNUMBER
- NAGIOS_NOTIFICATIONTYPE
- NAGIOS_SERVICEACKAUTHOR
- NAGIOS_SERVICEACKCOMMENT
- NAGIOS_SERVICEATTEMPT
- NAGIOS_SERVICEDESC
- NAGIOS_SERVICEDOWNTIME
- NAGIOS_SERVICEDURATION
- NAGIOS_SERVICENOTES
- NAGIOS_SERVICENOTIFICATIONNUMBER
- NAGIOS_SERVICEOUTPUT
- NAGIOS_SERVICEPROBLEMID
- NAGIOS_SERVICESTATE
- NAGIOS_SERVICESTATEID
- NAGIOS_SERVICESTATETYPE
- NAGIOS_SHORTDATETIME
- NAGIOS_TIMET
- OPSVIEW_KEYWORDS

For example, in perl, reference the HOSTNAME variables using:

  ```
  print "$ENV{NAGIOS_HOSTNAME}\n";
  ```

In bash, use:

  ```
  echo $NAGIOS_HOSTNAME
  ```

A useful trick in bash to see all available environment variables is to add at the top of a Notification Method:

  ```
  { date; echo "Called with $@"; env; echo; } >> /tmp/env.txt
  ```

To distinguish between a service alert and a Host alert, do something like (in Perl):

  ```
  if ( $ENV{NAGIOS_SERVICEDESC} ) {
  # This is a service alert
  } else {
  # This is a Host alert
  }
  ```

Global settings should be stored either in the script or via command arguments.

#### OUTPUT

The environment Variables SERVICEOUTPUT, HOSTOUTPUT, LONGSERVICEOUTPUT, LONGHOSTOUTPUT hold the output from a plugin. The first two hold only the first line of the output, while the remainder is in the LONG variables.
Note that the left and right angle brackets (<>) are stripped from the output.

#### CONTACTGROUPLIST

This environment variable holds all the contact groups that this Host/service belongs to, in a comma-separated list. Contact groups will be of the form:

  - HostgroupX_servicegroupY
  - kZ_NAME

You can use this to get the list of keyword names that the Host/Service is related to by:

  ```
  @keywords = grep { s/k\d+_// } (split ",", $ENV{NAGIOS_CONTACTGROUPLIST})
  ```

## Testing notification scripts

To test notification scripts on the Orchestrator, use the following commands:

```
# Test Host
sudo -u opsview /opt/opsview/coreutils/utils/test_notifications hostproblem /path/to/notificationscript [other parameters]

# Test Service
sudo -u opsview /opt/opsview/coreutils/utils/test_notifications serviceproblem /path/to/notificationscript [other parameters]
```

Some scripts may require extra configuration to test them. For example, to test the VictorOps notification method, ensure the access key is set in the UI and then use the following:

  ```
  export NAGIOS__CONTACTVICTOROPS_ROUTING_KEY="<routing_key>"
  /opt/opsview/coreutils/utils/test_notifications hostproblem /opt/opsview/monitoringscripts/notifications/notify_by_victorops
  where the routing key is set as per your VictorOps routing configuration.
  ```

This particular notification method logs to `/var/log/opsview/opsview.log`, but you need to check within each script where logging is sent (in many cases script output is captured in a file located in `/tmp/`).


