2022 Zabbix中国峰会
2022 Zabbix中国峰会

5 自定义警报提示

5 Custom alertscripts




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:

       cat <<EOF | mail -s "$subject" "$to"
       cat <<EOF | mail -s "$subject" "$to"

<note important>从版本3.4开始,Zabbix检查执行的命令和脚本的退出代码。任何与** 0 **不同的退出代码都被视为命令执行错误. 在这种情况下,Zabbix会尝试重复执行失败。 :::

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:

  • 进入 管理 - >媒介类型
  • 点击创建媒介类型
  • 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.

参数 说
Name 输入媒介类型的名称.
Type 选择 Script 作为媒介类型.
Script name 输入脚本的名称.
Script parameters 向脚本添加命令行参数.
Zabbix 3.0支持自定义脚本参数.
Parameter Description
Name Enter name of the media type.
Type Select Script as the type.
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.


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

从Zabbix 3.4.0版本开始实现了多个告警媒介并行处理, 所以需要注意的是,当配置了多个告警脚本时,这些脚本是可以被告警进程并行处理的. 告警进程的进程数可以通过配置项StartAlertersparameter进行限制。

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:

  • 进入 管理 - >用户
  • 打开用户属性窗体
  • 在媒介选项卡中,单击 Add
  • Go to Administration → Users
  • Open the user properties form
  • In Media tab, click on Add


User media attributes:

参数 说
Type 选择自定义的alertcripts媒介类型.
Send to 指定收件人接收警报.
When active 您可以限制执行警示标记的时间,例如,仅限工作日(1-5,09:00-18:00).\\格式说明参见时间段规格.页面.
Use if severity 勾选复选框(Not classified/Information/Warning/Average/High/Disaster),标识您要接收通知的触发严重性.
Status 用户媒介的状态
Enabled - 使用中.
Disabled -禁用.
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 colours while unselected ones will be greyed out.
Status Status of the user media.
Enabled - is in use.
Disabled - is not being used.