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
This commit is contained in:
Julius Härtl
2013-11-05 10:07:53 +01:00
parent a84da91f06
commit f187638b6e
5 changed files with 96 additions and 63 deletions

View File

@@ -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)))