diff --git a/flask-consul/requirements.txt b/flask-consul/requirements.txt index 8de167a..e1117f6 100644 --- a/flask-consul/requirements.txt +++ b/flask-consul/requirements.txt @@ -6,6 +6,7 @@ flask-cors==3.0.10 Flask-HTTPAuth==4.5.0 requests==2.27.1 Flask-APScheduler==1.12.3 +xlrd==1.2.0 #pyDes==2.0.1 pycryptodome==3.14.1 beautifulsoup4==4.11.1 diff --git a/flask-consul/units/upload.py b/flask-consul/units/upload.py new file mode 100644 index 0000000..bffb061 --- /dev/null +++ b/flask-consul/units/upload.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +import requests, json +import xlrd +import sys +sys.path.append("..") +from config import consul_token,consul_url + +def importconsul(row): + module, company, project, env, name, instance = row + headers = {'X-Consul-Token': consul_token} + data = { + "id": f"{module}/{company}/{project}/{env}@{name}", + "name": 'blackbox_exporter', + "tags": [module], + "Meta": {'module': module, 'company': company, 'project': project, 'env': env, 'name': name, + 'instance': instance} + } + + reg = requests.put(f"{consul_url}/agent/service/register", headers=headers, data=json.dumps(data)) + if reg.status_code == 200: + print({"code": 20000, "data": "增加成功!"},instance,flush=True) + else: + print({"code": 50000, "data": f'{reg.status_code}:{reg.text}'},instance,flush=True) + +def read_execl(file_contents): + data = xlrd.open_workbook(file_contents=file_contents, encoding_override="utf-8") + table = data.sheets()[0] + print("开始读取",flush=True) + for rownum in range(table.nrows): + row = table.row_values(rownum) + if rownum == 0: + continue + importconsul(row) + return {"code": 20000, "data": f"导入成功!"} diff --git a/flask-consul/views/blackbox.py b/flask-consul/views/blackbox.py index acbefed..136a5ff 100644 --- a/flask-consul/views/blackbox.py +++ b/flask-consul/views/blackbox.py @@ -3,6 +3,9 @@ from flask_restful import reqparse, Resource, Api import sys sys.path.append("..") from units import token_auth,blackbox_manager +from werkzeug.datastructures import FileStorage +from units import upload + blueprint = Blueprint('blackbox',__name__) api = Api(blueprint) @@ -16,6 +19,16 @@ parser.add_argument('name',type=str) parser.add_argument('instance',type=str) parser.add_argument('del_dict',type=dict) parser.add_argument('up_dict',type=dict) +parser.add_argument('file',type=FileStorage, location="files", help="File is wrong.") + +class Blackbox_Upload_Web(Resource): + def post(self): + file = parser.parse_args().get("file") + try: + return upload.read_execl(file.read()) + except Exception as e: + print("【blackbox】导入失败",e,flush=True) + return {"code": 50000, "data": f"导入失败!"} class GetAllList(Resource): @token_auth.auth.login_required @@ -60,3 +73,4 @@ class BlackboxApi(Resource): api.add_resource(GetAllList,'/api/blackbox/alllist') api.add_resource(BlackboxApi, '/api/blackbox/service') api.add_resource(GetConfig,'/api/blackboxcfg/') +api.add_resource(Blackbox_Upload_Web,'/api/blackboxcfg/upload_web') diff --git a/vue-consul/src/api/blackbox.js b/vue-consul/src/api/blackbox.js index 3c0d3cd..f970bc0 100644 --- a/vue-consul/src/api/blackbox.js +++ b/vue-consul/src/api/blackbox.js @@ -53,3 +53,11 @@ export function getBconfig() { method: 'get' }) } + +export function upload_web(data) { + return request({ + url: '/api/blackboxcfg/upload_web', + method: 'get', + data + }) +} diff --git a/vue-consul/src/assets/login_images/tensuns.png b/vue-consul/src/assets/login_images/tensuns.png new file mode 100644 index 0000000..5c2d910 Binary files /dev/null and b/vue-consul/src/assets/login_images/tensuns.png differ diff --git a/vue-consul/src/views/blackbox/index.vue b/vue-consul/src/views/blackbox/index.vue index 9bb1f86..0035082 100644 --- a/vue-consul/src/views/blackbox/index.vue +++ b/vue-consul/src/views/blackbox/index.vue @@ -3,7 +3,7 @@ 应用场景:如何优雅的使用Consul管理Blackbox站点监控 -
+
@@ -25,10 +25,15 @@ 导出 + + + 导入 + + 批量删除 -
+
@@ -259,6 +264,28 @@ export default { }, methods: { + success(response) { + if (response.code === 20000) { + this.fetchData() + this.$message({ + message: response.data, + type: 'success' + }) + } else { + this.$message({ + message: response.data, + type: 'error' + }) + } + }, + error(response) { + if (response.code === 50000) { + this.$message({ + message: response.data, + type: 'error' + }) + } + }, inameFilter(iname) { if (iname === '') { this.handleFilter() diff --git a/vue-consul/src/views/login/index.vue.tensuns b/vue-consul/src/views/login/index.vue.tensuns new file mode 100644 index 0000000..764e6e8 --- /dev/null +++ b/vue-consul/src/views/login/index.vue.tensuns @@ -0,0 +1,239 @@ + + + + + + +