ZABBIX python脚本邮件报警配置

 

一:创建报警类型

Administraion ----->Media Type ----> Create Media---->Type

wKiom1cUVZGCXJeWAAB7q3FHfdA260.png

 

二:创建报警联系用户组

Administration----->User------>Create user group

 

wKiom1cUVfyC-kfJAADVyobJle0581.png三:创建报警练习人

Administration ----->User  --------->点击 《北京奇点报警联系人》组中的Users------->Create User

wKioL1cUVvahI8bvAAE5OKLq-_U642.png

wKiom1cUVjzxFmfwAAMd1Qq9ttQ345.png

wKioL1cUVvzBt6ZKAAK7ljkJb1Q998.png

 

 

四:创建Action(报警触发动作)

Configuration ------>Actions--------> Create actions----> Rereport probelms to Zabbix Admin(默认存在)

 

wKiom1cUVoThGpJYAAHh_QvFwWU152.png

wKiom1cUVoXi_THrAAEM3d8gUaA436.png

wKioL1cUV0OQIEfAAADTs03rJiI045.png

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+"<"+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])

 

 

vi /usr/local/zabbix/etc/zabbix_server.conf

AlertScriptsPath=/etc/zabbix/alterscripts/

 

 

.重启zabbix

service   zabbix_server  stop

service   zabbix_server  start