Use With Blueprints
|
@ -3,7 +3,7 @@ eth=$(ls /sys/class/net/ | grep -v "`ls /sys/devices/virtual/net/`")
|
|||
ip=$(ip addr | grep $eth | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}' | head -1)
|
||||
cd flask-consul
|
||||
docker build -t flask-consul:latest .
|
||||
cd ../nginx-consul
|
||||
cd ../vue-consul
|
||||
docker build -t nginx-consul:latest .
|
||||
|
||||
echo -e "\n\n自行编译的版本,注意修改docker-compose.yml中的镜像地址为本地仓库后再启动。"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
vf=$1
|
||||
vb=$2
|
||||
vf=0.1.3
|
||||
vb=0.2.0
|
||||
docker login --username=starsliao@163.com registry.cn-shenzhen.aliyuncs.com
|
||||
|
||||
docker tag nginx-consul:latest registry.cn-shenzhen.aliyuncs.com/starsl/nginx-consul:latest
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
__pycache__/
|
||||
*.pyc
|
|
@ -0,0 +1,2 @@
|
|||
__pycache__/
|
||||
*.pyc
|
|
@ -1,6 +1,7 @@
|
|||
FROM python:3-alpine
|
||||
ADD . /
|
||||
ADD . /flask
|
||||
WORKDIR /flask
|
||||
RUN pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
||||
#&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
EXPOSE 2026
|
||||
CMD ["python3","/flaskconsul.py"]
|
||||
CMD ["python3","./manager.py"]
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
import os
|
||||
from itsdangerous import TimedJSONWebSignatureSerializer
|
||||
|
||||
consul_token = os.environ.get('consul_token','a94d1ecb-81d3-ea0a-4dc8-5e6701e528c5')
|
||||
consul_url = os.environ.get('consul_url','http://10.5.148.67:8500/v1')
|
||||
admin_passwd = os.environ.get('admin_passwd','cass.007')
|
||||
secret_key = os.environ.get('secret_key',consul_token)
|
||||
s = TimedJSONWebSignatureSerializer(secret_key)
|
|
@ -1,150 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
from flask import Flask
|
||||
from flask_restful import reqparse, Api, Resource
|
||||
from flask_httpauth import HTTPTokenAuth
|
||||
from itsdangerous import TimedJSONWebSignatureSerializer
|
||||
#from flask_cors import CORS
|
||||
import requests,json,os
|
||||
|
||||
app = Flask(__name__)
|
||||
#CORS(app)
|
||||
auth = HTTPTokenAuth()
|
||||
api = Api(app)
|
||||
|
||||
consul_token = os.environ.get('consul_token')
|
||||
consul_url = os.environ.get('consul_url')
|
||||
admin_passwd = os.environ.get('admin_passwd')
|
||||
secret_key = os.environ.get('secret_key',consul_token)
|
||||
|
||||
headers = {'X-Consul-Token': consul_token}
|
||||
s = TimedJSONWebSignatureSerializer(secret_key)
|
||||
|
||||
@auth.verify_token
|
||||
def verify_token(token):
|
||||
try:
|
||||
data = s.loads(token)
|
||||
except:
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_all_list(module,company,project,env):
|
||||
module = f'and Meta.module=="{module}"' if module != '' else f'and Meta.module != ""'
|
||||
company = f'and Meta.company=="{company}"' if company != '' else f'and Meta.company != ""'
|
||||
project = f'and Meta.project=="{project}"' if project != '' else f'and Meta.project != ""'
|
||||
env = f'and Meta.env=="{env}"' if env != '' else f'and Meta.env != ""'
|
||||
url = f'{consul_url}/agent/services?filter=Service == blackbox_exporter {module} {company} {project} {env}'
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
info = response.json()
|
||||
all_list = [i['Meta'] for i in info.values()]
|
||||
module_list = sorted(list(set([i['module'] for i in all_list])))
|
||||
company_list = sorted(list(set([i['company'] for i in all_list])))
|
||||
project_list = sorted(list(set([i['project'] for i in all_list])))
|
||||
env_list = sorted(list(set([i['env'] for i in all_list])))
|
||||
return {'code': 20000,'all_list':all_list,'module_list':module_list,
|
||||
'company_list':company_list,'project_list':project_list,'env_list':env_list}
|
||||
else:
|
||||
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}
|
||||
|
||||
def get_service():
|
||||
response = requests.get(f'{consul_url}/agent/services?filter=Service == blackbox_exporter', headers=headers)
|
||||
if response.status_code == 200:
|
||||
info = response.json()
|
||||
all_list = [i['Meta'] for i in info.values()]
|
||||
module_list = sorted(list(set([i['module'] for i in all_list])))
|
||||
company_list = sorted(list(set([i['company'] for i in all_list])))
|
||||
project_list = sorted(list(set([i['project'] for i in all_list])))
|
||||
env_list = sorted(list(set([i['env'] for i in all_list])))
|
||||
return {'code': 20000,'all_list':all_list,'module_list':module_list,
|
||||
'company_list':company_list,'project_list':project_list,'env_list':env_list}
|
||||
else:
|
||||
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}
|
||||
|
||||
def add_service(module,company,project,env,name,instance):
|
||||
sid = f"{module}/{company}/{project}/{env}@{name}"
|
||||
data = {
|
||||
"id": sid,
|
||||
"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:
|
||||
return {"code": 20000, "data": f"【{sid}】增加成功!"}
|
||||
else:
|
||||
return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"}
|
||||
def del_service(module,company,project,env,name):
|
||||
sid = f"{module}/{company}/{project}/{env}@{name}"
|
||||
reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers)
|
||||
if reg.status_code == 200:
|
||||
return {"code": 20000, "data": f"【{sid}】删除成功!"}
|
||||
else:
|
||||
return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"}
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('module',type=str)
|
||||
parser.add_argument('company',type=str)
|
||||
parser.add_argument('project',type=str)
|
||||
parser.add_argument('env',type=str)
|
||||
parser.add_argument('name',type=str)
|
||||
parser.add_argument('instance',type=str)
|
||||
parser.add_argument('username',type=str)
|
||||
parser.add_argument('password',type=str)
|
||||
parser.add_argument('del_dict',type=dict)
|
||||
parser.add_argument('up_dict',type=dict)
|
||||
|
||||
class User(Resource):
|
||||
@auth.login_required
|
||||
def get(self, user_opt):
|
||||
if user_opt == 'info':
|
||||
return {
|
||||
"code": 20000,
|
||||
"data": {"roles": ["admin"],"name": "admin","avatar": "/sl.png"}}
|
||||
def post(self, user_opt):
|
||||
if user_opt == 'login':
|
||||
args = parser.parse_args()
|
||||
username = args.get('username')
|
||||
password = args.get('password')
|
||||
if password == admin_passwd:
|
||||
token = str(s.dumps(admin_passwd),encoding="utf-8")
|
||||
return {"code": 20000,"data": {"token": "Bearer " + token}}
|
||||
else:
|
||||
return {"code": 40000, "data": "密码错误!"}
|
||||
elif user_opt == 'logout':
|
||||
return {"code": 20000,"data": "success"}
|
||||
|
||||
class GetAllList(Resource):
|
||||
@auth.login_required
|
||||
def get(self):
|
||||
args = parser.parse_args()
|
||||
return get_all_list(args['module'],args['company'],args['project'],args['env'])
|
||||
|
||||
class ConsulApi(Resource):
|
||||
decorators = [auth.login_required]
|
||||
def get(self):
|
||||
return get_service()
|
||||
def post(self):
|
||||
args = parser.parse_args()
|
||||
return add_service(args['module'],args['company'],args['project'],args['env'],args['name'],args['instance'])
|
||||
def put(self):
|
||||
args = parser.parse_args()
|
||||
del_dict = args['del_dict']
|
||||
up_dict = args['up_dict']
|
||||
resp_del = del_service(del_dict['module'],del_dict['company'],
|
||||
del_dict['project'],del_dict['env'],del_dict['name'])
|
||||
resp_add = add_service(up_dict['module'],up_dict['company'],up_dict['project'],
|
||||
up_dict['env'],up_dict['name'],up_dict['instance'])
|
||||
if resp_del["code"] == 20000 and resp_add["code"] == 20000:
|
||||
return {"code": 20000, "data": f"更新成功!"}
|
||||
else:
|
||||
return {"code": 50000, "data": f"更新失败!"}
|
||||
def delete(self):
|
||||
args = parser.parse_args()
|
||||
return del_service(args['module'],args['company'],args['project'],args['env'],args['name'])
|
||||
|
||||
api.add_resource(GetAllList,'/api/consul/alllist')
|
||||
api.add_resource(ConsulApi, '/api/consul/service')
|
||||
api.add_resource(User, '/api/user/<user_opt>')
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=2026)
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
from flask import Flask
|
||||
from views import login, blackbox
|
||||
|
||||
app = Flask(__name__)
|
||||
app.register_blueprint(login.blueprint)
|
||||
app.register_blueprint(blackbox.blueprint)
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=2026)
|
|
@ -0,0 +1,61 @@
|
|||
import requests,json
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from config import consul_token,consul_url
|
||||
|
||||
headers = {'X-Consul-Token': consul_token}
|
||||
|
||||
def get_all_list(module,company,project,env):
|
||||
module = f'and Meta.module=="{module}"' if module != '' else f'and Meta.module != ""'
|
||||
company = f'and Meta.company=="{company}"' if company != '' else f'and Meta.company != ""'
|
||||
project = f'and Meta.project=="{project}"' if project != '' else f'and Meta.project != ""'
|
||||
env = f'and Meta.env=="{env}"' if env != '' else f'and Meta.env != ""'
|
||||
url = f'{consul_url}/agent/services?filter=Service == blackbox_exporter {module} {company} {project} {env}'
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
info = response.json()
|
||||
all_list = [i['Meta'] for i in info.values()]
|
||||
module_list = sorted(list(set([i['module'] for i in all_list])))
|
||||
company_list = sorted(list(set([i['company'] for i in all_list])))
|
||||
project_list = sorted(list(set([i['project'] for i in all_list])))
|
||||
env_list = sorted(list(set([i['env'] for i in all_list])))
|
||||
return {'code': 20000,'all_list':all_list,'module_list':module_list,
|
||||
'company_list':company_list,'project_list':project_list,'env_list':env_list}
|
||||
else:
|
||||
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}
|
||||
|
||||
def get_service():
|
||||
response = requests.get(f'{consul_url}/agent/services?filter=Service == blackbox_exporter', headers=headers)
|
||||
if response.status_code == 200:
|
||||
info = response.json()
|
||||
all_list = [i['Meta'] for i in info.values()]
|
||||
module_list = sorted(list(set([i['module'] for i in all_list])))
|
||||
company_list = sorted(list(set([i['company'] for i in all_list])))
|
||||
project_list = sorted(list(set([i['project'] for i in all_list])))
|
||||
env_list = sorted(list(set([i['env'] for i in all_list])))
|
||||
return {'code': 20000,'all_list':all_list,'module_list':module_list,
|
||||
'company_list':company_list,'project_list':project_list,'env_list':env_list}
|
||||
else:
|
||||
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}
|
||||
|
||||
def add_service(module,company,project,env,name,instance):
|
||||
sid = f"{module}/{company}/{project}/{env}@{name}"
|
||||
data = {
|
||||
"id": sid,
|
||||
"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:
|
||||
return {"code": 20000, "data": f"【{sid}】增加成功!"}
|
||||
else:
|
||||
return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"}
|
||||
|
||||
def del_service(module,company,project,env,name):
|
||||
sid = f"{module}/{company}/{project}/{env}@{name}"
|
||||
reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers)
|
||||
if reg.status_code == 200:
|
||||
return {"code": 20000, "data": f"【{sid}】删除成功!"}
|
||||
else:
|
||||
return {"code": 50000, "data": f"{reg.status_code}【{sid}】{reg.text}"}
|
|
@ -0,0 +1,14 @@
|
|||
from flask_httpauth import HTTPTokenAuth
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from config import s
|
||||
|
||||
auth = HTTPTokenAuth()
|
||||
|
||||
@auth.verify_token
|
||||
def verify_token(token):
|
||||
try:
|
||||
data = s.loads(token)
|
||||
except:
|
||||
return False
|
||||
return True
|
|
@ -0,0 +1,51 @@
|
|||
from flask import Blueprint
|
||||
from flask_restful import reqparse, Resource, Api
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from units import token_auth,blackbox_manager
|
||||
|
||||
blueprint = Blueprint('blackbox',__name__)
|
||||
api = Api(blueprint)
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('module',type=str)
|
||||
parser.add_argument('company',type=str)
|
||||
parser.add_argument('project',type=str)
|
||||
parser.add_argument('env',type=str)
|
||||
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)
|
||||
|
||||
class GetAllList(Resource):
|
||||
@token_auth.auth.login_required
|
||||
def get(self):
|
||||
args = parser.parse_args()
|
||||
return blackbox_manager.get_all_list(args['module'],args['company'],args['project'],args['env'])
|
||||
|
||||
class BlackboxApi(Resource):
|
||||
decorators = [token_auth.auth.login_required]
|
||||
def get(self):
|
||||
return blackbox_manager.get_service()
|
||||
def post(self):
|
||||
args = parser.parse_args()
|
||||
return blackbox_manager.add_service(args['module'],args['company'],args['project'],
|
||||
args['env'],args['name'],args['instance'])
|
||||
def put(self):
|
||||
args = parser.parse_args()
|
||||
del_dict = args['del_dict']
|
||||
up_dict = args['up_dict']
|
||||
resp_del = blackbox_manager.del_service(del_dict['module'],del_dict['company'],
|
||||
del_dict['project'],del_dict['env'],del_dict['name'])
|
||||
resp_add = blackbox_manager.add_service(up_dict['module'],up_dict['company'],up_dict['project'],
|
||||
up_dict['env'],up_dict['name'],up_dict['instance'])
|
||||
if resp_del["code"] == 20000 and resp_add["code"] == 20000:
|
||||
return {"code": 20000, "data": f"更新成功!"}
|
||||
else:
|
||||
return {"code": 50000, "data": f"更新失败!"}
|
||||
def delete(self):
|
||||
args = parser.parse_args()
|
||||
return blackbox_manager.del_service(args['module'],args['company'],args['project'],args['env'],args['name'])
|
||||
|
||||
api.add_resource(GetAllList,'/api/blackbox/alllist')
|
||||
api.add_resource(BlackboxApi, '/api/blackbox/service')
|
|
@ -0,0 +1,35 @@
|
|||
from flask import Blueprint
|
||||
from flask_restful import reqparse, Resource, Api
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from config import admin_passwd,s
|
||||
from units import token_auth
|
||||
|
||||
blueprint = Blueprint('login',__name__)
|
||||
api = Api(blueprint)
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('username',type=str)
|
||||
parser.add_argument('password',type=str)
|
||||
|
||||
class User(Resource):
|
||||
@token_auth.auth.login_required
|
||||
def get(self, user_opt):
|
||||
if user_opt == 'info':
|
||||
return {
|
||||
"code": 20000,
|
||||
"data": {"roles": ["admin"],"name": "admin","avatar": "/sl.png"}}
|
||||
def post(self, user_opt):
|
||||
if user_opt == 'login':
|
||||
args = parser.parse_args()
|
||||
username = args.get('username')
|
||||
password = args.get('password')
|
||||
if password == admin_passwd:
|
||||
token = str(s.dumps(admin_passwd),encoding="utf-8")
|
||||
return {"code": 20000,"data": {"token": "Bearer " + token}}
|
||||
else:
|
||||
return {"code": 40000, "data": "密码错误!"}
|
||||
elif user_opt == 'logout':
|
||||
return {"code": 20000,"data": "success"}
|
||||
|
||||
api.add_resource(User, '/api/user/<user_opt>')
|
|
@ -14,7 +14,7 @@
|
|||
"test:ci": "npm run lint && npm run test:unit"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "0.21.2",
|
||||
"axios": "0.18.1",
|
||||
"core-js": "3.6.5",
|
||||
"element-ui": "2.15.7",
|
||||
"file-saver": "2.0.1",
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
|
@ -2,7 +2,7 @@ import request from '@/utils/request-ops'
|
|||
|
||||
export function getAllList(module, company, project, env) {
|
||||
return request({
|
||||
url: '/api/consul/alllist',
|
||||
url: '/api/blackbox/alllist',
|
||||
method: 'get',
|
||||
params: { module, company, project, env }
|
||||
})
|
||||
|
@ -10,27 +10,27 @@ export function getAllList(module, company, project, env) {
|
|||
|
||||
export function getAllInfo() {
|
||||
return request({
|
||||
url: '/api/consul/service',
|
||||
url: '/api/blackbox/service',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
export function addService(data) {
|
||||
return request({
|
||||
url: '/api/consul/service',
|
||||
url: '/api/blackbox/service',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
export function updateService(del_dict, up_dict) {
|
||||
return request({
|
||||
url: '/api/consul/service',
|
||||
url: '/api/blackbox/service',
|
||||
method: 'put',
|
||||
data: { del_dict, up_dict }
|
||||
})
|
||||
}
|
||||
export function delService(data) {
|
||||
return request({
|
||||
url: '/api/consul/service',
|
||||
url: '/api/blackbox/service',
|
||||
method: 'delete',
|
||||
data
|
||||
})
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 497 B After Width: | Height: | Size: 497 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 944 B After Width: | Height: | Size: 944 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 285 B After Width: | Height: | Size: 285 B |
Before Width: | Height: | Size: 821 B After Width: | Height: | Size: 821 B |
Before Width: | Height: | Size: 623 B After Width: | Height: | Size: 623 B |
Before Width: | Height: | Size: 597 B After Width: | Height: | Size: 597 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 440 B After Width: | Height: | Size: 440 B |
|
@ -46,7 +46,7 @@ export const constantRoutes = [
|
|||
{
|
||||
path: '/',
|
||||
component: Layout,
|
||||
redirect: '/consul/index',
|
||||
redirect: '/blackbox/index',
|
||||
children: [{
|
||||
path: 'dashboard',
|
||||
name: 'Dashboard',
|
||||
|
@ -56,12 +56,12 @@ export const constantRoutes = [
|
|||
},
|
||||
|
||||
{
|
||||
path: '/consul',
|
||||
path: '/blackbox',
|
||||
component: Layout,
|
||||
children: [{
|
||||
path: 'index',
|
||||
name: '站点监控',
|
||||
component: () => import('@/views/consul/index'),
|
||||
component: () => import('@/views/blackbox/index'),
|
||||
meta: { title: '站点监控', icon: 'tree' }
|
||||
}]
|
||||
},
|