zoukankan      html  css  js  c++  java
  • Zabbix告警脚本-微信

    1、weixin.sh

    [root@iot-svndata02 bin]# cat weixin.sh
    #!/bin/bash
    ###SCRIPT_NAME:weixin.sh###
    ###send message from weixin for zabbix monitor###
    ###zongx###
    ###V1-2017-06-12###
    
    #CropID='wx01975981c5d1502c'
    #Secret='k6hjyg4UY1Sx4YZIA6teqq5Q_cjjuDKliN3fVCUksN0'
    #GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret" 
    #Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F " '{print $10}')
    
    Gtoken=(`cat  /etc/zabbix/bin/token_new.txt`)
    echo "Gtoken="$Gtoken
    
    PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
    
    function body() {
            local int AppID=1000002                  #企业号中的应用id
    #        local UserID=@all                         #部门成员id,zabbix中定义的微信接收者
            local UserID=$1
            local PartyID=@all                        #部门id,定义了范围,组内成员都可接收到消息
            local Msg=$(echo "$@" | cut -d" " -f3-)  #过滤出zabbix中传递的第三个参数
            printf '{
    '
            printf '	"touser": "'"$UserID""",
    "
    #        printf '	"toparty": "'"$PartyID""",
    "
            printf '	"msgtype": "text",
    '
            printf '	"agentid": "'"$AppID""",
    "
            printf '	"text": {
    '
            printf '		"content": "'"$Msg"""
    "
            printf '	},
    '
            printf '	"safe":"0"
    '
            printf '}
    '
    }
    /usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL
    
    time=`date +"%Y-%m-%d"`
    echo "`date`    $1      $2     $3">>/var/log/zabbix/zbx_weixin-$time.log
    [root@iot-svndata02 bin]#

    2、token_new.txt

    [root@iot-svndata02 bin]# cat token_new.txt
    v2MHGuET7Z1usPvKSE0W5xyIfNrN8NzsPYOKWOdAYXBWpYjdOcp_0T_Ub3ig1jE_bjJq15YzQLvhwnorQiu8iUGwfbkr-0HOQ8AzkFiRwK_GLE7xQURy8JUlopP0ANES4nW-BD2XyVUhSDr1lmO-BiPNJFxgHvlQDPJfrObSyvc4e8kFFdMl5463GDPZv-ZbA_QGy4zAsfs6AGW1nhb7YQ
    [root@iot-svndata02 bin]#
  • 相关阅读:
    Eclipse解决Ctrl+c很卡的方法
    关于编程,大学没有传授的十件事-月光博客
    最牛B的编码套路
    (CareerCup)find the largest repetitive sequence
    (CareerCup)Find next higher number with same digits
    2013年HTML5峰会 一场守望者的盛宴
    Youzi2D推出开源HTML5游戏加速引擎
    HTML5与原生APP之争胜负已出?
    编程的未来
    拖拽即可创建HTML5网站的建站平台
  • 原文地址:https://www.cnblogs.com/shawhe/p/9583575.html
Copyright © 2011-2022 走看看