opo 发表于 2019-1-22 10:25:53

zabbix host update percent报警脚本

  之前有一篇文章讲到使用update percent监控agent的数据提交状况,可以有效地发现agent的故障问题,而使用unreachable的时候,会因为unreachable process busy的情况造成误报(可以通过增大StartPollersUnreachable和UnreachablePeriod解决),附一个python小程序,用来计算host的update percent(遇到host update 为0时不能报警的情况,使用RIGHT JOIN+IFNULL解决).
  

#!/usr/bin/python
# -*- coding: utf8 -*-
#get zabbix agent update percent
import MySQLdb
import os
import sys
import smtplib
from email.MIMEText import MIMEText
reload(sys)
sys.setdefaultencoding('utf-8')
def SendMail(sub,content,to_list = ["ericni.ni@vipshop.com"]):
me=mail_user+""
msg = MIMEText(content,'html','utf-8')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(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               
def getAll(sql):
db = MySQLdb.connect('xxx','xxx','xxx','xxx')
cursor = db.cursor()
try:
cursor.execute(sql)
result = cursor.fetchall()
except Exception,e:
print "failed info %s" % (str(e))
print result
print type(result)
return result
cursor.close()
db.close()
def getReport(allInfo):
print allInfo
mailcontent = ""
print type(allInfo)
if len(allInfo) == 0:
pass
else:
mailcontent = """



Zabbix agent update percent

body { font-size: 14px; color: #333;background-color: #fff;}
td { border: 1px solid #C1DAD7;padding:"4px 10px"; line-height: 24px;}   
table {border-collapse: collapse; width: 96%s;}
.divtd {color:#E28E40;}
.divcss5{ color:#F00;}






domain
ip
percent

"""
forline in allInfo:
mailcontent += ""
mailcontent += "%s" % line
mailcontent += "%s" % line
if float(line)
页: [1]
查看完整版本: zabbix host update percent报警脚本