banbanbai 发表于 2019-1-20 10:24:30

ZABBIX 之python脚本邮件报警配置


ZABBIX 之python脚本邮件报警配置

一:创建报警类型
Administraion ----->Media Type ----> Create Media---->Type
http://s5.运维网.com/wyfs02/M00/7F/1E/wKiom1cUVZGCXJeWAAB7q3FHfdA260.png

二:创建报警联系用户组
Administration----->User------>Create user group



http://s5.运维网.com/wyfs02/M01/7F/1E/wKiom1cUVfyC-kfJAADVyobJle0581.png三:创建报警练习人
Administration ----->User--------->点击 《北京奇点报警联系人》组中的Users,------->Create User


http://s3.运维网.com/wyfs02/M01/7F/1B/wKioL1cUVvahI8bvAAE5OKLq-_U642.png
http://s3.运维网.com/wyfs02/M02/7F/1E/wKiom1cUVjzxFmfwAAMd1Qq9ttQ345.png
http://s2.运维网.com/wyfs02/M00/7F/1B/wKioL1cUVvzBt6ZKAAK7ljkJb1Q998.png


四:创建Action(报警触发动作)
Configuration ------>Actions--------> Create actions----> Rereport probelms to Zabbix Admin(默认存在)
http://s1.运维网.com/wyfs02/M02/7F/1E/wKiom1cUVoThGpJYAAHh_QvFwWU152.png
http://s4.运维网.com/wyfs02/M00/7F/1E/wKiom1cUVoXi_THrAAEM3d8gUaA436.png
http://s2.运维网.com/wyfs02/M00/7F/1B/wKioL1cUV0OQIEfAAADTs03rJiI045.png
http://s1.运维网.com/wyfs02/M01/7F/1B/wKioL1cUV0bBdmNZAAFGQqvW7_c111.png
  

五.脚本内容
vi /usr/local/zabbix/etc/alterscripts/sendmail.py
  #!/usr/bin/envpython
  #coding:utf-8
  importsmtplib
  fromemail.mime.text import MIMEText
  importsys
  mail_host= 'smtp.163.com'
  mail_user= '15614119390@163.com'
  mail_pass= '123456'
  mail_postfix= '163.com'
  defsend_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)
vi /usr/local/zabbix/etc/zabbix_server.conf
  AlertScriptsPath=/etc/zabbix/alterscripts/
六.重启zabbix
  service   zabbix_serverstop
  service   zabbix_serverstart





页: [1]
查看完整版本: ZABBIX 之python脚本邮件报警配置