mirror of https://github.com/openspug/spug
U - 优化钉钉消息通知。
parent
e26650befd
commit
bb2f6bac68
|
@ -16,7 +16,7 @@ import uuid
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
from apps.system.models import NotifyWay
|
from apps.system.models import NotifyWay
|
||||||
from libs.utils import send_ding_msg
|
from libs.utils import send_ding_ding
|
||||||
|
|
||||||
|
|
||||||
blueprint = Blueprint(__name__, __name__)
|
blueprint = Blueprint(__name__, __name__)
|
||||||
|
@ -121,7 +121,7 @@ def do_update(q, form, host_id):
|
||||||
with_exit_code=True)
|
with_exit_code=True)
|
||||||
if exec_code != 0:
|
if exec_code != 0:
|
||||||
send_message('执行应用更新失败,退出状态码:{0}'.format(exec_code), level='error')
|
send_message('执行应用更新失败,退出状态码:{0}'.format(exec_code), level='error')
|
||||||
send_publish_message(pro.notify_way_id, pro.name + ' 发布失败!')
|
send_publish_message(pro.notify_way_id, pro.name + ' 发布失败!', status='failed')
|
||||||
send_message(exec_output, level='console')
|
send_message(exec_output, level='console')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -132,7 +132,7 @@ def do_update(q, form, host_id):
|
||||||
ctr.restart(timeout=3)
|
ctr.restart(timeout=3)
|
||||||
send_message('重启容器成功!', update=True)
|
send_message('重启容器成功!', update=True)
|
||||||
# 整个流程正常结束
|
# 整个流程正常结束
|
||||||
send_publish_message(pro.notify_way_id, pro.name + ' 发布成功')
|
send_publish_message(pro.notify_way_id, pro.name + ' 发布成功', status='success')
|
||||||
send_message('完成发布!', level='success')
|
send_message('完成发布!', level='success')
|
||||||
deploy_success = True
|
deploy_success = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -162,7 +162,19 @@ class PublishMessage(object):
|
||||||
q.put(data)
|
q.put(data)
|
||||||
|
|
||||||
|
|
||||||
def send_publish_message(notify_way_id, message):
|
def send_publish_message(notify_way_id, message, status='info'):
|
||||||
if notify_way_id:
|
if notify_way_id:
|
||||||
notice_value = NotifyWay.query.filter_by(id=notify_way_id).first()
|
notice_value = NotifyWay.query.filter_by(id=notify_way_id).first()
|
||||||
send_ding_msg(token=notice_value.value, contacts=[], msg=message)
|
if status == 'success':
|
||||||
|
publish_status = '<font color=\"#85CE60\">发布成功</font>'
|
||||||
|
elif status == 'failed':
|
||||||
|
publish_status = '<font color=\"#f90202\">发布失败</font>'
|
||||||
|
else:
|
||||||
|
publish_status = '<font color=\"#A6A9AD\">开始发布</font>'
|
||||||
|
|
||||||
|
msg = f'# <font face=\"微软雅黑\">运维平台通知</font> # \n <br> \n ' \
|
||||||
|
f'**发布信息:** {message} \n \n ' \
|
||||||
|
f'**平台地址:** http://spug.qbangmang.com \n \n ' \
|
||||||
|
f'**发布状态:** {publish_status}<br /> \n \n ' \
|
||||||
|
|
||||||
|
send_ding_ding(token_url=notice_value.value, contacts=[], msg=msg)
|
||||||
|
|
|
@ -2,6 +2,7 @@ from flask import Blueprint, request
|
||||||
from libs.tools import json_response, JsonParser, Argument
|
from libs.tools import json_response, JsonParser, Argument
|
||||||
from .models import NotifyWay
|
from .models import NotifyWay
|
||||||
from libs.decorators import require_permission
|
from libs.decorators import require_permission
|
||||||
|
from libs.utils import send_ding_ding
|
||||||
|
|
||||||
|
|
||||||
blueprint = Blueprint(__name__, __name__)
|
blueprint = Blueprint(__name__, __name__)
|
||||||
|
@ -58,3 +59,15 @@ def put(n_id):
|
||||||
notify_info.save()
|
notify_info.save()
|
||||||
return json_response(notify_info)
|
return json_response(notify_info)
|
||||||
return json_response(message=error)
|
return json_response(message=error)
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.route('/test/<int:d_id>', methods=['POST'])
|
||||||
|
def send_ding_test(d_id):
|
||||||
|
if d_id:
|
||||||
|
notice_value = NotifyWay.query.filter_by(id=d_id).first()
|
||||||
|
message = f'# <font face=\"微软雅黑\">运维平台通知</font> # \n ' \
|
||||||
|
'**平台地址:** http://spug.qbangmang.com \n \n ' \
|
||||||
|
'**测试状态:** <font color=\"#85CE60\">测试成功</font><br /> \n \n '
|
||||||
|
|
||||||
|
send_ding_ding(token_url=notice_value.value, contacts=[], msg=message)
|
||||||
|
return json_response()
|
||||||
|
|
|
@ -225,18 +225,11 @@ class Git(object):
|
||||||
return '<Git %r>' % self.work_tree
|
return '<Git %r>' % self.work_tree
|
||||||
|
|
||||||
|
|
||||||
def send_ding_msg(token_url='', contacts=[], msg=''):
|
def send_ding_ding(token_url='', contacts='', msg=''):
|
||||||
payload = {
|
payload = {"msgtype": "markdown", "markdown": {"title": "运维平台", "text": msg}}
|
||||||
"msgtype": "text",
|
binary_data = json.dumps(payload).encode(encoding='UTF8')
|
||||||
"text": {
|
headers = {"Content-Type": "application/json"}
|
||||||
"content": msg,
|
req = requests.post(token_url, data=binary_data, headers=headers)
|
||||||
"isAtAll": False
|
|
||||||
},
|
|
||||||
"at": {
|
|
||||||
"atMobiles": contacts
|
|
||||||
}
|
|
||||||
}
|
|
||||||
req = requests.post(token_url, json=payload)
|
|
||||||
if req.status_code == 200:
|
if req.status_code == 200:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
<el-table-column v-if="has_permission('system_notify_view|system_notify_add|system_notify_edit')" label="操作">
|
<el-table-column v-if="has_permission('system_notify_view|system_notify_add|system_notify_edit')" label="操作">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button v-if="has_permission('system_notify_edit')" size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
|
<el-button v-if="has_permission('system_notify_edit')" size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
|
||||||
|
<el-button v-if="has_permission('system_notify_add')" type="primary" size="small"
|
||||||
|
@click="handleDingTest(scope.row)">测试</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
@ -49,7 +51,9 @@
|
||||||
<el-input v-model="editForm.name" ></el-input>
|
<el-input v-model="editForm.name" ></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="value" label="通知URL" >
|
<el-form-item prop="value" label="通知URL" >
|
||||||
<el-input placeholder="输入钉钉webhook" type="textarea" :rows="3" v-model="editForm.value" auto-complete="off"></el-input>
|
<el-input
|
||||||
|
placeholder="钉钉机器人完整URL,例如:https://oapi.dingtalk.com/robot/send?access_token=858124219d02d5bf412aab28a0b26"
|
||||||
|
type="textarea" :rows="3" v-model="editForm.value" auto-complete="off"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item prop="desc" label="备注信息">
|
<el-form-item prop="desc" label="备注信息">
|
||||||
|
@ -155,6 +159,12 @@
|
||||||
this.getUsers(this.currentPage);
|
this.getUsers(this.currentPage);
|
||||||
}, response => this.$layer_message(response.result)).finally(() => this.btnDelLoading = {});
|
}, response => this.$layer_message(response.result)).finally(() => this.btnDelLoading = {});
|
||||||
},
|
},
|
||||||
|
handleDingTest: function (row){
|
||||||
|
this.$http.post(`/api/system/notify/test/${row.id}`, row).then( res=> {
|
||||||
|
this.$layer_message('测试成功', 'success');
|
||||||
|
this.getNotify(this.currentPage);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
editSubmit: function () {
|
editSubmit: function () {
|
||||||
this.$refs.editForm.validate((valid) => {
|
this.$refs.editForm.validate((valid) => {
|
||||||
|
|
Loading…
Reference in New Issue