zoukankan      html  css  js  c++  java
  • 使用python实现钉钉告警通知功能

    前言:日常工作中告警通知是必不可少的,一般会使用邮件、钉钉、企业微信等,今天分享一下使用python实现钉钉告警

    一. 钉钉机器人创建

    登录钉钉客户端,创建一个群,把需要收到报警信息的人员都拉到这个群内.然后点击群右上角的"群机器人"->"添加机器人"->"自定义",记录该机器人的webhook值!
     
    安全设置必须选一个,选择自定义关键词,凡是包含有告警这两个字的都会触发
    点击完成之后会生成类似下面的连接
    https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxx
    测试一下是否可以使用
    curl 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxx' -H 'Content-Type: application/json' -d '{"msgtype": "text","text": {"content": "告警:好好好"}}'
    

    二、实例

    import subprocess,json,sys,os,datetime
    try:
        import requests
    except Exception as e:
        subprocess.getstatusoutput('pip install requests -i http://pypi.douban.com/simple  --trusted-host pypi.douban.com')
    
    def dingtalk_warning(message):
        webhook = "https://oapi.dingtalk.com/robot/send?access_token=a0e849473bde502f547e4eb66"
        headers = {'Content-Type': 'application/json'}
        data={
            "msgtype": "text",
            "text": {
                "content": message,
            },
        }
    
        x=requests.post(url=webhook,data=json.dumps(data),headers=headers)
        if x.json()["errcode"] == 0:
            return True
        else:
            return False
    dingtalk_warning('告警:测试')

    运行查看结果

     如果使用zabbix监控软件,也可以结合使用~

      

  • 相关阅读:
    判断单链表中是否有环,找到环的入口节点的理论证明
    交叉熵代价函数(作用及公式推导)
    C#调用C++、Opencv的Dll
    腾讯机器学习一面面经
    C#调用C++类库的几种方式
    2017年腾讯基础研究笔试感受
    关于开源库或者SDK的文档问题
    卷积神经网络Lenet-5实现
    NULL、0、nullptr 区别分析
    C++中,new/delete和malloc/free的区别
  • 原文地址:https://www.cnblogs.com/lucktomato/p/14757552.html
Copyright © 2011-2022 走看看