2、脚本文件路径
先确认下zabbix_server.conf文件中定义的告警脚本路径
#AlertScriptsPath=/usr/lib/zabbix/alertscripts
AlertScriptsPath=/etc/zabbix/alertscripts
然后将准备好的python脚本存放到该路径下,并更改脚本文件的权限和属主属组
#chown zabbix:zabbix mail.py
#chmod +x mail.py
注意:如果在zabbix_server.conf文件中没有设置Allow root=1,则表示zabbix是以zabbix用户启动而不是root,所以脚本的属主属组都应该设置为zabbix用户。设置为root用户启动的配置如下。
### Option: AllowRoot
# Allow the server to run as 'root'. If disabled and the server is started by 'root', the server
# will try to switch to user 'zabbix' instead. Has no effect if started under a regular user.
# 0 - do not allow
# 1 - allow
#
# Mandatory: no
# Default:
AllowRoot=1
3、测试脚本文件发送邮件是否成功,这一步很重要
# cd /usr/lib/zabbix/alertscripts
#./mail.py 451345726@qq.com “subject” “content”
如果能收到邮件,表示脚本没有问题。