-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
116 changed files
with
199 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/bash | ||
vf=$1 | ||
vb=$2 | ||
vf=0.1.3 | ||
vb=0.2.0 | ||
docker login [email protected] registry.cn-shenzhen.aliyuncs.com | ||
|
||
docker tag nginx-consul:latest registry.cn-shenzhen.aliyuncs.com/starsl/nginx-consul:latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__/ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__/ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>') |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
Oops, something went wrong.