查看zabbix 告警脚本位置
[root@zabbix alertscripts]# grep "^AlertScriptsPath" /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/usr/lib/zabbix/alertscripts
编写告警邮件脚本
#cd /usr/lib/zabbix/alertscripts
#vim alert.sh
#!/bin/bash
#author firxiao
#date 20141124
to=$1
subject=$2
body=$3
cat <<EOF | mail -s "$subject" -S from=sender@example.com "$to"
$body
EOF
其中 from=sender@example.com 可以自行定义
#chmod +x alert.sh
web页面配置如下
至此 zabbix告警的发件人已经配置成脚本中指定的用户了
zabbix 2.4版本以后使用上述脚本会出现邮件正文为附件的情况,请使用以下脚本
#!/bin/bash
#author firxiao
#date 20160725
to=$1
subject=$2
body=$3
headers="Content-Type: text/plain; charset=UTF-8"
cat <<EOF | mail -s "$(echo -e "$subject\n$headers")" -S from=sender@example.com "$to"
$body
EOF
参考:https://www.zabbix.com/documentation/2.0/manual/config/notifications/media/script