首页 > 微信 > 详细

Zabbix-3.2.6部署微信报警

时间:2018-03-30 10:37:18      阅读:332      评论:0      收藏:0      [点我收藏+]
1、准备数据

企业微信的:CorpID

企业应用的:AgentId

企业应用的:Secret

接收消息的部门ID


2、创建企业应用并设置好权限


3、微信接口调试工具网址

http://work.weixin.qq.com/api/devtools/devtool.php


4、准备报警脚本

vim /application/zabbix/scripts/weixin.sh

#!/bin/bash

CropID='  '

Secret='  '

 

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

Gtoken=$(/usr/bin/curl -s -G $GURL)

a=`echo $Gtoken |awk -F ':"' '{print $3}'`

token=`echo $a |awk -F '".' '{print $1}'`

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

 

function body() {

local int AppID=

local UserID=$1

local PartyID=

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": "'"$AppID "\"",\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


5、脚本权限设置

chown zabbix.zabbix weixin.sh

chmod +x weixin.sh


6、测试脚本的可用性

bash weixin.sh "ChenShuiTao" "test" "hello world"

说明:ChenShuiTao是企业微信用户的帐号、test为发送的标题、hello world为发送的内容

技术分享图片


7、在Web管理页面创建媒体类型

技术分享图片


8、为Admin用户添加新创建的报警媒体

技术分享图片


9、创建动作并测试

技术分享图片





Zabbix-3.2.6部署微信报警

原文:http://blog.51cto.com/12098963/2092763

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!