From 63d932765d86dc3bfb356fb9136b28d5e9b83aef Mon Sep 17 00:00:00 2001 From: huangchao Date: Wed, 6 Sep 2017 18:13:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?alarm=20dashboard=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + rrd/model/portal/alarm.py | 11 +- rrd/model/portal/bean.py | 1 - rrd/templates/portal/alarm/case.html | 46 +++++++- rrd/templates/portal/alarm/case_problem.html | 105 +++++++++++++++++++ rrd/view/portal/alarm.py | 9 +- 6 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 rrd/templates/portal/alarm/case_problem.html diff --git a/.gitignore b/.gitignore index e27f8df..c6f9c58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ env/ var/ log/ diff --git a/rrd/model/portal/alarm.py b/rrd/model/portal/alarm.py index 8a18dff..0194061 100644 --- a/rrd/model/portal/alarm.py +++ b/rrd/model/portal/alarm.py @@ -57,7 +57,7 @@ def __init__(self, id, endpoint, metric, func, cond, note, max_step, current_ste self.process_status = process_status @classmethod - def query(cls, page, limit, endpoint_query, metric_query, status): + def query(cls, page, limit, endpoint_query, metric_query, status, from_data, to_data): where = '1=1' params = [] if status == "PROBLEM" or status == "OK": @@ -72,6 +72,15 @@ def query(cls, page, limit, endpoint_query, metric_query, status): where += ' and metric like %s' params.append('%' + metric_query + '%') + if from_data != "": + where += ' and timestamp >= %s' + params.append(from_data) + + if to_data != "": + where += ' and timestamp <= %s' + params.append(to_data) + + vs = cls.select_vs(where=where, params=params, page=page, limit=limit, order='update_at desc') total = cls.total(where, params) diff --git a/rrd/model/portal/bean.py b/rrd/model/portal/bean.py index edfb332..1b58ed5 100644 --- a/rrd/model/portal/bean.py +++ b/rrd/model/portal/bean.py @@ -82,7 +82,6 @@ def select(cls, cols=None, where=None, params=None, order=None, limit=None, page if offset < 0: offset = 0 sql = '%s OFFSET %s' % (sql, offset) - return cls._db.query_all(sql, params) @classmethod diff --git a/rrd/templates/portal/alarm/case.html b/rrd/templates/portal/alarm/case.html index 9118662..ca60e72 100644 --- a/rrd/templates/portal/alarm/case.html +++ b/rrd/templates/portal/alarm/case.html @@ -1,6 +1,47 @@ {% extends "portal/layout.html" %} {% block content %} - +
+
+ + +
+
+ + +
+
+ +
+ + + + +
+
+
+ +
+ + + + +
+
+ + +
+

{{_('alerting cases')}} @@ -14,6 +55,7 @@

{{_('alerting cases')}} {{case.status}} P{{case.priority}} [第#{{case.current_step}}次/最大{{case.max_step}}次] + {{case.timestamp}} {{case.timestamp|time_duration}} [ template @@ -55,7 +97,7 @@

{{_('alerting cases')}} {% import "portal/blocks.html" as blocks %}
- {{ blocks.pager('/portal/alarm-dash/case?status='+status, total, limit, page) }} + {{ blocks.pager('/portal/alarm-dash/case?status='+status+'&endpoint_q='+endpoint_q+'&metric_q='+metric_q+'&from_data='+from_data+'&to_data='+to_data, total, limit, page) }}

diff --git a/rrd/templates/portal/alarm/case_problem.html b/rrd/templates/portal/alarm/case_problem.html new file mode 100644 index 0000000..9c84485 --- /dev/null +++ b/rrd/templates/portal/alarm/case_problem.html @@ -0,0 +1,105 @@ +{% extends "portal/layout.html" %} +{% block content %} +
+
+ + +
+
+ + +
+
+ +
+ + + + +
+
+
+ +
+ + + + +
+
+ + + +
+
+
+
+

{{_('alerting cases')}} + {{_('not recovered cases')}} +

+
+
+
+ {%for case in cases%} +
+ + {{case.status}} P{{case.priority}} + [第#{{case.current_step}}次/最大{{case.max_step}}次] + {{case.timestamp}} + {{case.timestamp|time_duration}} + [ + template + + {%if case.strategy_id>0%} + ¦ + strategy + {%endif%} + + {%if case.expression_id>0%} + ¦ + expression + {%endif%} + + ¦ + delete + ¦ + {{_('event list')}} + ] +
+ + {{case.endpoint}} + ¦ + {{case.metric}} + ¦ + {{case.func}} + ¦ + {{case.cond}} + ¦ + note: {{case.note}} +
+
+ {%endfor%} + {{_('select all')}}/ + {{_('reverse select')}} + +
+
+ + {% import "portal/blocks.html" as blocks %} +
+ {{ blocks.pager('/portal/alarm-dash/case?status='+status+'&endpoint_q='+endpoint_q+'&metric_q='+metric_q+'&from_data='+from_data+'&to_data='+to_data, total, limit, page) }} +
+ +
+{%endblock%} diff --git a/rrd/view/portal/alarm.py b/rrd/view/portal/alarm.py index ba1bad6..31be220 100644 --- a/rrd/view/portal/alarm.py +++ b/rrd/view/portal/alarm.py @@ -12,9 +12,14 @@ def alarm_dash_case_get(): endpoint_q = request.args.get("endpoint_q") or "" metric_q = request.args.get("metric_q") or "" status = request.args.get("status") or "" + from_data = request.args.get("from_data") or "" + to_data = request.args.get("to_data") or "" - cases, total = EventCase.query(page, limit, endpoint_q, metric_q, status) - return render_template("portal/alarm/case.html", **locals()) + cases, total = EventCase.query(page, limit, endpoint_q, metric_q, status, from_data, to_data) + if status == 'PROBLEM': + return render_template("portal/alarm/case_problem.html", **locals()) + else: + return render_template("portal/alarm/case.html", **locals()) @app.route("/portal/alarm-dash/case/event") def alarm_dash_event_get(): From f3c935a4eae5c625343cf963bc0f8c93281b16bb Mon Sep 17 00:00:00 2001 From: huangchao Date: Thu, 7 Sep 2017 16:33:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dexpression=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=BF=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rrd/templates/portal/expression/list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rrd/templates/portal/expression/list.html b/rrd/templates/portal/expression/list.html index 6753dff..1f64e0e 100644 --- a/rrd/templates/portal/expression/list.html +++ b/rrd/templates/portal/expression/list.html @@ -58,7 +58,7 @@
{% import "portal/blocks.html" as blocks %} - {{ blocks.pager('/portal/expressions?q='+data.query+'&mine='+data.mine, data.total, data.limit, data.page) }} + {{ blocks.pager('/portal/expression?q='+data.query+'&mine='+data.mine, data.total, data.limit, data.page) }}