告警脚本的放置位置见配置/usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/zabbix_server.log
AlertScriptsPath=/usr/local/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/externalscripts
先创建一下告警脚本位置:
邮件告警注意事项
发邮件的python脚本/usr/local/zabbix/alertscripts/zabbix_sendmail.py
from email.mime.text import MIMEText
from email.header import Header
f = open('/usr/local/zabbix/.passwd','r')
password = f.readline().strip()
msg = MIMEText("""%s"""%(content), "plain", "utf-8")
msg['Subject'] = Header(subject, 'utf-8').encode()
smtp.sendmail(myemail, recvmail.split(','), msg.as_string())
测试脚本
chmod a+x /usr/local/zabbix/alertscripts/zabbix_sendmail.py
/usr/local/zabbix/alertscripts/zabbix_sendmail.py 361589194@qq.com 'zabbix disk' 'content: disk > 90%'
Zabbix邮件告警配置
创建action
为故障恢复时再发送邮件:同Operations设置
报警媒介添加邮件告警
用户添加报警媒介
创建触发器动作
告警内容自定义和告警抑制