钉钉告警

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import requests
import json
import sys
import os

headers = {'Content-Type': 'application/json;charset=utf-8'}
TOKEN="XXXXXX"
api_url = "https://oapi.dingtalk.com/robot/send?access_token="+TOKEN


def dingAlert(text,mobile):
    json_text= {
     "msgtype": "text",
        "at": {
            "atMobiles": [
                str(mobile_number)  # 被联系人电话,就能@了
            ],
            "isAtAll": False
        },
        "text": {
            "content": text
        }
    }
    print(requests.post(api_url,json.dumps(json_text),headers=headers).content)

if __name__ == '__main__':
    text = sys.argv[1]
    mobile = sys.argv[2]
    dingAlert(text,mobile)

  

posted @ 2019-05-08 15:49 richardzgt 阅读(...) 评论(...) 编辑 收藏