1.配置告警媒介
邮件:
微信:
#!/usr/bin/env python # -*- coding: utf-8 -*- import urllib,urllib2,datetime,hashlib,sys reload(sys) sys.setdefaultencoding( "utf-8" ) #Send message to all user def sendmessage(touser,data): url='http://msg.xin.com/msg/receive-msg' appkey = 'MjU5ZTZl' #正式 secret = '51e8b107a653886c9377878e69436f79faf89105' #正式 today = datetime.datetime.now().strftime('%Y-%m-%d') snstr = 'appkey=%s&batch=1&content=%s&touser=%s%s%s'%(appkey,data,touser,secret,today) sn = hashlib.md5(snstr.encode(encoding='UTF-8')).hexdigest().lower() textmod={"appkey":appkey,"batch":1,"content":data,"touser":touser,"sn":sn} postdata = urllib.urlencode(textmod) postdata = postdata.encode('utf-8') res = urllib2.urlopen(url,postdata) res = res.read() return sendmessage(sys.argv[1],sys.argv[3]) #with open('/usr/lib/zabbix/alertscripts/aa.txt','ab') as fo: # fo.write(sys.argv[1])
2.配置告警方式
Name:Alert_email_for_Network
###出情况啦!!!###
告警级别: {TRIGGER.SEVERITY}
告警主机:{HOST.NAME}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警信息: {TRIGGER.NAME}
问题详情:{ITEM.NAME1} ({HOST.CONN}:{ITEM.KEY1}): {ITEM.VALUE1}
Recovery message:
###已经搞定啦!!!###
告警级别: {TRIGGER.SEVERITY}
告警主机:{HOST.NAME}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警信息: {TRIGGER.NAME}
问题详情:{ITEM.NAME1} ({HOST.CONN}:{ITEM.KEY1}): {ITEM.VALUE1}
看看天上,于是我去了满是风雪的地方