diff --git a/puppetboard/app.py b/puppetboard/app.py index 9b216d2..113eaf8 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -517,25 +517,43 @@ def report_latest(env, node_name): check_env(env, envs) if env == '*': - query='["and",' \ - '["=", "certname", "{0}"],' \ - '["=", "latest_report?", true]]'.format(node_name) + node_query = '["=", "certname", "{0}"]'.format(node_name) else: - query='["and",' \ - '["=", "environment", "{0}"],' \ - '["=", "certname", "{1}"],' \ - '["=", "latest_report?", true]]'.format( - env, - node_name) + node_query = '["and",' \ + '["=", "report_environment", "{0}"],' \ + '["=", "certname", "{1}"]]'.format(env, node_name) - reports = get_or_abort(puppetdb.reports, query=query) try: - report = next(reports) + node = next(get_or_abort(puppetdb.nodes, + query=node_query, + with_status=True)) except StopIteration: abort(404) + if node.latest_report_hash is not None: + hash_ = node.latest_report_hash + else: + if env == '*': + query='["and",' \ + '["=", "certname", "{0}"],' \ + '["=", "latest_report?", true]]'.format(node.name) + else: + query='["and",' \ + '["=", "environment", "{0}"],' \ + '["=", "certname", "{1}"],' \ + '["=", "latest_report?", true]]'.format( + env, + node.name) + + reports = get_or_abort(puppetdb.reports, query=query) + try: + report = next(reports) + hash_ = report.hash_ + except StopIteration: + abort(404) + return redirect( - url_for('report', env=env, node_name=node_name, report_id=report.hash_)) + url_for('report', env=env, node_name=node_name, report_id=hash_)) @app.route('/report//', defaults={'env': app.config['DEFAULT_ENVIRONMENT']}) diff --git a/puppetboard/templates/catalog.html b/puppetboard/templates/catalog.html index 2a71894..33c4e21 100644 --- a/puppetboard/templates/catalog.html +++ b/puppetboard/templates/catalog.html @@ -10,6 +10,7 @@ Hostname Version Transaction UUID + Code ID @@ -17,6 +18,7 @@ {{catalog.node}} {{catalog.version}} {{catalog.transaction_uuid}} + {{catalog.code_id}} diff --git a/puppetboard/templates/index.html b/puppetboard/templates/index.html index 30aab3a..dcfe7be 100644 --- a/puppetboard/templates/index.html +++ b/puppetboard/templates/index.html @@ -79,14 +79,22 @@ {% if node.status != 'unchanged' %} - {{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}} + {% if node.latest_report_hash %} + {{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env, report_hash=node.latest_report_hash)}} + {% else %} + {{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}} + {% endif %} {{ node.name }} {% if node.report_timestamp %} - {{ node.report_timestamp }} + {% if node.latest_report_hash %} + {{ node.report_timestamp }} + {% else %} + {{ node.report_timestamp }} + {% endif %} {% else %} {% endif %} diff --git a/puppetboard/templates/nodes.html b/puppetboard/templates/nodes.html index bcf715d..70249a5 100644 --- a/puppetboard/templates/nodes.html +++ b/puppetboard/templates/nodes.html @@ -18,13 +18,21 @@ {% for node in nodes %} - {{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}} + {% if node.latest_report_hash %} + {{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env, report_hash=node.latest_report_hash)}} + {% else %} + {{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}} + {% endif %} {{node.name}} {{node.catalog_timestamp}} {% if node.report_timestamp %} - {{ node.report_timestamp }} + {% if node.latest_report_hash %} + {{ node.report_timestamp }} + {% else %} + {{ node.report_timestamp }} + {% endif %} {% else %} {% endif %} diff --git a/setup.py b/setup.py index 2f99e61..1ae3990 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ setup( "Flask >= 0.10.1", "Flask-WTF >= 0.9.4, <= 0.9.5", "WTForms < 2.0", - "pypuppetdb >= 0.2.0, < 0.3.0", + "pypuppetdb >= 0.2.1, < 0.3.0", ], keywords="puppet puppetdb puppetboard", classifiers=[