zoukankan      html  css  js  c++  java
  • Zabbix 3.4.3 使用阿里云短信服务进行报警

    一、阿里云短信服务

    有时候微信报警或者邮寄报警我们可能会有遗忘,今天我主要介绍使用阿里云的短信服务进行短信报警。

    1.1、首先开通阿里云短信服务

    1.2 创建签名

    签名用途选择:公众号或小程序的全称或简称 就可以了。

    1.3 创建短信模板

    模板里面的参数有字数限制,最高20个字符,所以大家也需要注意一下,获取的参数值不要太大。

    1.4 创建发送脚本

    创建脚本sendsms.py,放到 zabbix 脚本路径,记得在配置文件开启AlertScriptsPath=路径,我们向脚本传递两个参数,一个是手机号,一个是信息,信息里面包含三个字段(主机IP,时间,内容),由我们下面的 Media types 参数配置。

    #!/usr/bin/python3.6
    # coding=utf-8
    # pip3.6 install aliyun-python-sdk-core-v3
    
    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.request import CommonRequest
    import sys
    client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')
    
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https') # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')
    string = sys.argv[2]
    phone_number = sys.argv[1]
    message = string.split(";")
    print(message)
    dict1 = { }
    dict1['host'] = message[0]
    dict1['time'] = message[1]
    dict1['item'] = message[2][0:18]
    request.add_query_param('RegionId', 'cn-hangzhou')
    request.add_query_param('PhoneNumbers', phone_number)
    request.add_query_param('SignName', '某某监控报警')
    request.add_query_param('TemplateCode', 'SMS_159772654')
    request.add_query_param('TemplateParam', dict1)
    
    response = client.do_action(request)
    # python2:  print(response)
    print(str(response, encoding='utf-8'))
    

    二、Zabbix Web 配置

    2.1 增加 Media types

    2.2 给用户增加报警媒介

    2.3 创建 Actions

    关于告警的回复报警,以及阶梯报警,大家可以自行详细去设定,正常我们可以第一步发生短信报警,在多久之内没有恢复再进行短信报警。

    三、验证

    我们停掉一个服务,来验证一下,首先可以查看一下 Action log 查看是否成功。

    然后可以看到我们接到了短信通知。

  • 相关阅读:
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    C# List分组
    Win7安装VS2019
    C# Lambda Left Join AND Group by Then Sum
    RSA加密解密,Base64String
    Ion-select and ion-option list styling 自定义样式
    Docker镜像
  • 原文地址:https://www.cnblogs.com/wzlinux/p/11188385.html
Copyright © 2011-2022 走看看