Zabbix 自定义邮件发送脚本(Python)
1、Zabbix添加处理方法:管理——处理方法——create media typehttp://blog.运维网.com/attachment/201211/113622870.png
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+""
[*] 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, sys.argv, sys.argv)
2、添加触发设置:系统配置——操作——create action
http://blog.运维网.com/attachment/201211/114018488.png
http://blog.运维网.com/attachment/201211/114026575.png
http://blog.运维网.com/attachment/201211/114041136.png
3、zabbix_server添加脚本配置:
mkdir -p /usr/local/zabbix/scripts
把脚本上传到该目录
修改zabbix_server.conf配置:
AlertScriptsPath=/usr/local/zabbix/scripts
然后重启服务
配置完成,很简单!~
页:
[1]