下载  >  课程资源  >  软件测试  > zabbix短信.微信.钉钉告警脚本.md.pdf

zabbix短信.微信.钉钉告警脚本.md.pdf 评分:

zabbix短信.微信.钉钉告警脚本.md.pdf文档。zabbix短信.微信.钉钉告警脚本教程
#!/usr/bin/env python t coding: utf-8 import sys import urllib2 45678 import time import json import requests reload(sys) 10.sys.setdefaultencoding(utf-8) title= sys. argv2 13.content= sys. argv [31 14 15.class Token(object) 16 def init (self, corpid, corpsecret) selfbaseurl=https://gyapi.weixinqg.com/cgi-bin/gettoken?corpid= o&corpsecret=f1. format( corpid, corpsecret) 19 self expire time= sys. maxint 2 def get token(self) if self expire time time time (: request urllib2 Request(self baseurl) 24 response= urllib2 urlopen (request) 25 ret= response. reado. strip ret= json. loads(ret) if 'errcode in ret keys() 28 print > ret['errmsg, sys. stderr 29 sys. exit(1) lf expire time timetime()+ ret[ 'expires in'I self access token ret['access token'1 32 return self, access token 34。 def send msg(title, content) corpid =" NX97a697157fe8" corpsecret ="7FbbmUuMFbD6TDkYVA18jWCnAg 3KVE8bVMJIJX8QHN9mz fwgstWG14A9S VCPgBB 3 gs token= Token (corpidcorpid, corpsecretcorpsecret) get token() 39 url=https://gyapi.weixinqq.com/cgi-bin/message/send?accesstoken=10 format( gs token) payload =t touser":"@all msgtype":text text 46 en>9" content":"标题:{0}n内容:1. format( title, content) safe":0 59 ret- requests. post(url, data=json, dumps(payload, ensure ascii=False)) print ret json( 54. if name n print title, content send msg(title, content) 短信 /usr/bin/python #coding: utf-8 I import urllib2 import urllib 5.import sys 7. def send(mobile, msg) url=http://odianyun.com/open-api/omc/sendmsgwithcontent.do 19 ta= urllib urlencode(t 11 token":" bd4ff2f2-0966-9F0f-18bedda743fa 12 mobiles: mobile, msg":msg) 14 req urllib2 Request(url, data 15 res- urllib2, urlopen(reg) 16 print res, reado .8. mobile=sys. argv[1] 19.msg-sysargv[2]+\r\n'+sys. argv[3] 20. send( mobile, msg)

...展开详情
2018-02-24 上传 大小:146KB
举报 收藏
分享