zabbix企业微信号、钉钉报警脚本

微信企业号报警脚本:

#!/bin/bash

CropID=''#企业号id

Secret=''#企业号管理密码

GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"

Gtoken=$(/usr/bin/curl -s -G $GURL|awk -F\" '{print$10}' )

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

function body() {

local int AppID=1

local UserID=$1

local PartyID=1

扫描二维码关注公众号,回复: 588488 查看本文章

local Msg=$(echo "$@" | cut -d" "-f3-)

printf '{\n'

printf '\t"touser":"'"$UserID"\"",\n" #联系人人id

printf '\t"toparty": "1",\n' #联系人部门id

printf '\t"totag": "1",\n'

printf '\t"msgtype": "text",\n'

printf '\t"agentid":"'"$AppID"\"",\n" #应用id

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

 

 

钉钉报警脚本:

#!/bin/bash

Gtoken="https://oapi.dingtalk.com/robot/send?access_token=0f2d4ab13bcf17b55b403862463215970f1286702ecccdc0d01a60ddddddd"#钉钉号接口

function test(){

printf '{'

printf '"msgtype":"text",'

printf '"text":{'

printf'"content":"'"$1"\"""

printf '}}'

}

Text="$(test $1)"

Json="Content-Type:application/json"

/usr/bin/curl $Gtoken -H $Json -d $Text

#/usr/bin/curl --data-ascii $Text $Gtoken

 

 

猜你喜欢

转载自blog.csdn.net/hzx1464138068/article/details/78212581