forked from hhyo/Archery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 17 commits.
# This is the 1st commit message: Initial commit # This is the commit message hhyo#2: django framework. # This is the commit message hhyo#3: django. # This is the commit message hhyo#4: django 1 # This is the commit message hhyo#5: base.html # This is the commit message hhyo#6: user login, main menu. # This is the commit message hhyo#7: django admin, middleware. # This is the commit message hhyo#8: submitsql # This is the commit message hhyo#9: delete sth. # This is the commit message hhyo#10: 自动审核,人工审核,回滚功能 # This is the commit message hhyo#11: 所有历史工单展示 # This is the commit message hhyo#12: pymysql. # This is the commit message hhyo#13: static_root # This is the commit message hhyo#14: fix bug. # This is the commit message hhyo#15: fix bug # This is the commit message hhyo#16: readme updated. # This is the commit message hhyo#17: readme updated
- Loading branch information
0 parents
commit a299ddf
Showing
116 changed files
with
15,491 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.pyc | ||
*.swp | ||
*.lock | ||
*.log | ||
.idea/ | ||
.DS_Store |
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,50 @@ | ||
# archer | ||
基于inception的自动化SQL操作平台 | ||
|
||
### 开发语言 | ||
python:3.4 | ||
django:1.8 | ||
|
||
### 主要功能 | ||
* 发起inception SQL上线,工单提交 | ||
* 工单DBA人工审核、sql执行 | ||
* 历史工单展示 | ||
* 回滚数据展示 | ||
* 主库集群配置 | ||
* 用户权限配置<br/> | ||
工程师角色(engineer)与审核角色(review_man):工程师可以发起SQL上线,在通过了inception自动审核之后,需要由人工审核点击确认才能执行SQL | ||
* 历史工单管理 | ||
* 可通过django admin进行匹配SQL关键字的工单搜索 | ||
|
||
### 安装步骤: | ||
1. 安装python3:<br/> | ||
tar -xzvf Python-3.4.1.tar.gz <br/> | ||
cd Python-3.4.1 <br/> | ||
./configure --prefix=/path/to/python3 && make && make install | ||
或者rpm、yum、binary等其他安装方式 | ||
2. 安装django:<br/> | ||
tar -xzvf Django-1.8.17 && cd Django-1.8.17 && python3 setup.py install | ||
3. 给python3安装MySQLdb模块<br/> | ||
pip install pymysql<br/> | ||
记得确保settings.py里有如下两行:<br/> | ||
import pymysql<br/> | ||
pymysql.install_as_MySQLdb()<br/> | ||
<br/> | ||
由于python3使用的pymysql模块里并未兼容inception返回的server信息,因此需要编辑/path/to/python3/lib/python3.4/site-packages/pymysql/connections.py:<br/> | ||
在if int(self.server_version.split('.', 1)[0]) >= 5: 这一行前面加上下面一句并保存:<br/> | ||
self.server_version = '5.6.24-72.2-log'<br/> | ||
4. 通过model创建数据库表<br/> | ||
python3 manage.py makemigrations<br/> | ||
python3 manage.py migrate<br/> | ||
5. 记得登录到settings.py里配置的各个mysql里给用户授权<br/> | ||
(1)archer数据库授权<br/> | ||
(2)远程备份库授权<br/> | ||
6. 创建系统root用户(该用户可以使用django admin来管理model):<br/> | ||
cd archer && python3 manage.py createsuperuser<br/> | ||
7. 用django内置runserver启动服务:<br/> | ||
cd archer && bash debug.sh<br/> | ||
<br/> | ||
如果要用gunicorn启动服务的话,可以使用pip install gunicorn安装并用startup.sh启动,但需要配合nginx处理静态资源. | ||
|
||
### 联系方式: | ||
164473279@qq.com |
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,125 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
""" | ||
Django settings for archer project. | ||
Generated by 'django-admin startproject' using Django 1.8.17. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.8/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.8/ref/settings/ | ||
""" | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
import os | ||
import pymysql | ||
pymysql.install_as_MySQLdb() | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'hfusaf2m4ot#7)fkw#di2bu6(cv0@opwmafx5n#6=3d%x^hpl6' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = ( | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'sql', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
'django.middleware.security.SecurityMiddleware', | ||
'sql.check_login_middleware.CheckLoginMiddleware', | ||
) | ||
|
||
ROOT_URLCONF = 'archer.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [os.path.join(BASE_DIR, 'sql/static')], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
'sql.processor.global_info', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'archer.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases | ||
|
||
#该项目本身的mysql数据库地址 | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.mysql', | ||
'NAME': 'archer', | ||
'USER': 'archer_rw', | ||
'PASSWORD': 'archer_rw', | ||
'HOST': '172.21.139.1', | ||
'PORT': '5000' | ||
} | ||
} | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.8/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'Asia/Shanghai' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = False | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/1.8/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
STATIC_ROOT = os.path.join(BASE_DIR, 'static') | ||
|
||
#inception组件所在的地址 | ||
INCEPTION_HOST = '172.16.5.7' | ||
INCEPTION_PORT = '6100' | ||
|
||
#inception要备份数据到该远端mysql地址 | ||
INCEPTION_REMOTE_BACKUP_HOST='172.16.5.10' | ||
INCEPTION_REMOTE_BACKUP_PORT=5621 | ||
INCEPTION_REMOTE_BACKUP_USER='inception' | ||
INCEPTION_REMOTE_BACKUP_PASSWORD='inception' |
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,21 @@ | ||
"""archer URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/1.8/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) | ||
""" | ||
from django.conf.urls import include, url | ||
from django.contrib import admin | ||
|
||
urlpatterns = [ | ||
url(r'^admin/', include(admin.site.urls)), | ||
url(r'^', include('sql.urls')), | ||
] |
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,16 @@ | ||
""" | ||
WSGI config for archer project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "archer.settings") | ||
|
||
application = get_wsgi_application() |
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,3 @@ | ||
#!/bin/bash | ||
|
||
python3 manage.py runserver 172.16.5.10:9123 |
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,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "archer.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
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 @@ | ||
Django==1.8.17 | ||
python==3.4.1 |
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,21 @@ | ||
#coding=utf-8 | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import users, master_config, workflow | ||
|
||
class usersAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'username', 'display', 'role', 'password') | ||
search_fields = ['id', 'username', 'display', 'role'] | ||
|
||
class master_configAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'cluster_name', 'master_host', 'master_port', 'master_user', 'master_password', 'create_time', 'update_time') | ||
search_fields = ['id', 'cluster_name', 'master_host', 'master_port', 'master_user', 'master_password', 'create_time', 'update_time'] | ||
|
||
class workflowAdmin(admin.ModelAdmin): | ||
list_display = ('id','workflow_name', 'engineer', 'review_man', 'create_time', 'finish_time', 'status', 'is_backup', 'review_content', 'cluster_name', 'reviewok_time', 'sql_content', 'execute_result') | ||
search_fields = ['id','workflow_name', 'engineer', 'review_man', 'create_time', 'finish_time', 'status', 'is_backup', 'review_content', 'cluster_name', 'reviewok_time', 'sql_content', 'execute_result'] | ||
|
||
admin.site.register(users, usersAdmin) | ||
admin.site.register(master_config, master_configAdmin) | ||
admin.site.register(workflow, workflowAdmin) |
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,12 @@ | ||
# coding = utf-8 | ||
from django.http import HttpResponseRedirect | ||
|
||
class CheckLoginMiddleware(object): | ||
def process_request(self, request): | ||
""" | ||
本系统没有采用django.contrib.auth组件,自己简单实现了一把认证系统。 | ||
该函数在每个函数之前检查是否登录,若未登录,则重定向到/login/ | ||
""" | ||
if request.session.get('login_username', False) in (False, '匿名用户'): | ||
if request.path not in ('/login/', '/authenticate/'): | ||
return HttpResponseRedirect('/login/') |
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,12 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
class Const(object): | ||
workflowStatus = { | ||
'finish': '已正常结束', | ||
'abort': '人工终止流程', | ||
'autoreviewing': '自动审核中', | ||
'manreviewing': '等待审核人审核', | ||
'executing': '执行中', | ||
'autoreviewwrong': '自动审核不通过', | ||
'exception': '执行有异常', | ||
} |
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,24 @@ | ||
# coding = utf-8 | ||
|
||
import MySQLdb | ||
|
||
class Dao(object): | ||
#连进指定的mysql实例里,读取所有databases并返回 | ||
def getAlldbByCluster(self, masterHost, masterPort, masterUser, masterPassword): | ||
listDb = [] | ||
try: | ||
conn=MySQLdb.connect(host=masterHost, port=masterPort, user=masterUser, passwd=masterPassword) | ||
cursor = conn.cursor() | ||
sql = "show databases" | ||
n = cursor.execute(sql) | ||
listDb = [row[0] for row in cursor.fetchall() | ||
if row[0] not in ('information_schema', 'performance_schema', 'mysql', 'test')] | ||
except MySQLdb.Warning as w: | ||
print(str(w)) | ||
except MySQLdb.Error as e: | ||
print(str(e)) | ||
finally: | ||
cursor.close() | ||
conn.commit() | ||
conn.close() | ||
return listDb |
Oops, something went wrong.