Skip to content

使用 python-decouple 加载配置等 #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 88 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
5042f42
Modules should always get session values from SSO
chyeh Oct 26, 2015
ef06c52
Don't need the session variable anymore
chyeh Oct 26, 2015
b20ea21
Merge pull request #2 from chyeh/master
hitripod Oct 26, 2015
841620c
[OWL-144] Add grafana-style sidemenu and navbar.
Oct 28, 2015
552ded3
[OWL-144] Use the absolute URL for falcon-dashboard
Oct 29, 2015
f92b934
[OWL-144] Use the absolute URL for UIC.
Oct 29, 2015
41af7d9
Remove a redundant character.
Oct 30, 2015
5fdbef3
[OWL-144] Clicking outside also closes the UIC dropdown menu.
Oct 30, 2015
9e16b24
[OWL-144] Replace href with 'Shortcut' defined in config.py.
Oct 30, 2015
500ab2b
Fix Uncaught TypeError: $.layer is not a function.
Oct 30, 2015
533dfd5
Remove href of fav32.png to avoid jumping out when collapsing sidemenu.
Oct 31, 2015
74c78f0
Modules should always get session values from SSO
chyeh Oct 26, 2015
be54103
Don't need the session variable anymore
chyeh Oct 26, 2015
d37d4c8
[OWL-144] Add grafana-style sidemenu and navbar.
Oct 28, 2015
ddd3c69
[OWL-144] Use the absolute URL for falcon-dashboard
Oct 29, 2015
f887166
[OWL-144] Use the absolute URL for UIC.
Oct 29, 2015
98809e2
Remove a redundant character.
Oct 30, 2015
6cf9cfc
[OWL-144] Clicking outside also closes the UIC dropdown menu.
Oct 30, 2015
980db9f
[OWL-144] Replace href with 'Shortcut' defined in config.py.
Oct 30, 2015
1190725
Fix Uncaught TypeError: $.layer is not a function.
Oct 30, 2015
5606b01
Remove href of fav32.png to avoid jumping out when collapsing sidemenu.
Oct 31, 2015
8e0fafa
Merge branch 'master' of https://github.com/myhung/portal
myhung Nov 19, 2015
d07544f
Merge pull request #3 from myhung/master
hitripod Nov 19, 2015
982e2b0
Fix error when inserting data into mockcfg table.
minimum-hsu Nov 24, 2015
dc91fd8
Merge pull request #5 from minimum-hsu/master
hitripod Nov 24, 2015
2cb1293
[OWL-182] unify font style with grafana
chuanxd Dec 16, 2015
8adc6d2
Merge pull request #6 from chuanxd/fix_portal_sidebar_font_style
hitripod Dec 16, 2015
260585f
[OWL-157] fix scroll display
chuanxd Dec 16, 2015
11f48ae
Merge pull request #7 from chuanxd/fix_scroll_display
hitripod Dec 16, 2015
f132c7b
[OWL-212] Merge remote-tracking branch 'open-falcon/portal/master'
hitripod Dec 29, 2015
3465892
[OWL-239] add UIC_ADDRESS['login'] in frame/config.py
Dec 31, 2015
3915f24
[OWL-239] set return UIC_ADDRESS['login'] in frame/api/uic.py
Dec 31, 2015
002ac37
[OWL-239] refine def before_request() and def redirect_to_sso()
Dec 31, 2015
02f2bc6
Merge pull request #8 from donh/master
hitripod Dec 31, 2015
45eb01e
Modules should always get session values from SSO
chyeh Oct 26, 2015
143aea0
Don't need the session variable anymore
chyeh Oct 26, 2015
bf705ae
[OWL-144] Add grafana-style sidemenu and navbar.
Oct 28, 2015
cfac9bf
[OWL-144] Use the absolute URL for falcon-dashboard
Oct 29, 2015
7184bd0
[OWL-144] Use the absolute URL for UIC.
Oct 29, 2015
a43d3d2
Remove a redundant character.
Oct 30, 2015
e7ebe54
[OWL-144] Clicking outside also closes the UIC dropdown menu.
Oct 30, 2015
ca7cda7
[OWL-144] Replace href with 'Shortcut' defined in config.py.
Oct 30, 2015
2d4b99c
Fix Uncaught TypeError: $.layer is not a function.
Oct 30, 2015
7eed024
Remove href of fav32.png to avoid jumping out when collapsing sidemenu.
Oct 31, 2015
c174218
Modules should always get session values from SSO
chyeh Oct 26, 2015
7df721b
Don't need the session variable anymore
chyeh Oct 26, 2015
7e8cfd4
[OWL-144] Add grafana-style sidemenu and navbar.
Oct 28, 2015
ba828b6
[OWL-144] Use the absolute URL for falcon-dashboard
Oct 29, 2015
5c27c46
[OWL-144] Use the absolute URL for UIC.
Oct 29, 2015
2818bd4
[OWL-144] Replace href with 'Shortcut' defined in config.py.
Oct 30, 2015
3a7344b
Fix Uncaught TypeError: $.layer is not a function.
Oct 30, 2015
12018bf
Remove href of fav32.png to avoid jumping out when collapsing sidemenu.
Oct 31, 2015
c3d4ffa
Fix error when inserting data into mockcfg table.
minimum-hsu Nov 24, 2015
cf4a426
[OWL-182] unify font style with grafana
chuanxd Dec 16, 2015
9ef97c8
[OWL-157] fix scroll display
chuanxd Dec 16, 2015
cae5df4
[OWL-239] add UIC_ADDRESS['login'] in frame/config.py
Dec 31, 2015
3bb856e
[OWL-239] set return UIC_ADDRESS['login'] in frame/api/uic.py
Dec 31, 2015
3f03d9e
[OWL-239] refine def before_request() and def redirect_to_sso()
Dec 31, 2015
fd65cba
Merge branch 'develop' into upstream-merged
hitripod Mar 7, 2016
1815145
Merge pull request #9 from Cepave/upstream-merged
hitripod Mar 9, 2016
a7e0e30
fix user submenu not shown
hitripod Mar 17, 2016
9b4ac70
Merge branch 'develop'
hitripod Mar 17, 2016
c11fa1d
[OWL-459] note field is mandatory for display
hitripod Apr 1, 2016
69a0af6
Merge branch 'develop'
hitripod Apr 21, 2016
37861b8
integrated alarm adjust api of fe
masato25 Jul 14, 2016
1740d0d
Merge pull request #10 from masato25/develop
hitripod Jul 14, 2016
36116ef
integrate with alarm adjust api - WhenEndpointOnMaintain
masato25 Jul 14, 2016
1873388
Merge pull request #11 from masato25/develop
hitripod Jul 14, 2016
cc1eb7c
Merge branch 'develop'
hitripod Jul 15, 2016
bb4c99f
add time range for avoiding wrong status set of alarm adjust api
masato25 Jul 18, 2016
2f4f5b5
Merge pull request #12 from masato25/develop
hitripod Jul 18, 2016
ad827ee
Merge branch 'develop'
hitripod Jul 18, 2016
35cb463
add retry for auto ignored request
masato25 Jul 29, 2016
df6ceb9
Merge pull request #13 from masato25/develop
hitripod Jul 30, 2016
e99a302
Merge branch 'develop'
hitripod Aug 11, 2016
887a48f
[OWL-1045] Unified print msg format.
Sep 19, 2016
2d2bbe8
[OWL-1045] Unified log msg format.
Sep 19, 2016
8cf7355
Merge pull request #14 from crosserclaws/unified_msg
hitripod Sep 23, 2016
16d4873
Merge pull request #15 from Cepave/develop
hitripod Sep 30, 2016
6f641ef
add checking to avoiding update status issue of event_cases
masato25 Dec 1, 2016
a3d5d07
remove debug info print and merged condition checking into one
masato25 Dec 2, 2016
dc14982
Merge pull request #16 from masato25/develop
hitripod Dec 2, 2016
6d9415c
fix create issue on strategy
masato25 Dec 7, 2016
3d93fb5
Merge pull request #17 from masato25/develop
hitripod Dec 7, 2016
93e6faa
Merge branch 'develop'
hitripod Dec 7, 2016
f774fdb
tag显示为蓝色;当用户在metric中输入metric/tags时,自动填充 metric和tags的值。
Mar 22, 2016
2e2f975
trim host before add
qudongfang Aug 2, 2016
66cdc04
使用 `python-decouple` 加载配置
Jan 5, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.py]
indent_style = space
indent_size = 4

