From 81c71607ae665320510cdf671eb8cc8125eed600 Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 16 May 2014 16:37:16 -0500 Subject: [PATCH] Added a hacky solution to allow users to be able to set a number of reports that they wish to display on the reports panel on the node page --- puppetboard/app.py | 7 ++++--- puppetboard/default_settings.py | 1 + puppetboard/templates/_macros.html | 8 ++++++-- puppetboard/templates/node.html | 2 +- puppetboard/utils.py | 10 ++++++++++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/puppetboard/app.py b/puppetboard/app.py index ed1a52f..d613d14 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -21,7 +21,7 @@ from pypuppetdb import connect from puppetboard.forms import QueryForm from puppetboard.utils import ( get_or_abort, yield_or_stop, - ten_reports, jsonprint + ten_reports, limit_reports, jsonprint ) @@ -173,12 +173,13 @@ def node(node_name): """ node = get_or_abort(puppetdb.node, node_name) facts = node.facts() - reports = ten_reports(node.reports()) + reports = limit_reports(node.reports(), app.config['REPORTS_COUNT']) return render_template( 'node.html', node=node, facts=yield_or_stop(facts), - reports=yield_or_stop(reports)) + reports=yield_or_stop(reports), + reports_count=app.config['REPORTS_COUNT']) @app.route('/reports') diff --git a/puppetboard/default_settings.py b/puppetboard/default_settings.py index 12f9e20..82f85ba 100644 --- a/puppetboard/default_settings.py +++ b/puppetboard/default_settings.py @@ -9,3 +9,4 @@ DEV_LISTEN_PORT = 5000 UNRESPONSIVE_HOURS = 2 ENABLE_QUERY = True LOGLEVEL = 'info' +REPORTS_COUNT = 10 diff --git a/puppetboard/templates/_macros.html b/puppetboard/templates/_macros.html index 3c0bad5..c0be9a5 100644 --- a/puppetboard/templates/_macros.html +++ b/puppetboard/templates/_macros.html @@ -95,9 +95,13 @@ {%- endmacro %} -{% macro reports_table(reports, nodename, condensed=False, hash_truncate=False, show_conf_col=True, show_agent_col=True, show_host_col=True) -%} + + +{% macro reports_table(reports, nodename, reports_count, condensed=False, hash_truncate=False, show_conf_col=True, show_agent_col=True, show_host_col=True) -%}
- Only showing the last ten reports. + + Only showing the last {{reports_count}} reports. +
diff --git a/puppetboard/templates/node.html b/puppetboard/templates/node.html index b5b4519..b0e83c9 100644 --- a/puppetboard/templates/node.html +++ b/puppetboard/templates/node.html @@ -28,7 +28,7 @@

Reports

- {{ macros.reports_table(reports, node.name, condensed=True, hash_truncate=True, show_conf_col=False, show_agent_col=False, show_host_col=False)}} + {{ macros.reports_table(reports, node.name, reports_count, condensed=True, hash_truncate=True, show_conf_col=False, show_agent_col=False, show_host_col=False)}}
diff --git a/puppetboard/utils.py b/puppetboard/utils.py index 608fbae..a4ad550 100644 --- a/puppetboard/utils.py +++ b/puppetboard/utils.py @@ -39,6 +39,16 @@ def ten_reports(reports): yield report +def limit_reports(reports, limit): + """Helper to yield a number of from the reports generator. + + This is an ugly solution at best... + """ + for count, report in enumerate(reports): + if count == limit: + raise StopIteration + yield report + def yield_or_stop(generator): """Similar in intent to get_or_abort this helper will iterate over our generators and handle certain errors.