Zabbix 4.0 钉钉报警
111
#!/usr/bin/env python #coding:utf-8 #zabbix钉钉报警 import requests,json,sys,os,datetime webhook="钉钉机器人地址" user=sys.argv[1] text=sys.argv[3] data={ "msgtype": "text", "text": { "content": text }, "at": { "atMobiles": [ user ], "isAtAll": False } } headers = {'Content-Type': 'application/json'} x=requests.post(url=webhook,data=json.dumps(data),headers=headers) if os.path.exists("/tmp/zabbix_dingding.log"): f=open("/tmp/zabbix_dingding.log","a+") else: f=open("/tmp/zabbix_dingding.log","w+") f.write("\n"+"--"*30) if x.json()["errcode"] == 0: f.write("\n"+str(datetime.datetime.now())+" "+str(user)+" "+"发送成功"+"\n"+str(text)) f.close() else: f.write("\n"+str(datetime.datetime.now()) + " " + str(user) + " " + "发送失败" + "\n" + str(text)) f.close()
默认标题:故障{TRIGGER.STATUS},服务器:{HOSTNAME1}发生: {TRIGGER.NAME}故障!
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
恢复标题:恢复{TRIGGER.STATUS}, 服务器:{HOSTNAME1}: {TRIGGER.NAME}已恢复!
恢复信息:
恢复主机:{HOSTNAME1}
恢复时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
恢复信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
人生苦短,我用Python