Zabbix-3.2.6部署微信报警

一、准备数据php

企业微信的:CorpID
vim

企业应用的:AgentIdapi

企业应用的:Secretbash

接收消息的部门ID微信


二、建立企业应用并设置好权限app


三、微信接口调试工具网址curl

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


四、准备报警脚本
工具

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


五、脚本权限设置

vim /application/zabbix/etc/zabbix_server.conf


AlertScriptsPath=/application/zabbix/scripts/

chown zabbix.zabbix weixin.sh

chmod +x weixin.sh


六、测试脚本的可用性

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

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

微信1.png


七、在Web管理页面建立媒体类型

微信2.png


八、为Admin用户添加新建立的报警媒体

微信3.png


九、建立动做并测试

微信4.png

相关文章
相关标签/搜索