Zabbix 自定义邮件发送脚本(Python)

2019年10月3日22:12:27 评论 56

1、Zabbix添加处理方法:管理——处理方法——create media type

zabbix会传给脚本三个参数:接收用户,邮件主题,邮件内容

zabbix_sendmail.py

  1. #!/usr/bin/Python
  2. #coding:utf-8
  3. import smtplib
  4. from email.mime.text import MIMEText
  5. import sys
  6. mail_host = 'smtp.163.com'
  7. mail_user = 'username'
  8. mail_pass = 'password'
  9. mail_postfix = '163.com'
  10. def send_mail(to_list,subject,content):
  11. me = mail_user+"<"+mail_user+"@"+mail_postfix+">"
  12. msg = MIMEText(content)
  13. msg['Subject'] = subject
  14. msg['From'] = me
  15. msg['to'] = to_list
  16. try:
  17. s = smtplib.SMTP()
  18. s.connect(mail_host)
  19. s.login(mail_user,mail_pass)
  20. s.sendmail(me,to_list,msg.as_string())
  21. s.close()
  22. returnTrue
  23. except Exception,e:
  24. print str(e)
  25. returnFalse
  26. if __name__ == "__main__":
  27. 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

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: