zabbix钉钉报警python脚本

Posted zhj5551

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix钉钉报警python脚本相关的知识,希望对你有一定的参考价值。

 1 #!/usr/bin/env python
 2 #coding:utf-8
 3 #zabbix钉钉报警
 4 import requests,json,sys,os,datetime
 5 webhook="https://oapi.dingtalk.com/robot/send?access_token=52c39155fcb9f2fecda75ef8cec6d2ffa318e4818982f772ecb9f779a630151d"
 6 user=sys.argv[1]
 7 text=sys.argv[3]
 8 data=
 9     "msgtype": "text",
10     "text": 
11         "content": text
12     ,
13     "at": 
14         "atMobiles": [
15             user
16         ],
17         "isAtAll": False
18     
19 
20 headers = Content-Type: application/json
21 x=requests.post(url=webhook,data=json.dumps(data),headers=headers)
22 if os.path.exists("/usr/local/zabbix/logs/dingding.log"):
23     f=open("/usr/local/zabbix/logs/dingding.log","a+")
24 else:
25     f=open("/usr/local/zabbix/logs/dingding.log","w+")
26 f.write("\n"+"--"*30)
27 if x.json()["errcode"] == 0:
28     f.write("\n"+str(datetime.datetime.now())+"    "+str(user)+"    "+"发送成功"+"\n"+str(text))
29     f.close()
30 else:
31     f.write("\n"+str(datetime.datetime.now()) + "    " + str(user) + "    " + "发送失败" + "\n" + str(text))
32     f.close()

 

以上是关于zabbix钉钉报警python脚本的主要内容,如果未能解决你的问题,请参考以下文章

zabbix3.4.4钉钉机器人报警图文笔记

zabbix之钉钉报警通知

zabbix之钉钉报警通知

zabbix之钉钉报警通知

zabbix之钉钉报警通知

zabbix 3.2 配置阿里云钉钉报警