• zabbix 微信告警脚本


    #!/usr/bin/env python3
    import requests
    import json
    import sys
    import os
    
    
    
    def access_token(Corpid,Secret):
        url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken"
        values = {"corpid":Corpid,"corpsecret":Secret}
        r = requests.get(url,params=values)
        data = json.loads(r.text)
        token = data['access_token']
        with open('/tmp/access.token','w') as f:
            f.write(token)
    
    def send_msg(toparty,agentid,token,content):
        url = "https://qyapi.weixin.qq.com/cgi-bin/message/send"
        values = {"access_token": token}
        data = {
           "toparty" : toparty,
           "msgtype" : "text",
           "agentid" : agentid,
           "text" : {
               "content" : content
           },
           "safe":0
        }
        r = requests.post(url,params=values,json=data)
        data = json.loads(r.text)
        code = data['errcode']
        return code
    
    def token():
        with open("/tmp/access.token",'r') as f:
            token = f.read()
        return  token
    
    if __name__ == "__main__":
        Corpid = "wwc67c4ff3846c4f6a"
        Secret = "-OWfdtJu8g4hbYWdb4hPn4rxN8o7_iTlpnnUxBLt-RY"
        agentid = 1000002
        toparty = sys.argv[1]
        content = sys.argv[2]
    
    
        if not os.path.exists("/tmp/access.token"):
            access_token(Corpid, Secret)
            token = token()
            send_msg(toparty, agentid, token, content)
        else:
            token = token()
            code = send_msg(toparty, agentid, token, content)
            if code != 0:
                access_token(Corpid, Secret)
                token = token()
                send_msg(toparty, agentid, token, content)
  • 相关阅读:
    使用Power Shell 拉取项目源代码
    C# 读取excel数据到datatable
    C# 导出datatable数据到excel
    redis过一段时间连接不上
    windows10 docker volume
    通过端口查询到应用
    centos清理磁盘
    maven镜像加速
    IDEA常用插件
    java开发常用软件
  • 原文地址:https://www.cnblogs.com/gaoyuanzhi/p/9699424.html
Copyright © 2020-2023  润新知