zabbix3.4.x添加短信报警

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,并增加两个参数

zabbix3.4.x添加短信报警_第1张图片

四、增加Action

zabbix3.4.x添加短信报警_第2张图片

zabbix3.4.x添加短信报警_第3张图片

 

posted @ 2018-08-01 17:34 ld1977 阅读(...) 评论(...) 编辑 收藏

你可能感兴趣的:(Zabbix)