1、注册企业微信并配置
AgentID和Secret会在发送微信报警信息的时候调用
创建微信账号
用户账户名称必须唯一,在发送微信报警信息的时候会调用
企业信息
企业ID在发送微信报警信息的时候会调用
测试发送信息
确认消息接收人
开始发送信息
手机收到信息,这里没成功,下面就不用看了
2、zabbix server配置
编写python脚本
#!/usr/bin/python3.6
#coding:utf-8
#Author:jiangshen
import requests
import sys
import os
import json
import logging
logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s', datefmt = '%a, %d %b %Y %H:%M:%S',
filename = os.path.join('/tmp','weixin.log'),
filemode = 'a')
corpid='企业ID'
appsecret="秘钥"
agentid="AgentID"
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']
msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken
touser=sys.argv[1]
subject=sys.argv[2]
message=sys.argv[3]
params={
"touser": touser,
"msgtype": "text",
"agentid": agentid,
"text": {
"content": message
},
"safe":0
}
req=requests.post(msgsend_url, data=json.dumps(params))
logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message)
测试 ,涂画的是第一个参数,他是企业微信里面添加的唯一账号,区分大小写
#报错原因,检查一下自己的python环境,我的python默认是python2
#这是我用python3.6执行的