Skip to content

Commit

Permalink
Merge pull request jly8866#86 from hhyo/github
Browse files Browse the repository at this point in the history
优化和调整
  • Loading branch information
Mr.July authored Jul 16, 2018
2 parents ad277e4 + 6422cdc commit 29ab8e4
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 76 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
### 慢日志管理
1. settings中SLOWQUERY改为True
2. 安装percona-toolkit(版本>3.0),以centos为例
2. 安装percona-toolkit(版本=3.0.6),以centos为例
```
yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
yum -y install percona-toolkit.x86_64
Expand Down Expand Up @@ -264,18 +264,15 @@ inception无法连接备份库
| 银行卡 | (.*)(.{4})$ | 2 | 隐藏后四位|
| 邮箱 | (.*)@(.*) | 2 | 去除后缀|
#### 查询权限管理
- 查询权限管理的审批流程和SQL上线是隔离的,需要到后台数据管理进行配置
- 审核人看不到待审核工单
代办列表被隐藏至右上角的消息图标中,当有待审核信息时会显示图标,可以进入查看待办数据
#### 审核人看不到查询权限申请待审核工单
查询权限申请待办列表被隐藏至右上角的消息图标中,当有待审核信息时会显示图标,可以进入查看待办数据
#### 慢日志管理
- 检查脚本内的配置,hostname和archer主库配置内容保持一致,用于archer做筛选
- 检查mysql_slow_query_review_history表收集的日志信息hostname_max是否和hostname一致
#### 慢日志不显示
- 检查脚本内的配置,hostname和archer主库配置内容保持一致,用于archer做筛选
- 检查mysql_slow_query_review_history表收集的日志信息hostname_max是否和hostname一致
#### 定时任务
- 未执行
检查django-apscheduler相关表是否有创建,可使用`python3 manage.py migrate`创建
#### 定时任务未执行
- 检查django-apscheduler相关表是否有创建,可使用`python3 manage.py migrate`创建
## 联系方式
QQ群524233225
4 changes: 2 additions & 2 deletions sql/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class master_configAdmin(admin.ModelAdmin):
class workflowAdmin(admin.ModelAdmin):
list_display = ('id', 'workflow_name', 'cluster_name', 'engineer', 'create_time', 'status', 'is_backup')
search_fields = ['id', 'workflow_name', 'engineer', 'review_man', 'sql_content']

exclude = ('is_manual',)

@admin.register(users)
class usersAdmin(UserAdmin):
Expand Down Expand Up @@ -55,7 +55,7 @@ def changelist_view(self, request, extra_context=None):
@admin.register(slave_config)
class WorkflowAuditAdmin(admin.ModelAdmin):
list_display = (
'cluster_name', 'slave_host', 'slave_port', 'slave_user', 'create_time', 'update_time')
'id', 'cluster_name', 'slave_host', 'slave_port', 'slave_user', 'create_time', 'update_time')
search_fields = ['id', 'cluster_name', 'slave_host', 'slave_port', 'slave_user', 'slave_password', ]


Expand Down
9 changes: 4 additions & 5 deletions sql/aes_decryptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Prpcrypt():
def __init__(self):
self.key = 'eCcGFZQj6PNoSSma31LR39rTzTbLkU8E'
self.key = 'eCcGFZQj6PNoSSma31LR39rTzTbLkU8E'.encode('utf-8')
self.mode = AES.MODE_CBC

#加密函数,如果text不足16位就用空格补足为16位,
Expand All @@ -22,10 +22,10 @@ def encrypt(self,text):
elif count > length:
add = (length-(count % length))
text = text + ('\0' * add)
self.ciphertext = cryptor.encrypt(text)
self.ciphertext = cryptor.encrypt(text.encode('utf-8'))
#因为AES加密时候得到的字符串不一定是ascii字符集的,输出到终端或者保存时候可能存在问题
#所以这里统一把加密后的字符串转化为16进制字符串
return b2a_hex(self.ciphertext)
return b2a_hex(self.ciphertext).decode(encoding='utf-8')

#解密后,去掉补足的空格用strip() 去掉
def decrypt(self,text):
Expand All @@ -35,8 +35,7 @@ def decrypt(self,text):

if __name__ == '__main__':
pc = Prpcrypt() #初始化密钥
import sys
e = pc.encrypt(sys.argv[1]) #加密
e = pc.encrypt('123456') #加密
d = pc.decrypt(e) #解密
print("加密:",str(e))
print("解密:",str(d))
17 changes: 9 additions & 8 deletions sql/aliyun_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
import simplejson as json
from .models import AliyunAccessKey
from .aes_decryptor import Prpcrypt
import logging

logger = logging.getLogger('default')

class Aliyun(object):
def __init__(self):
prpCryptor = Prpcrypt()
auth = AliyunAccessKey.objects.filter(is_enable=1)
try:
auth = AliyunAccessKey.objects.filter(is_enable=1)
prpCryptor = Prpcrypt()
ak = prpCryptor.decrypt(auth[0].ak)
secret = prpCryptor.decrypt(auth[0].secret)
except Exception:
ak = ''
secret = ''
self.clt = client.AcsClient(
ak=ak,
secret=secret)

logger.error('没有找到有效的ak信息!')
else:
self.clt = client.AcsClient(
ak=ak,
secret=secret)
def request_api(self, request, *values):
if values:
for value in values:
Expand Down
7 changes: 5 additions & 2 deletions sql/aliyun_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ def sapce_status(request):

# 提取进程列表
space_list = json.loads(space_info)['ListData']
space_list = json.loads(space_list)
if space_list:
space_list = json.loads(space_list)
else:
space_list = []

result = {'status': 0, 'msg': 'ok', 'data': space_list}

# 返回查询结果
return HttpResponse(json.dumps(result), content_type='application/json')
return result
10 changes: 5 additions & 5 deletions sql/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ class workflow(models.Model):
finish_time = models.DateTimeField('结束时间', null=True, blank=True)
status = models.CharField(max_length=50, choices=(
('已正常结束', '已正常结束'), ('人工终止流程', '人工终止流程'), ('自动审核中', '自动审核中'), ('等待审核人审核', '等待审核人审核'), ('审核通过', '审核通过'),
('执行中', '执行中'), ('自动审核不通过', '自动审核不通过'), ('执行有异常', '执行有异常')))
('定时执行', '定时执行'), ('执行中', '执行中'), ('自动审核不通过', '自动审核不通过'), ('执行有异常', '执行有异常')))
# is_backup = models.IntegerField('是否备份,0为否,1为是', choices=((0,0),(1,1)))
is_backup = models.CharField('是否备份', choices=(('否', '否'), ('是', '是')), max_length=20)
review_content = models.TextField('自动审核内容的JSON格式')
cluster_name = models.CharField('集群名称', max_length=50)
reviewok_time = models.DateTimeField('人工审核通过的时间', null=True, blank=True)
sql_content = models.TextField('具体sql内容')
execute_result = models.TextField('执行结果的JSON格式')
execute_result = models.TextField('执行结果的JSON格式', blank=True)
is_manual = models.IntegerField('是否手工执行', choices=((0, '否'), (1, '是')), default=0)
audit_remark = models.TextField('审核备注', null=True)
audit_remark = models.TextField('审核备注', null=True, blank=True)

def __str__(self):
return self.workflow_name
Expand Down Expand Up @@ -223,7 +223,7 @@ class Meta:
class DataMaskingColumns(models.Model):
column_id = models.AutoField('字段id', primary_key=True)
rule_type = models.IntegerField('规则类型',
choices=((1, '手机号'), (2, '证件号码'), (3, '银行卡'), (4, '邮箱'), (5, '金额')))
choices=((1, '手机号'), (2, '证件号码'), (3, '银行卡'), (4, '邮箱'), (5, '金额'), (6, '其他')))
active = models.IntegerField('激活状态', choices=((0, '未激活'), (1, '激活')))
cluster_name = models.CharField('集群名称', max_length=50)
table_schema = models.CharField('字段所在库名', max_length=64)
Expand All @@ -242,7 +242,7 @@ class Meta:
# 脱敏规则配置
class DataMaskingRules(models.Model):
rule_type = models.IntegerField('规则类型',
choices=((1, '手机号'), (2, '证件号码'), (3, '银行卡'), (4, '邮箱'), (5, '金额')), unique=True)
choices=((1, '手机号'), (2, '证件号码'), (3, '银行卡'), (4, '邮箱'), (5, '金额'), (6, '其他')), unique=True)
rule_regex = models.CharField('规则脱敏所用的正则表达式,表达式必须分组,隐藏的组会使用****代替', max_length=255)
hide_group = models.IntegerField('需要隐藏的组')
rule_desc = models.CharField('规则描述', max_length=100, default='', blank=True)
Expand Down
2 changes: 1 addition & 1 deletion sql/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
leftMenuBtnsSuper = (
{'key': 'diagnosis', 'name': '主库会话管理', 'url': '/diagnosis_process/', 'class': 'glyphicon glyphicon-scissors',
'display': True},
{'key': 'admin', 'name': '后台数据管理', 'url': '/admin/', 'class': 'glyphicon glyphicon-list', 'display': True},
{'key': 'admin', 'name': '后台数据管理', 'url': '/admin/sql/', 'class': 'glyphicon glyphicon-list', 'display': True},
)

leftMenuBtnsDoc = (
Expand Down
8 changes: 3 additions & 5 deletions sql/static/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
{% if todo > 0 %}
<li>
<a href="/workflow/"><span class="glyphicon glyphicon-envelope"></span></a>
</li>
{% endif %}
<li>
<a href="/workflow/"><span class="glyphicon glyphicon-envelope"></span></a>
</li>
<li>
<a href="#">你好,{{ UserDisplay }}</a>
</li>
Expand Down
13 changes: 9 additions & 4 deletions sql/static/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ <h4 style="display: inline;">单子名称:<span id="editWorkflowNname">{{ work
</tr>
</tbody>
</table>
<br>
{% endif %}
{% if workflowDetail.status == '定时执行' %}
<br>
Expand All @@ -112,8 +113,9 @@ <h4 style="display: inline;">单子名称:<span id="editWorkflowNname">{{ work
</tr>
</tbody>
</table>
<br>
{% endif %}
<br>

{% if workflowDetail.status == '等待审核人审核' %}
{% if loginUser in listAllReviewMen %}
<textarea id="remark" name="remark" class="form-control" data-name="审核备注"
Expand Down Expand Up @@ -399,7 +401,7 @@ <h4 class="modal-title text-danger">定时执行SQL</h4>
strictSearch: false, //是否全匹配搜索
showColumns: true, //是否显示所有的列(选择显示的列)
showRefresh: false, //是否显示刷新按钮
minimumCountColumns: 2, //最少允许的列数
minimumCountColumns: 1, //最少允许的列数
clickToSelect: false, //是否启用点击选中行
uniqueId: "id", //每一行的唯一标识,一般为主键列
showToggle: true, //是否显示详细视图和列表视图的切换按钮
Expand Down Expand Up @@ -440,8 +442,11 @@ <h4 class="modal-title text-danger">定时执行SQL</h4>
else {
return value
}
},
sortable: true
}
}, {
title: '完整SQL内容',
field: 'SQL',
visible: false
}, {
title: '审核状态',
field: 'errlevel',
Expand Down
6 changes: 3 additions & 3 deletions sql/static/diagnosis.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<li id="process_tab" class="active">
<a href="#process" role="tab" data-toggle="tab">进程状态</a>
</li>
{# <li id="space_tab">#}
{# <a href="#space" role="tab" data-toggle="tab">Top表空间</a>#}
{# </li>#}
<li id="space_tab">
<a href="#space" role="tab" data-toggle="tab">Top表空间</a>
</li>
<div class="form-inline pull-right">
<div class="form-group">
<select id=cluster_name class="form-control selectpicker" name="cluster_name_list"
Expand Down
8 changes: 5 additions & 3 deletions sql/static/submitSql.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ <h4 class="modal-title text-danger">提交信息确认</h4>

<!--upload -->
<script>
//初始化上传控件
//初始化上传控件
function init_upload() {
$("#sql-upload").fileinput({
language: 'zh',
allowedFileExtensions: ['sql'],//接收的文件后缀
showCaption: true,//是否显示标题
initialCaption: '仅支持后缀名为sql的文件',
initialCaption: '仅支持10M内的SQL文件',
defaultPreviewContent: '仅支持10M内的SQL文件',
showUpload: false, //不显示上传按钮
showPreview: false // 不显示预览,
showPreview: false, // 不显示预览,
maxFileSize: 10240
}).on('fileloaded', function () {
loadsql();
})
Expand Down
12 changes: 3 additions & 9 deletions sql/templatetags/format_tags.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
# -*- coding: UTF-8 -*-
from django import template
from django.utils.safestring import mark_safe

register = template.Library()


# 替换换行符
@register.simple_tag
def format_str(str):
# 替换所有的换行符
str = str.replace('\r', '<br>')
str = str.replace('\n', '<br>')
# 替换所有的空格
str = str.replace('\s', '&nbsp;')
# 逗号替换成换行符
str = str.replace(',', '<br>')

return str
# 换行
return mark_safe(str.replace(',', '<br/>'))
4 changes: 2 additions & 2 deletions sql/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
url(r'^slowquery_review/$', query.slowquery_review, name='slowquery_review'),
url(r'^slowquery_review_history/$', query.slowquery_review_history, name='slowquery_review_history'),
url(r'^process_status/$', views_ajax.process_status, name='process_status'),
url(r'^create_kill_session/$', views_ajax.create_kill_session,
name='create_kill_session'),
url(r'^create_kill_session/$', views_ajax.create_kill_session,name='create_kill_session'),
url(r'^kill_session/$', views_ajax.kill_session, name='kill_session'),
url(r'^sapce_status/$', views_ajax.tablesapce, name='tablesapce'),
url(r'^del_sqlcronjob/$', jobs.del_sqlcronjob, name='del_sqlcronjob'),

]
Expand Down
2 changes: 1 addition & 1 deletion sql/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def workflows(request):
# 获取用户信息
loginUser = request.session.get('login_username', False)
loginUserOb = users.objects.get(username=loginUser)
context = {'currentMenu': 'workflow', "loginUserOb": loginUserOb}
context = {'currentMenu': 'queryapply', "loginUserOb": loginUserOb}
return render(request, "workflow.html", context)


Expand Down
Loading

0 comments on commit 29ab8e4

Please sign in to comment.