码迷,mamicode.com
首页 > 编程语言 > 详细

zabbix钉钉报警python脚本

时间:2019-07-17 00:34:41      阅读:42      评论:0      收藏:0      [点我收藏+]

标签:脚本   python   env   ==   bsp   zab   http   bin   path   

 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脚本

标签:脚本   python   env   ==   bsp   zab   http   bin   path   

原文地址:https://www.cnblogs.com/zhj5551/p/11198227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!