forked from jly8866/archer
-
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.
- Loading branch information
Showing
8 changed files
with
222 additions
and
45 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 |
---|---|---|
|
@@ -112,27 +112,27 @@ | |
'NAME': 'archer', | ||
'USER': 'archer_rw', | ||
'PASSWORD': 'archer_rw', | ||
'HOST': '127.0.0.1', | ||
'HOST': '172.21.139.1', | ||
'PORT': '5000' | ||
} | ||
} | ||
|
||
#inception组件所在的地址 | ||
INCEPTION_HOST = '192.168.1.11' | ||
INCEPTION_HOST = '172.16.5.7' | ||
INCEPTION_PORT = '6100' | ||
|
||
#查看回滚SQL时候会用到,这里要告诉archer去哪个mysql里读取inception备份的回滚信息和SQL. | ||
#注意这里要和inception组件的inception.conf里的inception_remote_XX部分保持一致. | ||
INCEPTION_REMOTE_BACKUP_HOST='192.168.1.12' | ||
INCEPTION_REMOTE_BACKUP_HOST='172.16.5.10' | ||
INCEPTION_REMOTE_BACKUP_PORT=5621 | ||
INCEPTION_REMOTE_BACKUP_USER='inception' | ||
INCEPTION_REMOTE_BACKUP_PASSWORD='inception' | ||
|
||
#是否开启邮件提醒功能:发起SQL上线后会发送邮件提醒审核人审核,执行完毕会发送给DBA. on是开,off是关,配置为其他值均会被archer认为不开启邮件功能 | ||
MAIL_ON_OFF='on' | ||
|
||
MAIL_REVIEW_SMTP_SERVER='mail.xxx.com' | ||
MAIL_REVIEW_SMTP_SERVER='172.21.129.215' | ||
MAIL_REVIEW_SMTP_PORT=25 | ||
MAIL_REVIEW_FROM_ADDR='[email protected]' #发件人,也是登录SMTP server需要提供的用户名 | ||
MAIL_REVIEW_FROM_PASSWORD='' #发件人邮箱密码,如果为空则不需要login SMTP server | ||
MAIL_REVIEW_DBA_ADDR=['zhangsan@abc.com', 'lisi01@abc.com'] #DBA地址,执行完毕会发邮件给DBA,以list形式保存 | ||
MAIL_REVIEW_DBA_ADDR=['jialiyang@baijiahulian.com', 'zhangpeng@baijiahulian.com'] #DBA地址,执行完毕会发邮件给DBA,以list形式保存 |
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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
$("#btn-autoreview").click(function(){ | ||
autoreview(); | ||
}); | ||
|
||
function authenticateUser111() { | ||
var inputUsername = $('#inputUsername'); | ||
var inputPassword = $('#inputPassword'); | ||
$.ajax({ | ||
type: "post", | ||
url: "/authenticate/", | ||
dataType: "json", | ||
data: { | ||
username: inputUsername.val(), | ||
password: inputPassword.val() | ||
}, | ||
complete: function () { | ||
}, | ||
success: function (data) { | ||
if (data.status == 0) { | ||
$(location).attr('href','/allworkflow/'); | ||
} else { | ||
$('#wrongpwd-modal-body').html(data.msg); | ||
$('#wrongpwd-modal').modal({ | ||
keyboard: true | ||
}); | ||
} | ||
}, | ||
error: function (XMLHttpRequest, textStatus, errorThrown) { | ||
alert(errorThrown); | ||
} | ||
}); | ||
}; | ||
|
||
function autoreview() { | ||
var sqlContent = $("#sql_content"); | ||
var clusterName = $("#cluster_name"); | ||
|
||
//将数据通过ajax提交给后端进行检查 | ||
$.ajax({ | ||
type: "post", | ||
url: "/simplecheck/", | ||
dataType: "json", | ||
data: { | ||
sql_content: sqlContent.val(), | ||
cluster_name: clusterName.val() | ||
}, | ||
complete: function() { | ||
|
||
}, | ||
success: function (data) { | ||
if (data.status == 0) { | ||
//console.log(data.data); | ||
var result = data.data; | ||
var finalHtml = ""; | ||
for (var i=0; i<result.length; i++) { | ||
//索引5是SQL,4是审核建议 | ||
alertStyle = "alert-success"; | ||
if (result[i][4] != "None") { | ||
alertStyle = "alert-danger"; | ||
} | ||
finalHtml += "<div class='alert alert-dismissable " + alertStyle + "'> <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>x</button> <table class=''> <tr> <td width='800px'>" + result[i][5] + "</td> <td><strong>自动审核结果:</strong>" + result[i][4] + "</td> </tr> </table> </div>"; | ||
} | ||
|
||
$("#inception-result-col").html(finalHtml); | ||
//填充内容后展现出来 | ||
$("#inception-result").show(); | ||
} else { | ||
alert("status: " + data.status + "\nmsg: " + data.msg + data.data); | ||
} | ||
}, | ||
error: function(XMLHttpRequest, textStatus, errorThrown) { | ||
alert(errorThrown); | ||
} | ||
}); | ||
|
||
} |
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
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,84 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
import re | ||
import json | ||
import time | ||
import multiprocessing | ||
|
||
from django.db.models import Q | ||
from django.conf import settings | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django.shortcuts import render, get_object_or_404 | ||
from django.http import HttpResponse, HttpResponseRedirect | ||
from django.contrib.auth.decorators import login_required | ||
from django.contrib.auth.hashers import check_password | ||
|
||
from .dao import Dao | ||
from .const import Const | ||
from .inception import InceptionDao | ||
from .aes_decryptor import Prpcrypt | ||
from .models import users, master_config, workflow | ||
|
||
dao = Dao() | ||
inceptionDao = InceptionDao() | ||
prpCryptor = Prpcrypt() | ||
|
||
#ajax接口,登录页面调用,用来验证用户名密码 | ||
@csrf_exempt | ||
def authenticate(request): | ||
"""认证机制做的非常简单""" | ||
if request.is_ajax(): | ||
strUsername = request.POST.get('username') | ||
strPassword = request.POST.get('password') | ||
else: | ||
strUsername = request.POST['username'] | ||
strPassword = request.POST['password'] | ||
|
||
result = {} | ||
#服务端二次验证参数 | ||
if strUsername == "" or strPassword == "" or strUsername is None or strPassword is None: | ||
result = {'status':2, 'msg':'登录用户名或密码为空,请重新输入!', 'data':''} | ||
|
||
correct_users = users.objects.filter(username=strUsername) | ||
if len(correct_users) == 1 and check_password(strPassword, correct_users[0].password) == True: | ||
#调用了django内置函数check_password函数检测输入的密码是否与django默认的PBKDF2算法相匹配 | ||
request.session['login_username'] = strUsername | ||
result = {'status':0, 'msg':'ok', 'data':''} | ||
else: | ||
result = {'status':1, 'msg':'用户名或密码错误,请重新输入!', 'data':''} | ||
return HttpResponse(json.dumps(result), content_type='application/json') | ||
|
||
|
||
#提交SQL给inception进行自动审核 | ||
@csrf_exempt | ||
def simplecheck(request): | ||
if request.is_ajax(): | ||
sqlContent = request.POST.get('sql_content') | ||
clusterName = request.POST.get('cluster_name') | ||
else: | ||
sqlContent = request.POST['sql_content'] | ||
clusterName = request.POST['cluster_name'] | ||
|
||
finalResult = {'status':0, 'msg':'ok', 'data':[]} | ||
#服务器端参数验证 | ||
if sqlContent is None or clusterName is None: | ||
finalResult['status'] = 1 | ||
finalResult['msg'] = '页面提交参数可能为空' | ||
return HttpResponse(json.dumps(finalResult), content_type='application/json') | ||
|
||
sqlContent = sqlContent.rstrip() | ||
if sqlContent[-1] != ";": | ||
finalResult['status'] = 1 | ||
finalResult['msg'] = 'SQL语句结尾没有以;结尾,请重新修改并提交!' | ||
return HttpResponse(json.dumps(finalResult), content_type='application/json') | ||
|
||
#交给inception进行自动审核 | ||
result = inceptionDao.sqlautoReview(sqlContent, clusterName) | ||
if result is None or len(result) == 0: | ||
finalResult['status'] = 1 | ||
finalResult['msg'] = 'inception返回的结果集为空!可能是SQL语句有语法错误' | ||
return HttpResponse(json.dumps(finalResult), content_type='application/json') | ||
#要把result转成JSON存进数据库里,方便SQL单子详细信息展示 | ||
finalResult['data'] = result | ||
return HttpResponse(json.dumps(finalResult), content_type='application/json') | ||
|