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 are located in the directory defined in the server configuration file AlertScriptsPath variable.
Here is an example alert script:
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.
To configure custom alertscripts as the media type:
The Media type tab contains general media type attributes:
All mandatory input fields are marked with a red asterisk.
The following parameters are specific for the script media type:
Parameter | Description |
---|---|
Script name | Enter the name of the script. |
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. |
See common media type parameters for details on how to configure default messages and alert processing options.
Even if an alertscript doesn't use default messages, message templates for operation types used by this media type must still be defined, otherwise a notification will not be sent.
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.
To test a configured script media type:
Locate the relevant script in the list of media types.
Click on Test in the last column of the list; a testing form will open in a pop-up window. The testing form will contain the same number of parameters that are configured for the script media type.
Edit the script parameter values if needed. Editing only affects the test procedure; the actual values will not be changed.
Click on Test.
When testing a configured script media type, {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE} and user macros will resolve to their values, but macros that are related to events (e.g., {HOST.HOST}, {ITEM.LASTVALUE}, etc.) will not resolve, as during testing there is no related event to get the details from. Note that macros within {ALERT.SUBJECT} and {ALERT.MESSAGE} macros will also not resolve. For example, if the value of {ALERT.SUBJECT} is composed of "Problem: {EVENT.NAME}" then the {EVENT.NAME} macro will not be resolved.
Once the media type is configured, go to the Administration → Users section and edit user profile to assign media of this type to the user. Steps for setting up user media, being common for all media types, are described on the Media types page.
Note, that when defining a user media, a Send to field cannot be empty. If this field will not be used in an alertscript, enter any combination of supported characters to bypass validation requirements.