• zabbix3.4.x添加短信报警


    一、修改zabbix_server.conf

    #vi /etc/zabbix/zabbix_server.conf
    去掉注释:
    
    ### Option: AlertScriptsPath
    #       Full path to location of custom alert scripts.
    #       Default depends on compilation options.
    #
    # Mandatory: no
    # Default:
    # AlertScriptsPath=${datadir}/zabbix/alertscripts
    
    AlertScriptsPath=/usr/lib/zabbix/alertscripts

    二、编写脚本上传到上面的目录

    #!/usr/bin/env python
    # *-* coding:utf-8 *-*
    import hashlib,urllib,urllib2,sys,time,requests
    
    class REST_API:
        def __init__(self):
            self.ip = '118.190.103.79'
            self.user='ld1978'
            self.password = '135246'
            # self.md5_pwd = hashlib.md5(self.password.encode('utf-8')).hexdigest()
            # self.author = base64.b64encode(self.user + ':' + self.md5_pwd)
    
        def msm_sign(self):
    
            return hashlib.md5( "%s%s%s"%(self.user,self.password,time.strftime("%Y%m%d%H%M%S", time.localtime()))).hexdigest()
        def req_url(self,phone, content):
            content = '%s 【glp-zabbix】'%content
    
            data = {
                'userid': 3442,
                'timestamp':time.strftime("%Y%m%d%H%M%S", time.localtime()),
                'content': content,  # yes;内容
                'mobile': phone,  # yes;现只支持sms
                'sendTime': '',  # no;定时发送时间
                'extno': '',
                'sign':self.msm_sign() #sign
            }
    
            #data_re = urllib.urlencode(data)
            url = 'http://%s/v2sms.aspx?action=send' % (self.ip)
            response = requests.get(url, params=data)
    
            data = response.text
    
    
    
            if(data.find('Success') >=0):
                print "Success"
            else:
                print "Faild"
    
    
    
    if __name__ == '__main__':
    
        sms = REST_API()
        send_to = str(sys.argv[1])
        message = str(sys.argv[2])
        print type(send_to)
        sms.msm_sign()
        # 多个号码用,隔开像 189
        sms.req_url(send_to,message)
    sendsms.py

    三、在Administration->Media types下新增Media,并增加两个参数

    四、增加Action

  • 相关阅读:
    【扩展】1. PHP 大括号{} 的使用
    preg_replace 中修正符 e 的解析
    terminal 修改终端显示的名字
    find 命令详解
    OSI 7层结构 粗认识
    vi 全解析
    awk 学习笔记
    scp 复制远程文件 文件带空格 处理
    更新博客地址啦!!!
    ubuntu16.04安装NVIDIA驱动遇到的问题
  • 原文地址:https://www.cnblogs.com/ld1977/p/9402588.html
Copyright © 2020-2023  润新知