zabbix企業(yè)微信發(fā)送告警腳本,解決企業(yè)號(hào)升級(jí)后告警發(fā)送失敗問題

最近企業(yè)微信企業(yè)號(hào)升級(jí)為企業(yè)微信,導(dǎo)致了原先使用微信企業(yè)號(hào)發(fā)送告警的用戶無法正常發(fā)送告警。這里提供已經(jīng)測(cè)試通過的腳本以供參考。

微信告警配置可以參考:http://www.itdecent.cn/p/9ae2900f4029

微信企業(yè)號(hào)API:https://work.weixin.qq.com/api/doc#10167

企業(yè)微信告警腳本:
調(diào)整這一行Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F" '{print $10}'),升級(jí)后字段位置調(diào)整,把原來的$4改為$10即可。
還有printf '\t"agentid": '"$AppID"",\n" ,這里要求是整形,不能有空格

#!/bin/bash
###SCRIPT_NAME:weixin.sh###
###send message from weixin for zabbix monitor###

CropID='xxxxxxxxxxxxxxxxxxxxxxxx'
Secret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $10}')   ###升級(jí)后字段位置調(diào)整,$4改為$10即可

PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"

function body() {
        local int AppID=1                       ###APP ID
        local UserID=$1                         ###USER ID
        local PartyID=2                         ###PARTY ID
        local Msg=$(echo "$@" | cut -d" " -f3-)
        printf '{\n'
        printf '\t"touser": "'"$User"\"",\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 $3)" $PURL

升級(jí)前的微信企業(yè)號(hào)告警腳本:

#!/bin/bash
###SCRIPT_NAME:weixin.sh###
###send message from weixin for zabbix monitor###

CropID='xxxxxxxxxxxxxxxxxxxxxxxx'
Secret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $4}')

PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"

function body() {
        local int AppID=1                       ###APP ID
        local UserID=$1                         ###USER ID
        local PartyID=2                         ###PARTY ID
        local Msg=$(echo "$@" | cut -d" " -f3-)
        printf '{\n'
        printf '\t"touser": "'"$User"\"",\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 $3)" $PURL

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容