这里要先点通讯录创建一个部门,然后再点应用小程序创建应用,填写logo、名称、和选择部门就可以了
这个是接口调用测试gentId,和Secret的地址:https://work.weixin.qq.com/api/devtools/devtool.php
这里看到有HTTP/1.1 200 OK 就说明接口有效了,其它的不管。
[root@cyy alertscripts]# vim wechat.sh
#!/usr/bin/env bash
#!/usr/bin/env bash
#
# Author: cyylog
# Email: cyylog@aliyun.com
# Date: 2019/09/25
# Github: https://github.com/cyylog
# Usage: Wechat alert script for zabbix
#
if [ $# -eq 0 ] || [[ "$1" == "-h" || "$1" == "--help" ]];then
echo "Usage of $0:"
echo -e " --CorpID=string"
echo -e " --Secret=string"
echo -e " --AgentID=string"
echo -e " --UserID=string"
echo -e " --Msg=string"
exit
fi
#ops=(-c -s -a -u)
#args=(CorpID Secret AgentID UserID)
#while [ $# -gt 0 ];do
# [ "$1" == "-m" ] && Msg="$2" && shift 2
# for i in {0..3};do
# [ "$1" == "${ops[i]}" ] && eval ${args[i]}="$2"
# done
# shift 2
#done
for i in "$@";do
echo $i|grep Msg &> /dev/null && msg=$(echo $i|sed 's/.*=//') && Msg="$msg" && continue
eval "$(echo $i|sed 's/--//')"
done
#echo $CorpID
#echo $Secret
#echo $UserID
#echo $AgentID
#echo $Msg
#
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret"
Token=$(/usr/bin/curl -s -G $GURL |awk -F \" '{print $10}')
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Token"
Info(){
printf '{\n'
printf '\t"touser": "'"$UserID"\"",\n"
printf '\t"msgtype": "text",\n'
printf '\t"agentid": "'"$AgentID"\"",\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 "$(Info)" $PURL
echo
[root@cyy alertscripts]# chmod +x wechat.sh
[root@cyy alertscripts]# ./wechat.sh "这里一个测试" //可以这样直接调试,然后登陆到企业微信查看该部门的群成员是否收到此信息
脚本测试通过后就是在zabbix控制台上设置了
--AgentID=1000002
--CorpID=ww74c********56c
--Secret=-c-3Xw*****************j-Zj6cw
--Msg={ALERT.MESSAGE}
--UserID={ALERT.SENDTO}
第一步的第3点获取的账号
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有