zabbix 3.2 使用微信企业号报警

各位看官,我是orange小菜,初来扎道,不足之处还请指教,sharing make happy !!!python

1.我先把个人代码甩出来,供你们参考一下,挺丑的,别介意哦!json

#!/usr/bin/python

import requests 
import sys
import json

userID=sys.argv[1]
subject=sys.argv[2]
content=sys.argv[3]

corpid='CorpID'  #此处为权限管理中每一个组的ID,其实说就一个ID,所有相同的
corpsecret="CortSecret"#此处为权限管理中的密码,其实严格来讲是来区分其余组的ID

class WeiXin(object):
#初始化变量 
def  __init__(self,corpid,corpsecret):
self.corpid=corpid
self.corpsecret=corpsecret
#获取token的值
def get_token(self):

url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid='+\
self.corpid+'&corpsecret='+self.corpsecret
get_data=requests.request("GET",url)
get_token=get_data.json()
token=get_token.get('access_token')
return token
#发送data,也就是推送到用户 
def send_data(self,user,subject,content):
access_token=self.get_token()
url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='+\
access_token
send_data={
"touser": user,  #这是指的是通讯录中不一样组的用户,当发送的用户在组中没法找到,            
 默认会向全部用户发送
"toparty": 3,    #这里指的是通讯录中的组ID,
"msgtype": "text",
"agentid": 3,    #这里指的是应用,也就是消息管理,那些人能够收到本组信息那些不能够
"text": {
"content": '{0}{1}{2}'.format(subject,content,user)
},
"safe": 0
}
data=json.dumps(send_data,ensure_ascii=False)
ret=requests.post(url,data=data)
print ret.json()

if '__main__'==__name__:
User=WeiXin(corpid,corpsecret)
User.send_data(userID,subject,content)

2.曾经走过的坑api

(a) 权限问题,和两个地方有关系,第一与应用中心的某个应用的可见范围有关系;第二和设置里面功能设置中的权限管理有关。

 (b)微信的使用问题,第一要建个通讯录,找到正确的组ID,第二,应用中心agentid的建立并使用,第三,设置中分组要建立;

坑,解决掉就是路,解决不了仍是坑。微信

相关文章
相关标签/搜索