#coding=utf8
import requests
import json
import time
import sys
def send_report(reporter,report_text,url):
reporter = ‘‘
now_time = time.strftime(‘%Y-%m-%d %H:%M:%S‘, time.localtime(time.time()))
url = ‘https://oapi.dingtalk.com/robot/send?access_token=‘
if reporter:
reporter = ‘@{}‘.format(reporter)
data={
"msgtype": "markdown",
"markdown": {
"title":"一体化部署错误",
"text": "一体化部署错误 {} \n\n "
"{}\n\n"
"告警时间 {} [点击查看]({}) \n".format(reporter,report_text,now_time,url),
"at":{
"atMobiles":
[
],
"isAtAll": False
}
}
}
header={‘Content-Type‘: ‘application/json‘}
data=json.dumps(data,encoding=‘utf8‘)
res=requests.post(url,data=data,headers=header)
if res.status_code!=200:
print ‘发送通知失败‘,res.text
sys.exit(1)
else:
print ‘发送通知成功‘
send_report(‘‘,‘上传文件失败‘,‘‘)
原文:https://www.cnblogs.com/slqt/p/11570768.html