新建一个weixin.sh文件,内容如下
#!/bin/bash
# -*- coding: utf-8 -*-
###SCRIPT_NAME:weixin.sh###
###send message from weixin for monitoring###
###leo###
content=${@:1}
content=${content//\<font color=\'red\'\>/}
content=${content//\<\/font\>\<\/br\>/}
echo "告警信息 : $content"
CropID='xxx'
Secret='xxx'
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=xxx # 企业号中的应用id
local UserID=xxx # 部门成员id,微信接收者
#local PartyID=$2 # 部门id,定义了范围,组内成员都可接收到消息
local Msg="告警信息:$1"
printf '{\n'
printf '\t"touser": "'$UserID'",\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'
}
#body $content
curl --data-ascii "$(body $content)" $PURL
printf '\n'
echo "over!"
cli 测试
sh weixin.sh 测试
测试完成,修改/server/config/application.yml
#告警脚本文件,可以为空,参考:/server/template/sendMsg.sh
warnScript: /home/weixin.sh
好了,这样就可以在微信收到告警消息了
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。