[*.{html,js,jsx,css,styl,yml}]
indent_style = space
indent_size = 2

[*.html]
language = mako

[Vagrantfile]
indent_style = space
indent_size = 2
language = ruby
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FALCON_DEBUG=1
FALCON_DB_HOST=localhost
FALCON_DB_PORT=3306
FALCON_DB_USER=root
FALCON_DB_PASS=""
FALCON_DB_NAME=falcon_portal
FALCON_SECRET_KEY="4e.5tyg8-u9ioj"
FALCON_SESSION_COOKIE_NAME="falcon-portal"
FALCON_SERVER_NAME=
FALCON_SESSION_LIFETIME=86400
FALCON_NIC_INTERNAL=http://127.0.0.1:8080
FALCON_NIC_EXTERNAL=http://11.11.11.11:8080
FALCON_UIC_TOKEN=""
FALCON_MAINTAINERS=root
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ docs/_build/
/frame/local_config.py
/falcon-portal*
/gitversion
.env

11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ falcon portal
$ virtualenv ./env

# use douban pypi
$ ./env/bin/pip install -r pip_requirements.txt -i http://pypi.douban.com/simple
$ ./env/bin/pip install -r requirements.txt -i http://pypi.douban.com/simple


## Init database and config
Expand All @@ -19,16 +19,19 @@ falcon portal

