shell脚本之微信报警功能的实现
导语:现在越来越流行微信报警功能了。下面就来看看具体实现吧!
1.先申请一个微信企业号
传送门:http://work.weixin.qq.com/
2.添加用户

2.创建应用

3.创建管理组并添加管理员

接下来准备三个东西:
CorpID 在我的企业一栏中
AgentId
Secret 这2个都在应用中
API调试传送门:http://work.weixin.qq.com/api/devtools/devtool.php
shell脚本的实现
1 #!/bin/bash
2 # -*- coding: utf-8 -*-
3 ###SCRIPT_NAME:weixin.sh###
4 ###send message from weixin for monitoring###
5 ###leo###
6 ###V1-2017-09-05
7
8 CropID=‘xxx‘
9 Secret=‘xxx‘
10 GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
11 Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F " ‘{print $10}‘)
12 PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
13 function body() {
14 local int AppID=xxx # 企业号中的应用id
15 local UserID=$1 # 部门成员id,zabbix中定义的微信接收者
16 #local PartyID=$2 # 部门id,定义了范围,组内成员都可接收到消息
17 local Msg="hello" # 过滤出zabbix中传递的第三个参数
18 printf ‘{n‘
19 printf ‘t"touser": "‘$UserID‘",n‘
20 #printf ‘t"toparty": "$PartyID",n‘
21 printf ‘t"msgtype": "text",n‘
22 printf ‘t"agentid": "‘$AppID‘",n‘
23 printf ‘t"text": {n‘
24 printf ‘tt"content": "‘$Msg‘"n‘
25 printf ‘t},n‘
26 printf ‘t"safe":"0"n‘
27 printf ‘}n‘
28 }
29 #body $1
30 curl --data-ascii "$(body $1)" $PURL
31 printf ‘n‘
32 echo "over!"
cli 测试
sh weixin.sh mei
{ "touser": "mei", "msgtype": "text", "agentid": "xxx", "text": { "content": "hello" }, "safe":"0" } over!
手机上

OK!到此,通过微信企业号发送报警就成功实现了!
shell脚本之微信报警功能的实现
原文:http://www.cnblogs.com/leomei91/p/7479562.html