shell脚本调用企业微信api发送告警
alert.sh
#!/bin/sh
corpId=xxxxxxxxxxx
corpSecret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
###### get token (expires: 2 hour)
### version 1
# curl "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${corpId}&corpsecret=${corpSecret}" |awk -F\" '{prin
t $10}' > ./token_tmp.txt
# tokenTmp=$(cat ./token_tmp.txt)
### version 2
tokenTmp=$(curl -s "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${corpId}&corpsecret=${corpSecret}" |awk -
F\" '{print $10}')
# echo "The current token is ${tokenTmp}"
###### send json message by wechat api
curl -H "Content-Type: application/json" -XPOST -d @./post.json https://qyapi.weixin.qq.com/cgi-bin/message/send?acce
ss_token=${tokenTmp} &>/dev/null
echo "Alert send success !!!"
#END
post.json
{
"touser" : "xxxx",
"msgtype" : "text",
"agentid" : 1000002,
"text" : {
"content" : "alert script test"
},
"safe":0
}
================# 水平有限 欢迎指正 #=================

浙公网安备 33010602011771号