xuanxi 发表于 2018-8-26 10:47:51

zabbix微信告警shell脚本

#!/bin/bash  
#set -x
  
CorpID="xxxxxx"
  
Secret="yyyyy"
  
GETURL=https://qyapi.weixin.qq.com/cgi-bin/gettoken\?corpid=$CorpID\&corpsecret=$Secret
  
Token=$(/usr/bin/curl -s -G $GETURL |awk -F\": '{print $4}'|awk -F\" '{print $2}')
  
#echo $Token
  
POSTURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Token"
  
UserID=$1
  
PartyID=2
  
agentid=2
  
Msg=`echo "$@" | cut -f 3`
  
message(){
  
    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 "$(message $1 $2 $3)" $POSTURL


页: [1]
查看完整版本: zabbix微信告警shell脚本