Dbdocker added web import

This commit is contained in:
StarsL.cn 2022-06-18 21:12:27 +08:00
parent 9189084f9d
commit 0e38bd4891
7 changed files with 325 additions and 2 deletions

View File

@ -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

View File

@ -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"导入成功!"}

View File

@ -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/<stype>')
api.add_resource(Blackbox_Upload_Web,'/api/blackboxcfg/upload_web')

View File

@ -53,3 +53,11 @@ export function getBconfig() {
method: 'get'
})
}
export function upload_web(data) {
return request({
url: '/api/blackboxcfg/upload_web',
method: 'get',
data
})
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

View File

@ -3,7 +3,7 @@
<el-alert type="success" center close-text="知道了">
<el-link icon="el-icon-warning" type="success" href="https://github.com/starsliao/ConsulManager/blob/main/docs/blackbox%E7%AB%99%E7%82%B9%E7%9B%91%E6%8E%A7.md" target="_blank">应用场景如何优雅的使用Consul管理Blackbox站点监控</el-link>
</el-alert>
<div class="filter-container">
<div class="filter-container" style="flex: 1;display: flex;align-items: center;height: 100px;">
<el-select v-model="listQuery.module" placeholder="监控类型" clearable collapse-tags style="width: 150px" class="filter-item">
<el-option v-for="item in module_list" :key="item" :label="item" :value="item" />
</el-select>
@ -25,10 +25,15 @@
<el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">
导出
</el-button>
<el-upload style="margin-right: 10px;" class="upload-demo" action="/api/blackboxcfg/upload_web" :on-success="success" :on-error="error" accept=".xlsx" :show-file-list="false" multiple :limit="1">
<el-button v-waves style="margin-left: 10px;" :loading="downloadLoading" class="filter-item" type="success" icon="el-icon-upload2">
导入
</el-button>
</el-upload>
<el-button class="filter-item" type="danger" icon="el-icon-delete" @click="handleDelAll">
批量删除
</el-button>
<div style="float: right;">
<div style="float: right;margin-left: 10px;">
<el-input v-model="iname" prefix-icon="el-icon-search" placeholder="请输入名称或实例进行筛选" clearable style="width:230px" class="filter-item" @input="inameFilter(iname)" />
</div>
</div>
@ -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()

View File

@ -0,0 +1,239 @@
<template>
<div class="login-container">
<div class="title-container" style="text-align:center">
<img src="../../assets/login_images/tensuns.png" width="800" height="400">
</div>
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left" style="padding: 10px 70px 0;">
<el-form-item prop="username">
<span class="svg-container">
<svg-icon icon-class="user" />
</span>
<el-input
ref="username"
v-model="loginForm.username"
placeholder="Username"
name="username"
type="text"
tabindex="1"
auto-complete="on"
/>
</el-form-item>
<el-form-item prop="password">
<span class="svg-container">
<svg-icon icon-class="password" />
</span>
<el-input
:key="passwordType"
ref="password"
v-model="loginForm.password"
:type="passwordType"
placeholder="Password"
name="password"
tabindex="2"
auto-complete="on"
@keyup.enter.native="handleLogin"
/>
<span class="show-pwd" @click="showPwd">
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
</span>
</el-form-item>
<el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">登 录</el-button>
</el-form>
<div align="center" class="title-container">
<span style="font-size:12px" class="title">v0.6.2</span>
</div>
</div>
</template>
<script>
import { validUsername } from '@/utils/validate'
export default {
name: 'Login',
data() {
const validateUsername = (rule, value, callback) => {
if (!validUsername(value)) {
callback(new Error('Please enter the correct user name'))
} else {
callback()
}
}
const validatePassword = (rule, value, callback) => {
if (value.length < 6) {
callback(new Error('The password can not be less than 6 digits'))
} else {
callback()
}
}
return {
loginForm: {
username: 'admin',
password: ''
},
loginRules: {
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
},
loading: false,
passwordType: 'password',
redirect: undefined
}
},
watch: {
$route: {
handler: function(route) {
this.redirect = route.query && route.query.redirect
},
immediate: true
}
},
methods: {
showPwd() {
if (this.passwordType === 'password') {
this.passwordType = ''
} else {
this.passwordType = 'password'
}
this.$nextTick(() => {
this.$refs.password.focus()
})
},
handleLogin() {
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true
this.$store.dispatch('user/login', this.loginForm).then(() => {
this.$router.push({ path: this.redirect || '/' })
this.loading = false
}).catch(() => {
this.loading = false
})
} else {
console.log('error submit!!')
return false
}
})
}
}
}
</script>
<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
$bg:#283443;
$light_gray:#fff;
$cursor: #fff;
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
.login-container .el-input input {
color: $cursor;
}
}
/* reset element-ui css */
.login-container {
.el-input {
display: inline-block;
height: 47px;
width: 85%;
input {
background: transparent;
border: 0px;
-webkit-appearance: none;
border-radius: 0px;
padding: 12px 5px 12px 15px;
color: $light_gray;
height: 47px;
caret-color: $cursor;
&:-webkit-autofill {
box-shadow: 0 0 0px 1000px $bg inset !important;
-webkit-text-fill-color: $cursor !important;
}
}
}
.el-form-item {
border: 2px solid rgba(255, 255, 255, 0.3);
background: rgba(0, 0, 0, 0.1);
border-radius: 5px;
color: #454545;
}
}
</style>
<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;
.login-container {
// min-height: 100%;
// width: 100%;
// background-color: $bg;
// overflow: hidden;
width: 100%;
height: 100%;
background-image: url("../../assets/login_images/bg.png");
background-size: cover;
background-position: center;
position: relative;
.login-form {
position: relative;
width: 460px;
max-width: 100%;
padding: 160px 35px 0;
margin: 0 auto;
overflow: hidden;
}
.tips {
font-size: 14px;
color: #fff;
margin-bottom: 10px;
span {
&:first-of-type {
margin-right: 16px;
}
}
}
.svg-container {
padding: 6px 5px 6px 15px;
color: $dark_gray;
vertical-align: middle;
width: 30px;
display: inline-block;
}
.title-container {
position: relative;
.title {
font-size: 26px;
color: $light_gray;
margin: 0px auto 20px auto;
text-align: center;
font-weight: bold;
}
}
.show-pwd {
position: absolute;
right: 10px;
top: 7px;
font-size: 16px;
color: $dark_gray;
cursor: pointer;
user-select: none;
}
}
</style>