Skip to content

Commit

Permalink
Fix reports_status criterions
Browse files Browse the repository at this point in the history
  • Loading branch information
redref committed Feb 2, 2017
1 parent 8ee1f85 commit 1f961fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
49 changes: 38 additions & 11 deletions puppetboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ def environments():
return x


def reports_noop_query():
"""Compatibility function building a query string
to select noop reports.
Direct access fields 'noop' and 'noop_pending' are not set
by 3.X clients on a 4.X database.
"""
noop_event_query = EqualsOperator('status', 'noop')
noop_subquery = SubqueryOperator('events')
noop_subquery.add_query(noop_event_query)
noop_extract = ExtractOperator()
noop_extract.add_field(str('certname'))
noop_extract.add_query(noop_subquery)
noop_in_query = InOperator('certname')
noop_in_query.add_query(noop_extract)

other_event_query = NotOperator()
other_event_query.add(EqualsOperator('status', 'noop'))
other_subquery = SubqueryOperator('events')
other_subquery.add_query(other_event_query)
other_extract = ExtractOperator()
other_extract.add_field(str('certname'))
other_extract.add_query(other_subquery)
other_in_query = InOperator('certname')
other_in_query.add_query(other_extract)
other_not_in = NotOperator()
other_not_in.add(other_in_query)

result = AndOperator()
result.add([noop_in_query, other_not_in])
return result


def check_env(env, envs):
if env != '*' and env not in envs:
abort(404)
Expand Down Expand Up @@ -461,7 +493,7 @@ def reports_ajax(env, node_name):
order_column = int(request.args.get('order[0][column]', 0))
order_filter = REPORTS_COLUMNS[order_column].get(
'filter', REPORTS_COLUMNS[order_column]['attr'])
order_dir = request.args.get('order[0][dir]')
order_dir = request.args.get('order[0][dir]', 'desc')
order_args = '[{"field": "%s", "order": "%s"}]' % (order_filter, order_dir)
status_args = request.args.get('columns[1][search][value]', '').split('|')
max_col = len(REPORTS_COLUMNS)
Expand Down Expand Up @@ -492,18 +524,13 @@ def reports_ajax(env, node_name):
if status_arg in ['failed', 'changed', 'unchanged']:
arg_query = AndOperator()
arg_query.add(EqualsOperator('status', status_arg))
arg_query.add(EqualsOperator('noop', False))
status_query.add(arg_query)
if status_arg == 'unchanged':
arg_query = AndOperator()
arg_query.add(EqualsOperator('noop', True))
arg_query.add(EqualsOperator('noop_pending', False))
status_query.add(arg_query)
elif status_arg == 'noop':
arg_query = AndOperator()
arg_query.add(EqualsOperator('noop', True))
arg_query.add(EqualsOperator('noop_pending', True))
noop_query = NotOperator()
noop_query.add(reports_noop_query())
arg_query.add(noop_query)
status_query.add(arg_query)
elif status_arg == 'noop':
status_query.add(reports_noop_query())

if len(status_query.operations) == 0:
if len(reports_query.operations) == 0:
Expand Down
1 change: 1 addition & 0 deletions puppetboard/templates/_macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
{%- endmacro %}

{% macro report_status(caller, status, node_name, metrics, current_env, unreported_time=False, report_hash=False) -%}
{% if status == 'unchanged' and metrics.events and metrics.events.noop and metrics.events.noop > 0 %}{% set status = 'noop' %}{% endif %}
<a class="ui {{status}} label status" href="{{url_for('report', env=current_env, node_name=node_name, report_id=report_hash)}}">{{ status|upper }}</a>
{% if status == 'unreported' %}
<span class="ui label status"> {{ unreported_time|upper }} </span>
Expand Down

0 comments on commit 1f961fd

Please sign in to comment.