zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    js 删除数组的某一项或者几项的方法
    JavaScript 面向对象的程序设计(一)之理解对象属性
    iview 之 穿梭框 transfer
    iview2.0 bug之+8 区的 DatePicker
    js Object.keys 用法
    js map 、filter 、forEach 、every、some 的用法
    iview tree 之如何获取已勾选的节点
    js 中常见的深拷贝的方法
    ES6新特性
    Amazon2014在线笔试 第三题
  • 原文地址:https://www.cnblogs.com/ld1977/p/9402588.html
Copyright © 2011-2022 走看看