## Start

$ ./env/bin/python wsgi.py
$ cp .env.example .env

$ . env/bin/activate
$ env `cat .env | xargs` python wsgi.py

--> goto http://127.0.0.1:5050


## Run with gunicorn

$ . env/bin/activate
$ bash run.sh
$ env `cat .env 2>/dev/null | xargs` gunicorn -c gunicorn.conf wsgi:app

--> goto http://127.0.0.1:5050


2 changes: 1 addition & 1 deletion frame/api/uic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def username_from_sso(sig=''):


def login_url(sig='', callback=''):
return '%s/auth/login?sig=%s&callback=%s' % (UIC_ADDRESS['external'], sig, callback)
return UIC_ADDRESS['login']


def query_group(query='', limit=10):
Expand Down
54 changes: 38 additions & 16 deletions frame/config.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
# -*- coding:utf-8 -*-
__author__ = 'Ulric Qin'
__author__ = ['Ulric Qin', 'Eagle Liut']

from decouple import config

# -- app config --
DEBUG = True
DEBUG = config('FALCON_DEBUG', default=False, cast=bool)

# -- db config --
DB_HOST = "127.0.0.1"
DB_PORT = 3306
DB_USER = "root"
DB_PASS = ""
DB_NAME = "falcon_portal"

DB_HOST = config('FALCON_PORTAL_DB_HOST', default="127.0.0.1")
DB_PORT = config('FALCON_PORTAL_DB_PORT', default=3306, cast=int)
DB_USER = config('FALCON_PORTAL_DB_USER', default="root")
DB_PASS = config('FALCON_PORTAL_DB_PASS', default="password")
DB_NAME = config('FALCON_PORTAL_DB_NAME', default="falcon_portal")

# -- cookie config --
SECRET_KEY = "4e.5tyg8-u9ioj"
SESSION_COOKIE_NAME = "falcon-portal"
PERMANENT_SESSION_LIFETIME = 3600 * 24 * 30
SECRET_KEY = config('FALCON_SECRET_KEY', default="4e.5tyg8-u9ioj")
SESSION_COOKIE_NAME = config('FALCON_SESSION_COOKIE_NAME', default="falcon-portal")
SESSION_COOKIE_DOMAIN = config('FALCON_SESSION_COOKIE_DOMAIN', default=None)
SERVER_NAME = config('FALCON_SERVER_NAME', default=None)
PERMANENT_SESSION_LIFETIME = config('FALCON_SESSION_LIFETIME', default=86400, cast=int)

