diff --git a/rrd/__init__.py b/rrd/__init__.py
index 149e20f..8f16af0 100644
--- a/rrd/__init__.py
+++ b/rrd/__init__.py
@@ -41,6 +41,9 @@ def get_locale():
def get_timezone():
return app.config.get("BABEL_DEFAULT_TIMEZONE")
+def start():
+ app.run(host=app.config.get("PORTAL_HOST", "0.0.0.0"), port=app.config.get("PORTAL_PORT", 8081), debug=False)
+
from view import index
from view.auth import auth
from view.user import user
diff --git a/rrd/config.py b/rrd/config.py
index a46a077..b567077 100755
--- a/rrd/config.py
+++ b/rrd/config.py
@@ -20,6 +20,8 @@
SECRET_KEY = os.environ.get("SECRET_KEY","secret-key")
PERMANENT_SESSION_LIFETIME = os.environ.get("PERMANENT_SESSION_LIFETIME",3600 * 24 * 30)
SITE_COOKIE = os.environ.get("SITE_COOKIE","open-falcon-ck")
+PORTAL_HOST = os.environ.get("PORTAL_HOST","127.0.0.1")
+PORTAL_PORT = os.environ.get("PORTAL_PORT",8081)
# Falcon+ API
API_ADDR = os.environ.get("API_ADDR","http://127.0.0.1:18080/api/v1")
diff --git a/rrd/model/portal/bean.py b/rrd/model/portal/bean.py
index 2dfa339..46153ec 100644
--- a/rrd/model/portal/bean.py
+++ b/rrd/model/portal/bean.py
@@ -103,7 +103,7 @@ def select(cls, cols=None, where=None, params=None, order=None, limit=None, page
@classmethod
def select_vs(cls, where=None, params=None, order=None, limit=None, page=None, offset=None):
rows = cls.select(where=where, params=params, order=order, limit=limit, page=page, offset=offset)
- return [cls(*row) for row in rows]
+ return [cls(*row) for row in rows] if rows is not None else None
@classmethod
def read(cls, where=None, params=None):
@@ -123,7 +123,7 @@ def get(cls, id_val):
@classmethod
def column(cls, col=None, where=None, params=None, order=None, limit=None, page=None, offset=None):
rows = cls.select(col, where, params, order, limit, page, offset)
- return [row[0] for row in rows]
+ return [row[0] for row in rows] if rows is not None else None
@classmethod
def total(cls, where=None, params=None):
@@ -134,7 +134,7 @@ def total(cls, where=None, params=None):
sql += ' WHERE ' + where
ret = cls._db.query_column(sql, params)
- return ret[0]
+ return ret[0] if ret and len(ret) > 0 else None
@classmethod
def exists(cls, where=None, params=None):
diff --git a/rrd/static/js/portal.js b/rrd/static/js/portal.js
index 034be17..c939f7d 100644
--- a/rrd/static/js/portal.js
+++ b/rrd/static/js/portal.js
@@ -168,6 +168,10 @@ function batch_add_host() {
}, "json");
}
+function goto_url(url) {
+ window.location = url;
+}
+
function host_unbind_group(host_id, group_id) {
$.getJSON('/portal/host/unbind', {'host_id': host_id, 'group_id': group_id}, function (json) {
handle_quietly(json, function () {
diff --git a/rrd/store.py b/rrd/store.py
index dd69824..1038cbc 100644
--- a/rrd/store.py
+++ b/rrd/store.py
@@ -55,8 +55,8 @@ def __init__(self, cfg):
self.config = cfg
self.conn = None
- def get_conn(self):
- if self.conn is None:
+ def get_conn(self, reset=False):
+ if self.conn is None or reset:
self.conn = connect_db(self.config)
return self.conn
@@ -67,9 +67,10 @@ def execute(self, *a, **kw):
cursor.execute(*a, **kw)
except (AttributeError, MySQLdb.OperationalError):
self.conn and self.conn.close()
- self.conn = None
- cursor = self.get_conn().cursor()
- cursor.execute(*a, **kw)
+ self.conn = self.get_conn(True)
+ if self.conn:
+ cursor = self.conn.cursor()
+ cursor.execute(*a, **kw)
return cursor
# insert one record in a transaction
@@ -78,7 +79,7 @@ def insert(self, *a, **kw):
cursor = None
try:
cursor = self.execute(*a, **kw)
- row_id = cursor.lastrowid
+ row_id = cursor.lastrowid if cursor else None
self.commit()
return row_id
except MySQLdb.IntegrityError:
@@ -104,7 +105,7 @@ def query_all(self, *a, **kw):
cursor = None
try:
cursor = self.execute(*a, **kw)
- return cursor.fetchall()
+ return cursor.fetchall() if cursor else None
finally:
cursor and cursor.close()
diff --git a/rrd/templates/portal/alarm/case.html b/rrd/templates/portal/alarm/case.html
index 9118662..9e785f5 100644
--- a/rrd/templates/portal/alarm/case.html
+++ b/rrd/templates/portal/alarm/case.html
@@ -9,47 +9,51 @@
{{_('alerting cases')}}
- {%for case in cases%}
-
-
- {{case.status}} P{{case.priority}}
- [第
#{{case.current_step}} 次/最大{{case.max_step}}次]
-
{{case.timestamp|time_duration}}
-
[
-
template
+ {% if cases is not none %}
+ {%for case in cases%}
+
+
+ {{case.status}} P{{case.priority}}
+ [第
#{{case.current_step}} 次/最大{{case.max_step}}次]
+
{{case.timestamp|time_duration}}
+
[
+
template
- {%if case.strategy_id>0%}
-
¦
-
strategy
- {%endif%}
+ {%if case.strategy_id>0%}
+
¦
+
strategy
+ {%endif%}
- {%if case.expression_id>0%}
-
¦
-
expression
- {%endif%}
+ {%if case.expression_id>0%}
+
¦
+
expression
+ {%endif%}
-
¦
-
delete
-
¦
-
{{_('event list')}}
-
]
-
+
¦
+
delete
+
¦
+
{{_('event list')}}
+
]
+
-
{{case.endpoint}}
- ¦
- {{case.metric}}
- ¦
- {{case.func}}
- ¦
- {{case.cond}}
-
¦
-
note: {{case.note}}
-
-
- {%endfor%}
+
{{case.endpoint}}
+ ¦
+ {{case.metric}}
+ ¦
+ {{case.func}}
+ ¦
+ {{case.cond}}
+
¦
+
note: {{case.note}}
+
+
+ {%endfor%}
{{_('select all')}} /
{{_('reverse select')}}
{{_('batch delete')}}
+ {% else %}
+ list fail, view logs for more.
+ {% endif %}
diff --git a/rrd/templates/portal/expression/list.html b/rrd/templates/portal/expression/list.html
index 1f64e0e..4fb6c35 100644
--- a/rrd/templates/portal/expression/list.html
+++ b/rrd/templates/portal/expression/list.html
@@ -20,41 +20,46 @@
- {% set left = '{' %}
- {% set right = '}' %}
- {% for v in data.vs %}
+ {% if data.vs is not none %}
+ {% set left = '{' %}
+ {% set right = '}' %}
+ {% for v in data.vs %}
-
+
-
{{ v.expression }}
-
-
if {{ v.func }}{{ v.op }}{{ v.right_value }}
- {{ left }}{{ v.action.html()|safe }}{{ right }}
+
{{ v.expression }}
+
+
if {{ v.func }}{{ v.op }}{{ v.right_value }}
+ {{ left }}{{ v.action.html()|safe }}{{ right }}
- {% if v.writable(g.user) %}
-
- {% endif %}
-
-
- note: {{ v.note }} (Max:{{ v.max_step }}, P{{ v.priority }})
- by {{ v.create_user }}
-
+ {% if v.writable(g.user) %}
+
+ {% endif %}
+
+
+ note: {{ v.note }} (Max:{{ v.max_step }}, P{{ v.priority }})
+ by {{ v.create_user }}
+
+ {% else %}
+
+ no records
+ {% endfor %}
{% else %}
- no records
- {% endfor %}
+ list fail, view logs for more.
+ {% endif %}
{% import "portal/blocks.html" as blocks %}
diff --git a/rrd/templates/portal/group/index.html b/rrd/templates/portal/group/index.html
index 0ff1e9b..cb76747 100644
--- a/rrd/templates/portal/group/index.html
+++ b/rrd/templates/portal/group/index.html
@@ -31,33 +31,39 @@
- {% for v in data.vs %}
-
- {{ v.grp_name }}
- {{ v.create_user }}
-
- templates
- ¦
- hosts
- ¦
- plugins
- ¦
- aggregator
- {% if v.writable(g.user) %}
+ {% if data.vs is not none %}
+ {% for v in data.vs %}
+
+ {{ v.grp_name }}
+ {{ v.create_user }}
+
+ templates
¦
-
-
-
+ hosts
¦
-
-
-
- {% endif %}
-
-
+ plugins
+ ¦
+ aggregator
+ {% if v.writable(g.user) %}
+ ¦
+
+
+
+ ¦
+
+
+
+ {% endif %}
+
+
+ {% else %}
+ no records
+ {% endfor %}
{% else %}
- no records
- {% endfor %}
+
+ list fail, view logs for more.
+
+ {% endif %}
{% import "portal/blocks.html" as blocks %}
diff --git a/rrd/templates/portal/host/add.html b/rrd/templates/portal/host/add.html
index 5e56f43..ee51497 100644
--- a/rrd/templates/portal/host/add.html
+++ b/rrd/templates/portal/host/add.html
@@ -23,7 +23,7 @@
Add Host
-
+
Back
diff --git a/rrd/templates/portal/nodata/list.html b/rrd/templates/portal/nodata/list.html
index dd53eaf..f70db60 100644
--- a/rrd/templates/portal/nodata/list.html
+++ b/rrd/templates/portal/nodata/list.html
@@ -38,30 +38,35 @@
- {% for v in data.vs %}
-
-
{{ v.name }}; {{ v.obj_type }} [{{ v.obj }}]/{{ v.metric }}/{{ v.tags }}; type={{ v.dstype }},step={{ v.step }}
-
-
默认值: {{ v.mock }}
- {% if v.writable(g.user) %}
-
- {% endif %}
-
-
-
创建人: {{ v.creator }}, 最后更改时间: {{ v.t_modify }}
-
+ {% if data.vs is not none %}
+ {% for v in data.vs %}
+
+
{{ v.name }}; {{ v.obj_type }} [{{ v.obj }}]/{{ v.metric }}/{{ v.tags }}; type={{ v.dstype }},step={{ v.step }}
+
+
默认值: {{ v.mock }}
+ {% if v.writable(g.user) %}
+
+ {% endif %}
+
+
+
创建人: {{ v.creator }}, 最后更改时间: {{ v.t_modify }}
+
+ {% else %}
+
+ no records
+ {% endfor %}
{% else %}
- no records
- {% endfor %}
+ list fail, view logs for more.
+ {% endif %}
{% import "portal/blocks.html" as blocks %}
diff --git a/rrd/templates/portal/template/list.html b/rrd/templates/portal/template/list.html
index 49f67dd..886c8cf 100644
--- a/rrd/templates/portal/template/list.html
+++ b/rrd/templates/portal/template/list.html
@@ -31,41 +31,47 @@
- {% for v in data.vs %}
-
- {{ v.tpl_name }}
- {% if v.parent %}{{ v.parent.tpl_name }} {% endif %}
-
- {{ v.create_user }}
-
-
-
-
-
- {% if v.writable(g.user) %}
- ¦
-
-
-
- ¦
-
-
+ {% if data.vs is not none %}
+ {% for v in data.vs %}
+
+ {{ v.tpl_name }}
+ {% if v.parent %}{{ v.parent.tpl_name }} {% endif %}
+
+ {{ v.create_user }}
+
+
+
+
- ¦
-
-
-
- {% endif %}
-
-
+ {% if v.writable(g.user) %}
+ ¦
+
+
+
+ ¦
+
+
+
+ ¦
+
+
+
+ {% endif %}
+
+
+ {% else %}
+
+ no records
+
+ {% endfor %}
{% else %}
- no records
+ list fail, view logs for more.
- {% endfor %}
+ {% endif %}
diff --git a/rrd/view/portal/expression.py b/rrd/view/portal/expression.py
index 9b48cef..cf6f6ad 100644
--- a/rrd/view/portal/expression.py
+++ b/rrd/view/portal/expression.py
@@ -29,8 +29,9 @@ def expressions_get():
mine = request.args.get('mine', '1')
me = g.user.name if mine == '1' else None
vs, total = Expression.query(page, limit, query, me)
- for v in vs:
- v.action = Action.get(v.action_id)
+ if vs:
+ for v in vs:
+ v.action = Action.get(v.action_id)
return render_template(
'portal/expression/list.html',
data={
diff --git a/rrd/view/portal/group.py b/rrd/view/portal/group.py
index 16a9f97..1060369 100644
--- a/rrd/view/portal/group.py
+++ b/rrd/view/portal/group.py
@@ -32,8 +32,10 @@ def group_create_post():
grp_id = HostGroup.create(grp_name, g.user.name, 1)
if grp_id > 0:
return jsonify(msg='')
- else:
+ elif grp_id == -1:
return jsonify(msg='grp_name has already existent')
+ else:
+ return jsonify(msg='create fail, view logs for more.')
@app.route('/portal/group/delete/')
diff --git a/rrd/view/portal/template.py b/rrd/view/portal/template.py
index 765217f..db27ec1 100644
--- a/rrd/view/portal/template.py
+++ b/rrd/view/portal/template.py
@@ -34,8 +34,9 @@ def templates_get():
mine = request.args.get('mine', '1')
me = g.user.name if mine == '1' else None
vs, total = Template.query(page, limit, query, me)
- for v in vs:
- v.parent = Template.get(v.parent_id)
+ if vs:
+ for v in vs:
+ v.parent = Template.get(v.parent_id)
return render_template(
'portal/template/list.html',
data={
@@ -62,7 +63,7 @@ def template_create_post():
if tpl_id:
return jsonify(msg='', id=tpl_id)
- return jsonify(msg='create fail')
+ return jsonify(msg='create fail, view logs for more.')
@app.route('/portal/template/update/')
diff --git a/wsgi.py b/wsgi.py
index d280ff7..b8f6376 100755
--- a/wsgi.py
+++ b/wsgi.py
@@ -25,7 +25,7 @@
import sys
sys.path.insert(0, base_dir)
-from rrd import app
+from rrd import start
if __name__ == "__main__":
- app.run(host="0.0.0.0", port=8081, debug=False)
+ start()