1、Zabbix添加处理方法:管理——处理方法——create media type
zabbix会传给脚本三个参数:接收用户,邮件主题,邮件内容
zabbix_sendmail.py
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_host = 'smtp.163.com'
mail_user = 'username'
mail_pass = 'password'
mail_postfix = '163.com'
def send_mail(to_list,subject,content):
me = mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = me
msg['to'] = to_list
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == "__main__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
2、添加触发设置:系统配置——操作——create action
3、zabbix_server添加脚本配置:
mkdir -p /usr/local/zabbix/scripts
把脚本上传到该目录
修改zabbix_server.conf配置:
AlertScriptsPath=/usr/local/zabbix/scripts
然后重启服务
配置完成,很简单!~
©著作权归作者所有:来自51CTO博客作者lihuipeng的原创作品,如需转载,请注明出处,否则将追究法律责任
pythonzabbix邮件报警系统监控