Skip to content

Commit

Permalink
新增SQL审核规则,可自定义
Browse files Browse the repository at this point in the history
  • Loading branch information
jly8866 committed Mar 22, 2017
1 parent 855a3bf commit 7f83b37
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
10 changes: 5 additions & 5 deletions archer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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形式保存
1 change: 1 addition & 0 deletions sql/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{'key':'masterconfig', 'name':'主库地址配置', 'url':'/admin/sql/master_config/', 'class':'glyphicon glyphicon-user'},
{'key':'userconfig', 'name':'用户权限配置', 'url':'/admin/sql/users/', 'class':'glyphicon glyphicon-th-large'},
{'key':'workflowconfig', 'name':'所有工单管理', 'url':'/admin/sql/workflow/', 'class':'glyphicon glyphicon-list-alt'},
{'key':'dbaprinciples', 'name':'SQL审核必读', 'url':'/dbaprinciples/', 'class':'glyphicon glyphicon-book'},
)

def global_info(request):
Expand Down
6 changes: 6 additions & 0 deletions sql/static/dbaprinciples.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "base.html" %}

{% block content %}
<h4>请认真阅读SQL审核规则:</h4>
https://github.com/jly8866/archer/raw/master/docs/mysql_db_design_guide.docx
{% endblock content %}
1 change: 1 addition & 0 deletions sql/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
url(r'^execute/$', views.execute, name='execute'),
url(r'^cancel/$', views.cancel, name='cancel'),
url(r'^rollback/$', views.rollback, name='rollback'),
url(r'^dbaprinciples/$', views.dbaprinciples, name='dbaprinciples'),
]
35 changes: 21 additions & 14 deletions sql/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,22 @@ def autoreview(request):
newWorkflow.save()
workflowId = newWorkflow.id

#如果进入等待人工审核状态了,则根据settings.py里的配置决定是否给审核人和发起人发一封邮件提醒.
if hasattr(settings, 'MAIL_ON_OFF') == True:
if getattr(settings, 'MAIL_ON_OFF') == "on":
url = _getDetailUrl(request) + str(workflowId) + '/'

#发一封邮件
strTitle = "新的SQL上线工单提醒"
strContent = "发起人:" + engineer + "\n审核人:" + reviewMan + "\n工单地址:" + url
objEngineer = users.objects.get(username=engineer)
objReviewMan = users.objects.get(username=reviewMan)
mailSender.sendEmail(strTitle, strContent, [objEngineer.email, objReviewMan.email])
else:
#不发邮件
pass
#自动审核通过了,才发邮件
if workflowStatus == Const.workflowStatus['manreviewing']:
#如果进入等待人工审核状态了,则根据settings.py里的配置决定是否给审核人和发起人发一封邮件提醒.
if hasattr(settings, 'MAIL_ON_OFF') == True:
if getattr(settings, 'MAIL_ON_OFF') == "on":
url = _getDetailUrl(request) + str(workflowId) + '/'

#发一封邮件
strTitle = "新的SQL上线工单提醒"
strContent = "发起人:" + engineer + "\n审核人:" + reviewMan + "\n工单地址:" + url
objEngineer = users.objects.get(username=engineer)
objReviewMan = users.objects.get(username=reviewMan)
mailSender.sendEmail(strTitle, strContent, [objEngineer.email, objReviewMan.email])
else:
#不发邮件
pass

return HttpResponseRedirect('/detail/' + str(workflowId) + '/')

Expand Down Expand Up @@ -322,6 +324,11 @@ def rollback(request):
context = {'listBackupSql':listBackupSql}
return render(request, 'rollback.html', context)

#SQL审核必读
def dbaprinciples(request):
context = {'currentMenu':'dbaprinciples'}
return render(request, 'dbaprinciples.html', context)

#根据集群名获取主库连接字符串,并封装成一个dict
def getMasterConnStr(clusterName):
listMasters = master_config.objects.filter(cluster_name=clusterName)
Expand Down

0 comments on commit 7f83b37

Please sign in to comment.