|
@@ -6,6 +6,8 @@ import datetime
|
|
|
# 获取jenkins构建信息和本次报告地址
|
|
|
import jenkins # 安装pip install python-jenkins
|
|
|
|
|
|
+from common.yaml_util import read_config_yaml
|
|
|
+
|
|
|
# 获取本机IP
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
# s.connect(("8.8.8.8", 80))
|
|
@@ -34,6 +36,9 @@ else:
|
|
|
'''
|
|
|
|
|
|
|
|
|
+# url = 'https://oapi.dingtalk.com/robot/send?access_token=f8566d2ed0feb8dc3bf2856df161241a8cf5a4c76af3d903abcabfdebebdff0e' # webhook
|
|
|
+
|
|
|
+
|
|
|
def DingTalkSend(info):
|
|
|
d = {}
|
|
|
# 获取项目绝对路径
|
|
@@ -42,7 +47,7 @@ def DingTalkSend(info):
|
|
|
print(rf"{path}" + rf"{file}")
|
|
|
# 打开prometheusData 获取需要发送的信息
|
|
|
# f = open(rf"{path}" + rf"{file}", 'r', encoding='UTF-8')
|
|
|
- f =open(os.getcwd()+file,'r', encoding='UTF-8')
|
|
|
+ f = open(os.getcwd() + file, 'r', encoding='UTF-8')
|
|
|
for lines in f:
|
|
|
for c in lines:
|
|
|
launch_name = lines.strip('\n').split(' ')[0]
|
|
@@ -64,7 +69,6 @@ def DingTalkSend(info):
|
|
|
print('不通过数量:{}'.format(status_failed))
|
|
|
|
|
|
# 钉钉推送
|
|
|
- url = 'https://oapi.dingtalk.com/robot/send?access_token=f8566d2ed0feb8dc3bf2856df161241a8cf5a4c76af3d903abcabfdebebdff0e' # webhook
|
|
|
text = (
|
|
|
f"<font color=\'#FFA500\'>[通知] </font>青春重庆-{info}报告"
|
|
|
"\n\n用例运行总数: " + retries_run +
|
|
@@ -75,10 +79,31 @@ def DingTalkSend(info):
|
|
|
"\n\n测试报告地址: \n" + report_url +
|
|
|
"\n\n播报时间: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) % (status_defects)
|
|
|
|
|
|
- dd_robot = DingtalkChatbot(url)
|
|
|
+ dd_robot = DingtalkChatbot(read_config_yaml("dingding", "prod_webhook"))
|
|
|
ret = dd_robot.send_markdown(title='青春重庆', text=text, is_at_all=False)
|
|
|
print(ret)
|
|
|
|
|
|
|
|
|
+def dingtalk_send_warning(msg):
|
|
|
+ """
|
|
|
+ 发送报警超时消息dingtalkchatbot
|
|
|
+ :param msg: 请求返回res
|
|
|
+ :return: none
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ res_time = round(msg.elapsed.total_seconds() * 1000, 2)
|
|
|
+ text = f"<font color=\'#FFA500\'>[通知] </font>青春重庆-报警"\
|
|
|
+ f"\n\n>请求接口路径: {msg.url}% " \
|
|
|
+ f"\n\n>请求体: {str(msg.request.body).replace('%','')}% "\
|
|
|
+ f"\n\n>接口响应时间: {res_time}毫秒 " \
|
|
|
+ f"\n\n>播报时间: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} "
|
|
|
+
|
|
|
+ dd_robot = DingtalkChatbot('')
|
|
|
+ dd_robot.send_markdown(title='青春重庆', text=text, is_at_all=False)
|
|
|
+ except Exception as e:
|
|
|
+ raise e
|
|
|
+
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
- DingTalkSend("生产APP巡检")
|
|
|
+ dingtalk_send_warning("测试")
|
|
|
+ # DingTalkSend("生产APP巡检")
|