• 腾讯云短信告警


    腾讯云短信告警

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    密钥获取地址:https://console.cloud.tencent.com/cam/capi

    在这里插入图片描述

    #!/bin/python
    #-*- coding: utf-8 -*-
    
    import json, sys
    from tencentcloud.common import credential
    from tencentcloud.common.profile.client_profile import ClientProfile
    from tencentcloud.common.profile.http_profile import HttpProfile
    from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
    from tencentcloud.sms.v20210111 import sms_client, models
    
    def sendtxy(msg,phone_id):
        try:
            #json str转成list列表形式,resvered是反转,先title后conetent
            msg_list=list(reversed(json.loads(msg).values()))
            # 实际中传过来的数据不是list类型的
            phone_id_list = eval((json.dumps(phone_id.split(","))))
         
            cred = credential.Credential("xxx" , "yyyy")
            httpProfile = HttpProfile()
            httpProfile.endpoint = "xxx"
            clientProfile = ClientProfile()
            clientProfile.httpProfile = httpProfile
            client = sms_client.SmsClient(cred , "ap-nanjing" , clientProfile)
    
            # 实例化一个请求对象,每个接口都会对应一个request对象
            req = models.SendSmsRequest()
            params = {
                # "PhoneNumberSet": [ "182xxxxxxxx", "153xxxxxxxx" ],
                "PhoneNumberSet": phone_id_list,
                "SmsSdkAppId": "1400xxxx" ,
                "SignName": "签名名称" ,
                "TemplateId": "模板id" ,
                "TemplateParamSet": msg_list
            }
            req.from_json_string(json.dumps(params))
    
            # 返回的resp是一个SendSmsResponse的实例,与请求对象对应
            resp = client.SendSms(req)
            # 输出json格式的字符串回包
            print(resp.to_json_string())
    
        except TencentCloudSDKException as err:
            print(err)
    
    
    
    if __name__ == "__main__":
       #当接收到告警信息时,调用下面函数即可
        sendtxy(sys.argv[1], sys.argv[2]) 
     
        #下面试调试
        #a=["基础监控】节点基础监控进程消失","\n告警详情: 节点:172.16.xx.xx:9101,主机名:hostname01\n节点:172.21.xx.xx:9101,主机名:hostname02\n告警级别:disaster\n告警模块:测试\n告警时间:2022-11-16 14:52:50" ]
        #b=["1825510xxxxx"]
        #sendtxy(a, b)
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57

    请添加图片描述

  • 相关阅读:
    C++【STL】【vector类的模拟实现】【迭代器失效问题】
    位 运 算
    《JAVA EE》内部类(下篇)&Lambda表达式
    深度解析DDoS攻击和CC攻击
    十大经典排序之归并排序
    UICollectionView 学习笔记
    YARP:探索反向代理的新境界
    SpringBoot学习(5) —— SpringBoot框架集成MyBatis
    管网数字孪生应用3d场景展示「优势解析」
    泰勒展开式记忆方法
  • 原文地址:https://blog.csdn.net/wyl9527/article/details/127887990