URL_PORTAL = config('FALCON_URL_PORTAL', default="http://127.0.0.1:5050")
URL_DARSHBOARD = config('FALCON_URL_DARSHBOARD', default="http://127.0.0.1:8081")
URL_GRAFANA = config('FALCON_URL_GRAFANA', default="http://127.0.0.1:3000")
URL_ALARM = config('FALCON_URL_ALARM', default="http://127.0.0.1:9912")
URL_UIC = config('FALCON_URL_UIC', default="http://127.0.0.1:1234")

UIC_ADDRESS = {
'internal': 'http://127.0.0.1:8080',
'external': 'http://11.11.11.11:8080',
'internal': config('FALCON_UIC_INTERNAL', default='http://127.0.0.1:1234'),
'external': config('FALCON_UIC_EXTERNAL', default=URL_UIC),
'login': config(
'FALCON_UIC_LOGIN',
default='{}/auth/login?callback={}'.format(URL_UIC, URL_PORTAL)),
}

UIC_TOKEN = ''
UIC_TOKEN = config('FALCON_UIC_TOKEN', default='')

MAINTAINERS = ['root']
CONTACT = '[email protected]'
MAINTAINERS = config('FALCON_MAINTAINERS', default='root').split(',')
CONTACT = config('FALCON_CONTACT', default='[email protected]')

COMMUNITY = True

JSONCFG = {}
JSONCFG['shortcut'] = {}
JSONCFG['shortcut']['falconPortal'] = URL_PORTAL
JSONCFG['shortcut']['falconDashboard'] = URL_DARSHBOARD
JSONCFG['shortcut']['grafanaDashboard'] = URL_GRAFANA
JSONCFG['shortcut']['falconAlarm'] = URL_ALARM
JSONCFG['shortcut']['falconUIC'] = URL_UIC

try:
from frame.local_config import *
except Exception, e:
print "[warning] %s" % e
print('level=warning msg="%s"' % e)
1 change: 1 addition & 0 deletions pip_requirements.txt → requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Werkzeug==0.9.4
gunicorn==19.3.0
requests==2.3.0
mysql-python
python-decouple
27 changes: 9 additions & 18 deletions web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
app.config.from_object("frame.config")

# config log
log_formatter = '%(asctime)s\t[%(filename)s:%(lineno)d] [%(levelname)s: %(message)s]'
log_formatter = 'time="%(asctime)s" level=%(levelname)s msg="%(message)s"'
log_level = logging.DEBUG if app.config['DEBUG'] else logging.WARNING
logging.basicConfig(format=log_formatter, datefmt="%Y-%m-%d %H:%M:%S", level=log_level)
logging.basicConfig(format=log_formatter, datefmt="%Y-%m-%dT%H:%M:%S%z", level=log_level)

IGNORE_PREFIX = ['/api', '/static']

Expand All @@ -38,26 +38,17 @@ def before_request():
if p.startswith(ignore_pre):
return

if 'user_name' in session and session['user_name']:
g.user_name = session['user_name']
else:
sig = request.cookies.get('sig')
if not sig:
return redirect_to_sso()

sig = request.cookies.get('sig')
if not sig:
return redirect_to_sso()
elif 'user_name' not in g:
username = uic.username_from_sso(sig)
if not username:
return redirect_to_sso()

session['user_name'] = username
g.user_name = session['user_name']
g.user_name = username


def redirect_to_sso():
sig = uic.gen_sig()
resp = make_response(redirect(uic.login_url(sig, urllib.quote(request.url))))
resp.set_cookie('sig', sig)
resp = make_response(redirect(uic.login_url()))
return resp


from web.controller import home, group, plugin, host, expression, api, template, strategy, nodata, cluster
from web.controller import home, group, plugin, host, expression, api, template, strategy, nodata, cluster
4 changes: 2 additions & 2 deletions web/controller/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from web.model.expression import Expression
from web.model.strategy import Strategy
from frame import utils
from frame import config


