From bce33aee0f627e6e6b674f738718006c98fa0c72 Mon Sep 17 00:00:00 2001 From: Corey Hammerton Date: Wed, 19 Aug 2015 21:01:11 -0400 Subject: [PATCH] puppetboard: Adding Catalog Viewer This makes use of the available catalog endpoints in pypuppetdb and PuppetDB and displays to administrators the last compiled catalog for a node, if the variable ENABLE_CATALOG is True (defaults to False) --- puppetboard/app.py | 10 +++ puppetboard/default_settings.py | 1 + puppetboard/static/coffeescript/tables.coffee | 4 ++ puppetboard/static/js/tables.js | 5 ++ puppetboard/templates/catalog.html | 61 +++++++++++++++++++ puppetboard/templates/nodes.html | 2 +- 6 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 puppetboard/templates/catalog.html diff --git a/puppetboard/app.py b/puppetboard/app.py index 8a54fac..7662f10 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -403,3 +403,13 @@ def metric(metric): 'metric.html', name=name, metric=sorted(metric.items())) + +@app.route('/catalog/') +def catalog_node(node_name): + """Fetches from PuppetDB the compiled catalog of a given node.""" + if app.config['ENABLE_CATALOG']: + catalog = puppetdb.catalog(node=node_name) + return render_template('catalog.html', catalog=catalog) + else: + log.warn('Access to catalog interface disabled by administrator') + abort(403) diff --git a/puppetboard/default_settings.py b/puppetboard/default_settings.py index 2dd76b6..65c9ec6 100644 --- a/puppetboard/default_settings.py +++ b/puppetboard/default_settings.py @@ -16,6 +16,7 @@ LOCALISE_TIMESTAMP = True LOGLEVEL = 'info' REPORTS_COUNT = 10 OFFLINE_MODE = False +ENABLE_CATALOG = False GRAPH_FACTS = ['architecture', 'domain', 'lsbcodename', diff --git a/puppetboard/static/coffeescript/tables.coffee b/puppetboard/static/coffeescript/tables.coffee index 65a3e81..aede435 100644 --- a/puppetboard/static/coffeescript/tables.coffee +++ b/puppetboard/static/coffeescript/tables.coffee @@ -35,6 +35,10 @@ $('.dashboard').tablesorter( sortList: [[0, 1]] ) +$('.catalog').tablesorter( + sortList: [[0, 0]] +) + $('input.filter-table').parent('div').removeClass('hide') $("input.filter-table").on "keyup", (e) -> rex = new RegExp($(this).val(), "i") diff --git a/puppetboard/static/js/tables.js b/puppetboard/static/js/tables.js index 3c945f7..fc85af4 100644 --- a/puppetboard/static/js/tables.js +++ b/puppetboard/static/js/tables.js @@ -52,6 +52,11 @@ sortList: [[0, 1]] }); + + $('.catalog').tablesorter({ + sortList: [[0, 0]] + }) + $('input.filter-table').parent('div').removeClass('hide'); $("input.filter-table").on("keyup", function(e) { diff --git a/puppetboard/templates/catalog.html b/puppetboard/templates/catalog.html new file mode 100644 index 0000000..3a43248 --- /dev/null +++ b/puppetboard/templates/catalog.html @@ -0,0 +1,61 @@ +{% extends 'layout.html' %} +{% block content %} +
+ +
+

Summary

+ + + + + + + + + + + + + + + +
HostnameVersionTransaction UUID
{{catalog.node}}{{catalog.version}}{{catalog.transaction_uuid}}
+ +

Resources

+ + + + + + + + + {% for resource in catalog.get_resources() %} + + + + + {% endfor %} + +
ResourceLocation
{{resource.type_}}[{{resource.name}}]{{resource.sourcefile}}:{{resource.sourceline}}
+ +

Edges

+ + + + + + + + + + {% for edge in catalog.get_edges() %} + + + + + + {% endfor %} + +
SourceRelationshipTarget
{{edge.source}}{{edge.relationship}}{{edge.target}}
+{% endblock content %} diff --git a/puppetboard/templates/nodes.html b/puppetboard/templates/nodes.html index 3a48688..c657706 100644 --- a/puppetboard/templates/nodes.html +++ b/puppetboard/templates/nodes.html @@ -39,7 +39,7 @@ {% endif %} {{node.name}} - {{node.catalog_timestamp}} + {{node.catalog_timestamp}} {% if node.report_timestamp %} {{ node.report_timestamp }}