forked from guohongze/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
6 changed files
with
143 additions
and
29 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 |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
*.log | ||
.idea/ | ||
.DS_Store | ||
archer/settings.py.github | ||
archer/settings.py.dev |
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 |
---|---|---|
|
@@ -77,23 +77,6 @@ | |
|
||
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/ | ||
|
||
|
@@ -114,14 +97,41 @@ | |
STATIC_URL = '/static/' | ||
STATIC_ROOT = os.path.join(BASE_DIR, 'static') | ||
|
||
#扩展django admin里users字段用到,指定了sql/models.py里的class users | ||
AUTH_USER_MODEL="sql.users" | ||
|
||
###############以下部分需要用户根据自己环境自行修改################### | ||
|
||
# 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': '127.0.0.1', | ||
'PORT': '5000' | ||
} | ||
} | ||
|
||
#inception组件所在的地址 | ||
INCEPTION_HOST = '172.16.5.7' | ||
INCEPTION_HOST = '192.168.1.11' | ||
INCEPTION_PORT = '6100' | ||
|
||
#inception要备份数据到该远端mysql地址 | ||
INCEPTION_REMOTE_BACKUP_HOST='172.16.5.10' | ||
INCEPTION_REMOTE_BACKUP_HOST='192.168.1.12' | ||
INCEPTION_REMOTE_BACKUP_PORT=5621 | ||
INCEPTION_REMOTE_BACKUP_USER='inception' | ||
INCEPTION_REMOTE_BACKUP_PASSWORD='inception' | ||
|
||
AUTH_USER_MODEL="sql.users" | ||
#是否开启邮件提醒功能:发起SQL上线后会发送邮件提醒审核人审核,执行完毕会发送给DBA. on是开,off是关,配置为其他值均会被archer认为不开启邮件功能 | ||
MAIL_ON_OFF='on' | ||
|
||
MAIL_REVIEW_SMTP_SERVER='mail.xxx.com' | ||
MAIL_REVIEW_SMTP_PORT=25 | ||
MAIL_REVIEW_FROM_ADDR='[email protected]' #发件人,也是登录SMTP server需要提供的用户名 | ||
MAIL_REVIEW_FROM_PASSWORD='' #发件人邮箱密码,如果为空则不需要login SMTP server | ||
MAIL_REVIEW_DBA_ADDR=['[email protected]', '[email protected]'] #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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: UTF-8 -*- | ||
|
||
|
||
import time | ||
from multiprocessing import Process | ||
import email | ||
from email import encoders | ||
from email.header import Header | ||
from email.mime.text import MIMEText | ||
from email.utils import parseaddr, formataddr | ||
import smtplib | ||
|
||
from django.conf import settings | ||
|
||
class MailSender(object): | ||
def __init__(self): | ||
try: | ||
self.MAIL_REVIEW_SMTP_SERVER = getattr(settings, 'MAIL_REVIEW_SMTP_SERVER') | ||
self.MAIL_REVIEW_SMTP_PORT = int(getattr(settings, 'MAIL_REVIEW_SMTP_PORT')) | ||
self.MAIL_REVIEW_FROM_ADDR = getattr(settings, 'MAIL_REVIEW_FROM_ADDR') | ||
self.MAIL_REVIEW_FROM_PASSWORD = getattr(settings, 'MAIL_REVIEW_FROM_PASSWORD') | ||
self.MAIL_REVIEW_DBA_ADDR = getattr(settings, 'MAIL_REVIEW_DBA_ADDR') | ||
|
||
except AttributeError as a: | ||
print("Error: %s" % a) | ||
except ValueError as v: | ||
print("Error: %s" % v) | ||
|
||
def _format_addr(self, s): | ||
name, addr = parseaddr(s) | ||
return formataddr((Header(name, 'utf-8').encode(), addr)) | ||
|
||
def _send(self, strTitle, strContent, listToAddr): | ||
msg = MIMEText(strContent, 'plain', 'utf-8') | ||
# 收件人地址: | ||
|
||
msg['From'] = self._format_addr(self.MAIL_REVIEW_FROM_ADDR) | ||
msg['To'] = self._format_addr(listToAddr) | ||
msg['Subject'] = Header(strTitle, "utf-8").encode() | ||
|
||
server = smtplib.SMTP(self.MAIL_REVIEW_SMTP_SERVER, self.MAIL_REVIEW_SMTP_PORT) # SMTP协议默认端口是25 | ||
#server.set_debuglevel(1) | ||
|
||
#如果提供的密码为空,则不需要登录SMTP server | ||
if self.MAIL_REVIEW_FROM_PASSWORD != '': | ||
server.login(self.MAIL_REVIEW_FROM_ADDR, self.MAIL_REVIEW_FROM_PASSWORD) | ||
sendResult = server.sendmail(self.MAIL_REVIEW_FROM_ADDR, listToAddr, msg.as_string()) | ||
server.quit() | ||
|
||
#调用方应该调用此方法,采用子进程方式异步阻塞地发送邮件,避免邮件服务挂掉影响archer主服务 | ||
def sendEmail(self, strTitle, strContent, listToAddr): | ||
p = Process(target=self._send, args=(strTitle, strContent, listToAddr)) | ||
p.start() |
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