Zabbix 4.0 - 企业微信告警shell脚本
/

Zabbix 4.0 - 企业微信告警shell脚本

SOSO
2022-02-25 / 0 评论 / 81 阅读 / 正在检测是否收录...

企业微信告警shell脚本

#!/bin/bash
#set -x
CorpID="xxx"                   #企业CorpID
Secret="xxx"            #应用Secret
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret"
accessToken=$(/usr/bin/curl -s -G $GURL |awk -F\": '{print $4}'|awk -F\" '{print $2}')
#echo $accessToken
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$accessToken"
 
function body(){
        local int agentid=1000002   #应用AgentId
        local UserID=$1             
        local PartyID=1            #部门ID
        local Msg=$(echo "$@" | cut -d" " -f3-)
        printf '{\n'
        printf '\t"touser": "'"$UserID"\"",\n"
        printf '\t"toparty": "'"$PartyID"\"",\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 "$(body $1 $2 $3)" $PURL
0

评论 (0)

取消