Skip to content
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

alarm dashboard页面添加搜索功能 #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
env/
var/
log/
Expand Down
11 changes: 10 additions & 1 deletion rrd/model/portal/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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)

Expand Down
1 change: 0 additions & 1 deletion rrd/model/portal/bean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 44 additions & 2 deletions rrd/templates/portal/alarm/case.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
{% extends "portal/layout.html" %}
{% block content %}

<form class="form-inline", method="get">
<div class="form-group">
<label for="endpoint">EndPoint</label>
<input type="text" class="form-control" id="endpoint" name="endpoint_q">
</div>
<div class="form-group">
<label for="metric">Metric</label>
<input type="text" class="form-control" id="metric" name="metric_q">
</div>
<div class="form-group">
<label>From</label>
<div class='input-group date' id='from_data'>
<input type='text' class="form-control" name="from_data" placeholder="YYYY-MM-DD HH:mm:ss"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="form-group">
<label>To</label>
<div class='input-group date' id='to_data'>
<input type='text' class="form-control" name="to_data" placeholder="YYYY-MM-DD HH:mm:ss"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<button type="submit" class="btn btn-default">Search</button>
<script>
$( function() {
$('#from_data').datetimepicker({
format: 'YYYY-MM-DD',
locale: moment.locale('zh-cn')
});
$('#to_data').datetimepicker({
format: 'YYYY-MM-DD',
locale: moment.locale('zh-cn')
});
} );
</script>
</form>
<br/>
<div class="panel panel-danger">
<div class="panel-heading">
<h4 class="panel-title">{{_('alerting cases')}}
Expand All @@ -14,6 +55,7 @@ <h4 class="panel-title">{{_('alerting cases')}}
<input type="checkbox" alarm="{{case.id}}">
{{case.status}} P{{case.priority}}
[第<span class="orange">#{{case.current_step}}</span>次/最大{{case.max_step}}次]
<span class="orange">{{case.timestamp}}</span>
<span class="orange">{{case.timestamp|time_duration}}</span>
<span class="gray">[</span>
<a href="/portal/template/view/{{case.template_id}}" target="_blank">template</a>
Expand Down Expand Up @@ -55,7 +97,7 @@ <h4 class="panel-title">{{_('alerting cases')}}

{% import "portal/blocks.html" as blocks %}
<div class="pull-left">
{{ 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) }}
</div>

</div>
Expand Down
105 changes: 105 additions & 0 deletions rrd/templates/portal/alarm/case_problem.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{% extends "portal/layout.html" %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个模板文件是多余的:)

{% block content %}
<form class="form-inline", method="get">
<div class="form-group">
<label for="endpoint">EndPoint</label>
<input type="text" class="form-control" id="endpoint" name="endpoint_q">
</div>
<div class="form-group">
<label for="metric">Metric</label>
<input type="text" class="form-control" id="metric" name="metric_q">
</div>
<div class="form-group">
<label>From</label>
<div class='input-group date' id='from_data'>
<input type='text' class="form-control" name="from_data" placeholder="YYYY-MM-DD HH:mm:ss"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="form-group">
<label>To</label>
<div class='input-group date' id='to_data'>
<input type='text' class="form-control" name="to_data" placeholder="YYYY-MM-DD HH:mm:ss"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<input type="text" name="status" value="PROBLEM" hidden>
<button type="submit" class="btn btn-default">Search</button>
<script>
$( function() {
$('#from_data').datetimepicker({
format: 'YYYY-MM-DD',
locale: moment.locale('zh-cn')
});
$('#to_data').datetimepicker({
format: 'YYYY-MM-DD',
locale: moment.locale('zh-cn')
});
} );
</script>
</form>
<br/>
<div class="panel panel-danger">
<div class="panel-heading">
<h4 class="panel-title">{{_('alerting cases')}}
<a class="pull-right small" href="/portal/alarm-dash/case?status=PROBLEM">{{_('not recovered cases')}}</a>
</h4>
</div>
<div class="panel-body">
<div class="alarms">
{%for case in cases%}
<div class="alarm">
<input type="checkbox" alarm="{{case.id}}">
{{case.status}} P{{case.priority}}
[第<span class="orange">#{{case.current_step}}</span>次/最大{{case.max_step}}次]
<span class="orange">{{case.timestamp}}</span>
<span class="orange">{{case.timestamp|time_duration}}</span>
<span class="gray">[</span>
<a href="/portal/template/view/{{case.template_id}}" target="_blank">template</a>

{%if case.strategy_id>0%}
<span class="cut-line">¦</span>
<a href="/portal/strategy/{{case.strategy_id}}" target="_blank">strategy</a>
{%endif%}

{%if case.expression_id>0%}
<span class="cut-line">¦</span>
<a href="/portal/expression/view/{{case.expression_id}}" target="_blank">expression</a>
{%endif%}

<span class="cut-line">¦</span>
<a href="javascript:alarm_case_rm('{{case.id}}');">delete</a>
<span class="cut-line">¦</span>
<a href="/portal/alarm-dash/case/event?case_id={{case.id}}">{{_('event list')}}</a>
<span class="gray">]</span>
</br>

<span style="padding-left:17px;"> {{case.endpoint}}
<span class="cut-line">¦</span>
{{case.metric}}
<span class="cut-line">¦</span>
{{case.func}}
<span class="cut-line">¦</span>
{{case.cond}}</span>
<span class="cut-line">¦</span>
<span class="gray">note: {{case.note}}</span>
</div>
<hr>
{%endfor%}
<a href="javascript:alarm_case_all_select();">{{_('select all')}}</a>/
<a href="javascript:alarm_case_reverse_select();">{{_('reverse select')}}</a>
<button class="btn btn-warning btn-sm" onclick="alarm_case_batch_rm();">{{_('batch delete')}}</button>
</div>
</div>

{% import "portal/blocks.html" as blocks %}
<div class="pull-left">
{{ 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) }}
</div>

</div>
{%endblock%}
2 changes: 1 addition & 1 deletion rrd/templates/portal/expression/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</div>

{% 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) }}

<br/>
<br/>
Expand Down
9 changes: 7 additions & 2 deletions rrd/view/portal/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case_problem.html 这个文件是多余的哈,可以删除的:)

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():
Expand Down