【zabbix教程七】——zabbix3.0配置微信報警

  引言

  在前面的博客中我們介紹了zabbix3.0中的郵件報警的配置,但是對於郵件來說並不是非常的方便,所以我們在這篇博客中我們介紹另外一種報警方式——微信報警。

 第一、準備微信企業號

  關於企業微信號的註冊和配置,請請大家參考博客:http://www.iyunv.com/thread-166308-1-1.html

 第二、關於企業號中配置的幾個重點

   1、查看部門ID:

   


  2、新建應用的時候選擇消息型應用 並記錄應用ID

 

 

  3、設置管理組 

  


  比較重要的大概就是上面這麼幾點。

 第三、準備腳本

 

#!/bin/bash
#########################################################################
# File Name: weixin.sh
# Author: shaonbean
# Email: [email protected]
# Created Time: Sun 24 Jul 2016 05:48:14 AM CST
#########################################################################
# Functions: send messages to wechat app
# set variables
CropID='wxda13247ee2c2ff9b'
Secret='vJg7Q2H28_3qkjBsl2IxnLrHTP-3_SerljJvrrlHDLczqS1Vib8_umQHEQRi3kZs'
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
#get acccess_token
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $4}')
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
#
function body() {
local int AppID=1                        #企業號中的應用id
local UserID="touser"                        #部門成員id,zabbix中定義的微信接收者
local PartyID=2                           #部門id,定義了範圍,組內成員都可接收到消息
local Msg=$(echo "$@" | cut -d" " -f3-)   #過濾出zabbix傳遞的第三個參數
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 $! $2 $3)" $PURL
  將腳本weixin.sh 放在 /usr/lib/zabbix/alertscripts目錄下,和我們配置的郵件報警的腳本放在同一目錄下面。

 第三、微信接口調用

   調用微信接口需要一個調用接口的憑證:access_token
   通過CorpID和Secret可以獲得access_token
   微信企業號接口調試地址: http://qydev.weixin.qq.com/debug

 

  第四、腳本測試

   進入 /usr/lib/zabbix/alertscripts 執行命令 bash weixin.sh test hello.world!

  

  第五、頁面配置

    創建媒介類型和我們配置郵件報警步驟一樣

  

 第六、配置用戶

  

 第七、配置觸發器

   步驟和前面的博客中的配置步驟一樣


 第八測試、

   


  小結

  到這關於微信報警的配置就已經完成了,希望對讀者有所幫助!

  

  


  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章