This is the documentation page for an unsupported version of Zabbix.
Is this not what you were looking for? Switch to the current version or choose one from the drop-down menu.

5 Custom alertscripts

Overview

If you are not satisfied with existing media types for sending alerts there is an alternative way to do that. You can create a script that will handle the notification your way.

Alert scripts are executed on Zabbix server. These scripts must be located in the directory specified in the server configuration file AlertScriptsPath parameter.

Here is an example alert script:

#!/bin/bash
       
       to=$1
       subject=$2
       body=$3
       
       cat <<EOF | mail -s "$subject" "$to"
       $body
       EOF

Starting from version 3.4 Zabbix checks for the exit code of the executed commands and scripts. Any exit code which is different from 0 is considered as a command execution error. In such case Zabbix will try to repeat failed execution.

Environment variables are not preserved or created for the script, so they should be handled explicitly.

Configuration

To configure custom alertscripts as the media type:

  • Go to Administration → Media types
  • Click on Create media type

The Media type tab contains general media type attributes:

All mandatory input fields are marked with a red asterisk.

Parameter Description
Name Enter name of the media type.
Type Select Script as the type.
Script name Enter the name of the script file (e.g., notification.sh) that is located in the directory specified in the server configuration file AlertScriptsPath parameter.
Script parameters Add command-line parameters to the script.
{ALERT.SENDTO}, {ALERT.SUBJECT} and {ALERT.MESSAGE} macros are supported in script parameters.
Customizing script parameters is supported since Zabbix 3.0.

The Options tab contains alert processing settings that are common for all media types.

As parallel processing of media types is implemented since Zabbix 3.4.0, it is important to note that with more than one script media type configured, these scripts may be processed in parallel by alerter processes. The total number of alerter processes is limited by the StartAlerters parameter.

User media

To assign custom alertscripts to the user:

  • Go to Administration → Users
  • Open the user properties form
  • In Media tab, click on Add

User media attributes:

Parameter Description
Type Select the custom alertscripts media type.
Send to Specify the recipient to receive the alerts.
When active You can limit the time when alertscripts are executed, for example, the working days only (1-5,09:00-18:00).
See the Time period specification page for description of the format.
Use if severity Mark the checkboxes of trigger severities that you want to activate the alertscript for.
Note that the default severity ('Not classified') must be checked if you want to receive notifications for non-trigger events.
After saving, the selected trigger severities will be displayed in the corresponding severity colors while unselected ones will be grayed out.
Status Status of the user media.
Enabled - is in use.
Disabled - is not being used.