1.编辑zabbix server端的配置文件,并重启服务
# vim /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/usr/local/zabbix/alertscripts
# /etc/init.d/zabbix_server restart
2.在服务端添加邮件报警的python脚本,并给脚本执行权限
邮件报警,并记录日志
# vim /usr/local/zabbix/alertscripts/zabbix_sendmail.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pdb
import smtplib
import string
import time
import sys
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
#pdb.set_trace()
#HOST = "mail.gw.com.cn"
def S_Mail():
HOST = "smtp.exmail.qq.com" #邮件服务器
SUBJECT = sys.argv[2].decode(‘utf-8‘).encode(‘gbk‘) #主题
TO =sys.argv[1] #收件邮箱
FROM = "admin@qq.cn"
text = sys.argv[3].decode(‘utf-8‘).encode(‘gbk‘) #发件内容
BODY = string.join((
"FROM: %s" % FROM,
"To: %s" % TO,
"Subject: %s" %SUBJECT,
"",
text
),"\r\n")
server = smtplib.SMTP()
server.connect(HOST,25)
#server.starttls()
server.login("发件邮箱","密码")
server.sendmail(FROM,[TO],BODY)
server.quit()
# email log 记录日志
with open(‘/data/logs/zabbix/Email.log‘, ‘a‘) as f:
date=time.strftime("%y-%m-%d %H:%M:%S")
str = date + "" + TO +"" + SUBJECT + "\r\n" + "\n"
str1 = str.decode(‘gbk‘).encode(‘utf-8‘)
# print("%s" %str1)
f.write(str1)
if __name__==‘__main__‘:
S_Mail()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)