diff --git a/puppetboard/app.py b/puppetboard/app.py index c25b78d..048e8ff 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 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') @@ -149,27 +144,13 @@ def nodes(): provide a search feature instead. """ status_arg = request.args.get('status', '') - latest_events = puppetdb._query( - 'event-counts', - query='["=", "latest-report?", true]', - summarize_by='certname') nodes = [] - for node in yield_or_stop(puppetdb.nodes()): - # check if node name is contained in any of the - # event-counts (grouped by certname) - status = [ - s for s in latest_events if - s['subject']['title'] == node.name] - if status: - node.status = status[0] - else: - node.status = {} + for node in yield_or_stop(puppetdb.nodes(with_status=True)): if status_arg: - if node.status.has_key(status_arg) and node.status[status_arg]: + if node.status == status_arg: nodes.append(node) else: nodes.append(node) - return Response(stream_with_context( stream_template('nodes.html', nodes=nodes))) diff --git a/puppetboard/static/coffeescript/tables.coffee b/puppetboard/static/coffeescript/tables.coffee index 137f11e..9b47f45 100644 --- a/puppetboard/static/coffeescript/tables.coffee +++ b/puppetboard/static/coffeescript/tables.coffee @@ -2,15 +2,22 @@ $ = jQuery $ -> $('.nodes').tablesorter( headers: - 3: + 4: sorter: false - sortList: [[0,0]] + sortList: [[1,0]] ) $('.facts').tablesorter( sortList: [[0,0]] ) +$('.dashboard').tablesorter( + headers: + 2: + sorter: false + sortList: [[0, 1]] +) + $('input.filter-table').parent('div').removeClass('hide') $("input.filter-table").on "keyup", (e) -> rex = new RegExp($(this).val(), "i") 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..ccac257 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, 1]] + }); + $('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..06f6570 100644 --- a/puppetboard/templates/index.html +++ b/puppetboard/templates/index.html @@ -1,25 +1,33 @@ {% 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 +52,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}}