@app.route('/api/version')
Expand Down Expand Up @@ -95,7 +96,7 @@ def api_pings_get():

@app.route('/api/debug')
def api_debug():
return render_template('debug/index.html')
return render_template('debug/index.html', config=config)


@app.route('/api/group/<grp_name>/hosts.json')
Expand All @@ -109,4 +110,3 @@ def api_group_hosts_json(grp_name):
vs, _ = Host.query(1, 10000000, '', '0', group.id)
names = [v.hostname for v in vs]
return jsonify(msg='', data=names)

15 changes: 11 additions & 4 deletions web/controller/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from web.model.action import Action
from frame.params import required_chk
from frame.config import UIC_ADDRESS
from frame import config


@app.route('/expressions')
Expand All @@ -28,7 +29,8 @@ def expressions_get():
'limit': limit,
'page': page,
'mine': mine,
}
},
config=config
)


Expand All @@ -46,8 +48,10 @@ def expression_add_get():
o = Expression.get(int(request.args.get('id', '0').strip()))
if o:
a = Action.get(o.action_id)
return render_template('expression/add.html',
data={'action': a, 'expression': o, 'uic_address': UIC_ADDRESS['external']})
return render_template(
'expression/add.html',
data={'action': a, 'expression': o, 'uic_address': UIC_ADDRESS['external']},
config=config)


@app.route('/expression/update', methods=['POST'])
Expand Down Expand Up @@ -132,4 +136,7 @@ def expression_view_get(eid):
a = Action.get(o.action_id)
else:
return 'no such expression'
return render_template('expression/view.html', data={'action': a, 'expression': o})
return render_template(
'expression/view.html',
data={'action': a, 'expression': o},
config=config)
34 changes: 34 additions & 0 deletions web/controller/fe_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import urllib2
import urllib
import logging
import time

log = logging.getLogger(__name__)
def post2FeUpdateEventCase(url, data):
mtries, mdelay, backoff = 4, 3, 2
resp_code = 200
while mtries > 1:
try:
url_values = urllib.urlencode(data)
full_url = url + '?' + url_values
response = urllib2.urlopen(full_url)
resp_code = response.getcode()
mtries = 1
except urllib2.HTTPError as e:
msg = "%s, Retrying in %d seconds..." % (str(e),mdelay)
print('msg="%s"' % msg)
resp_code = e.code
time.sleep(mdelay)
mdelay *= backoff
mtries -= 1
except Exception as e:
msg = "%s, Retrying in %d seconds..." % (str(e),mdelay)
print('msg="%s"' % msg)
log.warning(msg)
if mtries == 2:
resp_code = 500
log.error(str(e))
time.sleep(mdelay)
mdelay *= backoff
mtries -= 1
return resp_code
8 changes: 5 additions & 3 deletions web/controller/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from web.model.grp_tpl import GrpTpl
from web.service import group_service
from frame.config import UIC_ADDRESS
from frame import config


@app.route('/group/create', methods=['POST'])
Expand Down Expand Up @@ -55,7 +56,7 @@ def group_update_post(group_id):

@app.route('/group/advanced')
def group_advanced_get():
return render_template('group/advanced.html')
return render_template('group/advanced.html', config=config)


@app.route('/group/rename', methods=['POST'])
Expand All @@ -77,7 +78,8 @@ def group_templates_get(grp_id):

ts = GrpTpl.tpl_list(grp_id)

return render_template('group/templates.html', group=grp, ts=ts, uic_address=UIC_ADDRESS['external'])
return render_template('group/templates.html', group=grp, ts=ts,
uic_address=UIC_ADDRESS['external'], config=config)


@app.route('/group/bind/template')
Expand All @@ -91,4 +93,4 @@ def group_bind_template_get():
return jsonify(msg="grp id is blank")

GrpTpl.bind(grp_id, tpl_id, g.user_name)
return jsonify(msg='')
return jsonify(msg='')
3 changes: 2 additions & 1 deletion web/controller/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def home_get():
'mine': mine,
'is_root': g.user_name in config.MAINTAINERS,
'community': config.COMMUNITY,
}
},
config=config
)

Loading