diff --git a/puppetboard/app.py b/puppetboard/app.py index c7301dc..4aef489 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -531,25 +531,17 @@ def reports_ajax(env, node_name): reports_events = [] total = 0 - report_event_counts = {} - # Create a map from the metrics data to what the templates - # use to express the data. - events_metrics = ['success', 'failure', 'noop'] - resources_metrics = ['total', 'skipped'] + # Convert metrics to relational dict + metrics = {} for report in reports_events: if total is None: total = puppetdb.total - report_counts = {} - for metric in report.metrics: - if ('category' in metric and metric['category'] == 'events' and - 'name' in metric and metric['name'] in events_metrics): - report_counts[metric['name']] = metric['value'] - if ('category' in metric and metric['category'] == 'resources' and - 'name' in metric and metric['name'] in resources_metrics): - report_counts[metric['name']] = metric['value'] - - report_event_counts[report.hash_] = report_counts + metrics[report.hash_] = {'resources': {}, 'events': {}} + for m in report.metrics: + if m['category'] not in metrics[report.hash_]: + metrics[report.hash_][m['category']] = {} + metrics[report.hash_][m['category']][m['name']] = m['value'] if total is None: total = 0 @@ -560,7 +552,7 @@ def reports_ajax(env, node_name): total=total, total_filtered=total, reports=reports, - report_event_counts=report_event_counts, + metrics=metrics, envs=envs, current_env=env, columns=REPORTS_COLUMNS[:max_col]) diff --git a/puppetboard/templates/_macros.html b/puppetboard/templates/_macros.html index 7a07f15..f7ce947 100644 --- a/puppetboard/templates/_macros.html +++ b/puppetboard/templates/_macros.html @@ -57,16 +57,16 @@ {% endif %} {%- endmacro %} -{% macro report_status(caller, status, node_name, events, current_env, unreported_time=False, report_hash=False) -%} +{% macro report_status(caller, status, node_name, metrics, current_env, unreported_time=False, report_hash=False) -%} {{ status|upper }} {% if status == 'unreported' %} {{ unreported_time|upper }} {% else %} - {{events['total']}}{% else %}">0{% endif%} - {{events['failure']}}{% else %}">0{% endif%} - {{events['success']}}{% else %}">0{% endif%} - {{events['skipped']}}{% else %}">0{% endif%} - {{events['noop']}}{% else %}">0{% endif%} + {{ metrics.resources.total }}{% else %}">0{% endif%} + {{ metrics.events.failure }}{% else %}">0{% endif%} + {{ metrics.events.success }}{% else %}">0{% endif%} + {{ metrics.resources.skipped }}{% else %}">0{% endif%} + {{ metrics.events.noop }}{% else %}">0{% endif%} {% endif %} {%- endmacro %} diff --git a/puppetboard/templates/reports.json.tpl b/puppetboard/templates/reports.json.tpl index 9f74e31..b773105 100644 --- a/puppetboard/templates/reports.json.tpl +++ b/puppetboard/templates/reports.json.tpl @@ -15,7 +15,7 @@ "{{ report[column.attr] }}" {%- elif column.type == 'status' -%} {% filter jsonprint -%} - {{ macros.report_status(status=report.status, node_name=report.node, events=report_event_counts[report.hash_], report_hash=report.hash_, current_env=current_env) }} + {{ macros.report_status(status=report.status, node_name=report.node, metrics=metrics[report.hash_], report_hash=report.hash_, current_env=current_env) }} {%- endfilter %} {%- elif column.type == 'node' -%} {% filter jsonprint %}{{ report.node }}{% endfilter %}