From f187638b6eb673a18d3b165a34eaddf336720a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 5 Nov 2013 10:07:53 +0100 Subject: [PATCH] Enhance node status feature in overview and nodes This commit uses the new parameter with_status from nedap/pypuppetdb#18 Node status is now shown as text with the additional information of failed/succeded events, unreported time The statistics on Overview now show the *number of nodes* that have status failed/changed/unreported --- puppetboard/app.py | 51 +++++++++---------- puppetboard/static/css/puppetboard.css | 23 +++++++-- puppetboard/static/js/tables.js | 7 +++ puppetboard/templates/index.html | 68 +++++++++++++++----------- puppetboard/templates/nodes.html | 10 ++-- 5 files changed, 96 insertions(+), 63 deletions(-) diff --git a/puppetboard/app.py b/puppetboard/app.py index c25b78d..0294710 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -101,40 +101,35 @@ def index(): 'avg_resources_node': "{0:10.6f}".format(avg_resources_node['Value']), } - latest_event_count = puppetdb._query( - 'aggregate-event-counts', - query='["=", "latest-report?", true]', - summarize_by='certname') + nodes = puppetdb.nodes(with_status=True) - latest_event_count['noopskip'] = ( - latest_event_count['noops'] + latest_event_count['skips']) + nodes_overview = [] + stats = { + 'changed': 0, + 'unchanged': 0, + 'failed': 0, + 'unreported': 0, + } - latest_events = puppetdb._query( - 'event-counts', - query='["=", "latest-report?", true]', - summarize_by='certname') + for node in list(nodes): + if node.status == 'unreported': + stats['unreported'] += 1 + elif node.status == 'changed': + stats['changed'] += 1 + elif node.status == 'failed': + stats['failed'] += 1 + else: + stats['unchanged'] += 1 - unreported = [] - unresponsive_window = datetime.utcnow() - ( - timedelta(hours=app.config['UNRESPONSIVE_HOURS'])) - for node in puppetdb.nodes(): - try: - node_last_seen = node.report_timestamp.replace(tzinfo=None) - if node_last_seen < unresponsive_window: - delta = (datetime.utcnow() - node_last_seen) - node.noresponse = str(delta.days) + "d " - node.noresponse += str(int(delta.seconds / 3600)) + "h " - node.noresponse += str(int((delta.seconds % 3600) / 60)) + "m" - unreported.append(node) - except AttributeError: - unreported.append(node) + if node.status != 'unchanged': + nodes_overview.append(node) return render_template( 'index.html', metrics=metrics, - latest_event_count=latest_event_count, - latest_events=latest_events, - unreported=unreported) + nodes=nodes_overview, + stats=stats + ) @app.route('/nodes') @@ -169,7 +164,7 @@ def nodes(): nodes.append(node) else: nodes.append(node) - + nodes = puppetdb.nodes(with_status=True) return Response(stream_with_context( stream_template('nodes.html', nodes=nodes))) diff --git a/puppetboard/static/css/puppetboard.css b/puppetboard/static/css/puppetboard.css index 49d18d1..3e54c34 100644 --- a/puppetboard/static/css/puppetboard.css +++ b/puppetboard/static/css/puppetboard.css @@ -61,12 +61,29 @@ h1.success { h1.noop { color:#aaa; } -.numtag { - width:20px; +.label-count { + width:25px; + text-align:center; +} +.label-time { + width:73px; + text-align:center; +} +.label-status { + width:100px; text-align:center; } .label-nothing { background-color:#ddd; - width:20px; color:#ddd; } +.label.label-failed { + background-color: rgb(231, 76, 60); +} +.label.label-changed { + background-color: rgb(24, 188, 156); +} +.label.label-unreported { + background-color: rgb(231, 76, 60); + background-color: rgb(129, 145, 146); +} diff --git a/puppetboard/static/js/tables.js b/puppetboard/static/js/tables.js index 7fb44b8..a449ddd 100644 --- a/puppetboard/static/js/tables.js +++ b/puppetboard/static/js/tables.js @@ -19,6 +19,13 @@ sortList: [[0, 0]] }); + $('.dashboard').tablesorter({ + headers: { + 2: { sorter: false } + }, + sortList: [[0, 0]] + }); + $('input.filter-table').parent('div').removeClass('hide'); $("input.filter-table").on("keyup", function(e) { diff --git a/puppetboard/templates/index.html b/puppetboard/templates/index.html index d2a0afa..cc8fc9e 100644 --- a/puppetboard/templates/index.html +++ b/puppetboard/templates/index.html @@ -1,25 +1,31 @@ {% extends 'layout.html' %} {% block row_fluid %}
+
-

{{ unreported|length }} unreported

+

{{ stats['unreported'] }} + {% if stats['unreported']== 1 %} node {% else %} nodes {% endif %} +

- {% if unreported|length == 1 %} node {% else %} nodes {% endif %} - in the last {{ config.UNRESPONSIVE_HOURS }} hours + unreported in the last {{ config.UNRESPONSIVE_HOURS }} hours
@@ -44,34 +50,38 @@
-

Nodes unresponsive in the last {{ config.UNRESPONSIVE_HOURS }} hours

- +

Node Status Detail

+
+ + + + + + + - {% for node in unreported %} + {% for node in nodes %} + {% if node.status != 'unchanged' %} - - - - - - {% endfor %} - -
StatusHostname
No Report{{ node.noresponse }}{{ node.name }}Latest Report
-

Latest reports with events

- - - {% for event in latest_events %} - - - - - + + + + {% endif %} {% endfor %}
- {% if event['failures'] %}{{event['failures']}}{% else %}0{% endif%} - {% if event['successes'] %}{{event['successes']}}{% else %}0{% endif%} + + + {{node.status}} + + {% if node.status=='unreported'%} + {{ node.unreported_time }} + {% else %} + {% if node.events['failures'] %}{{node.events['failures']}}{% else %}0{% endif%} + {% if node.events['successes'] %}{{node.events['successes']}}{% else %}0{% endif%} + {% endif %} {{event['subject']['title']}}Latest Report
{{ node.name }}Latest Report
+
diff --git a/puppetboard/templates/nodes.html b/puppetboard/templates/nodes.html index 626525b..bc3b6af 100644 --- a/puppetboard/templates/nodes.html +++ b/puppetboard/templates/nodes.html @@ -29,10 +29,14 @@ {% for node in nodes %} - {% if node.status['failures'] %}{{node.status['failures']}}{% else %}0{% endif %} - {% if node.status['successes'] %}{{node.status['successes']}}{% else %}0{% endif %} - {% if node.status['noops'] or node.status['skips'] %}{{node.status['skips']+node.status['noops']}}{% else %}0{% endif %} + {{ node.status }} + {% if node.status=='unreported'%} + {{ node.unreported_time }} + {% else %} + {% if node.events['failures'] %}{{node.events['failures']}}{% else %}0{% endif%} + {% if node.events['successes'] %}{{node.events['successes']}}{% else %}0{% endif%} + {% endif %} {{node.name}} {{node.catalog_timestamp}}