zabbix使用企业微信发消息

2018 年 4 月 27 日 运维帮 南非蜘蛛

今天帮一个朋友调试zabbix使用企业微信发消息,发现微信企业号大改版了,所以把整个过程做个简单记录,分享给大家。


首先,你需要注册一个企业微信,https://work.weixin.qq.com/



接收消息有2种方式,一是用企业微信,二是用个人微信(需要关注企业号,需要登录扫描下图邀请关注的二维码):



官方api说明


地址:https://work.weixin.qq.com/api/doc#10167


整体过程


一:创建自建应用「报警」,然后用公司corpid和企业应用secret获取token,https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$corpsecret


二:带着token、touser、agentid、content等参数,向接口https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$token 进行post数据


一、创建自建应用


自建应用里会生成AgentId和Secret



二、首先测试连接


地址:http://work.weixin.qq.com/api/devtools/devtool.php


corpid在「我的企业」最下面显示,corpsecret就是上面的企业应用里的Secret的值



如果有返回一个access_token值,就说明没问题


在zabbix里生成发送脚本


发送消息例子:


具体的代码如下:


#!/bin/bash

access_token=$(/usr/bin/curl -s -G "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=xxxxxxxxx&corpsecret=xxxxxxxxxxxx" | awk -F\" '{print $10}')

#红色xxxx部分修改为你自己的

 

function body() {

        local UserID="$1"

        local PartyID=""

        local AppID="1000002"

        local Msg="$2"

        printf '{\n'

        printf '\t"touser": "'"$UserID"\"",\n"

        printf '\t"toparty": "'"$PartyID"\"",\n"

        printf '\t"msgtype": "text",\n'

        printf '\t"agentid": "'"$AppID"\"",\n"

        printf '\t"text": {\n'

        printf '\t\t"content": "'"$Msg"\""\n"

        printf '\t},\n'

        printf '\t"safe":"0"\n'

        printf '}\n'

}


/usr/bin/curl --data-ascii "$(body $1 $2)" "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$access_token"


测试

sh weixin.sh 账号 发送内容

注意:账号在企业微信「通讯录」里指用户账号,是一个唯一值,不能用姓名和英文名。


主流云厂商都已和运维帮达成战略合作,不管是1台还是100台,都可以享受到价格优惠,请联系群秘书。

欢迎加入「运维帮地方群」,现在有北京地方群、上海地方群、深圳地方群、成都地方群、广州地方群、杭州地方群

群秘书微信,扫描下方二维码

登录查看更多
0

相关内容

【2020新书】实战R语言4,323页pdf
专知会员服务
98+阅读 · 2020年7月1日
一份简明有趣的Python学习教程,42页pdf
专知会员服务
76+阅读 · 2020年6月22日
还在修改博士论文?这份《博士论文写作技巧》为你指南
【实用书】Python爬虫Web抓取数据,第二版,306页pdf
专知会员服务
115+阅读 · 2020年5月10日
Gartner:2020年十大战略性技术趋势, 47页pdf
专知会员服务
74+阅读 · 2020年3月10日
Transformer文本分类代码
专知会员服务
116+阅读 · 2020年2月3日
msf实现linux shell反弹
黑白之道
49+阅读 · 2019年8月16日
百度开源项目OpenRASP快速上手指南
黑客技术与网络安全
5+阅读 · 2019年2月12日
DiscuzX 3.4 Phar反序列化漏洞
黑客工具箱
8+阅读 · 2019年1月4日
比Selenium快100倍的方法爬东方财富网财务报表
程序人生
8+阅读 · 2018年10月31日
已删除
AI科技评论
4+阅读 · 2018年8月12日
python帅到没朋友的填充软件
运维帮
4+阅读 · 2018年5月30日
使用Keras和LSTM生成说唱歌词
论智
5+阅读 · 2018年5月22日
爬了自己的微信,原来好友都是这样的!
七月在线实验室
4+阅读 · 2018年1月18日
《小美好》短评文本情感分析+生成词云
数据挖掘入门与实战
5+阅读 · 2018年1月7日
Equalization Loss for Long-Tailed Object Recognition
Arxiv
5+阅读 · 2020年4月14日
Learning Implicit Fields for Generative Shape Modeling
Arxiv
10+阅读 · 2018年12月6日
Rapid Customization for Event Extraction
Arxiv
7+阅读 · 2018年9月20日
Arxiv
4+阅读 · 2018年5月10日
Arxiv
3+阅读 · 2017年12月23日
Arxiv
5+阅读 · 2015年9月14日
VIP会员
相关资讯
msf实现linux shell反弹
黑白之道
49+阅读 · 2019年8月16日
百度开源项目OpenRASP快速上手指南
黑客技术与网络安全
5+阅读 · 2019年2月12日
DiscuzX 3.4 Phar反序列化漏洞
黑客工具箱
8+阅读 · 2019年1月4日
比Selenium快100倍的方法爬东方财富网财务报表
程序人生
8+阅读 · 2018年10月31日
已删除
AI科技评论
4+阅读 · 2018年8月12日
python帅到没朋友的填充软件
运维帮
4+阅读 · 2018年5月30日
使用Keras和LSTM生成说唱歌词
论智
5+阅读 · 2018年5月22日
爬了自己的微信,原来好友都是这样的!
七月在线实验室
4+阅读 · 2018年1月18日
《小美好》短评文本情感分析+生成词云
数据挖掘入门与实战
5+阅读 · 2018年1月7日
相关论文
Equalization Loss for Long-Tailed Object Recognition
Arxiv
5+阅读 · 2020年4月14日
Learning Implicit Fields for Generative Shape Modeling
Arxiv
10+阅读 · 2018年12月6日
Rapid Customization for Event Extraction
Arxiv
7+阅读 · 2018年9月20日
Arxiv
4+阅读 · 2018年5月10日
Arxiv
3+阅读 · 2017年12月23日
Arxiv
5+阅读 · 2015年9月14日
Top
微信扫码咨询专知VIP会员