Add nodes with missing timestamp to unreported nodes

Skip nodes with NoneType timestamps

add nodes with missing timestamp to unreported nodes
This commit is contained in:
Lars Sjöström
2013-10-29 09:34:43 +01:00
committed by Lars Sjöström
parent ee2775512d
commit 61548c819c

View File

@@ -72,12 +72,12 @@ def server_error(e):
@app.route('/') @app.route('/')
def index(): def index():
"""This view generates the index page and displays a set of metrics and latest reports on """This view generates the index page and displays a set of metrics and latest reports on
nodes fetched from PuppetDB. nodes fetched from PuppetDB.
""" """
# TODO: Would be great if we could parallelize this somehow, doing these # TODO: Would be great if we could parallelize this somehow, doing these
# requests in sequence is rather pointless. # requests in sequence is rather pointless.
num_nodes = get_or_abort(puppetdb.metric, num_nodes = get_or_abort(puppetdb.metric,
'com.puppetlabs.puppetdb.query.population:type=default,name=num-nodes') 'com.puppetlabs.puppetdb.query.population:type=default,name=num-nodes')
num_resources = get_or_abort(puppetdb.metric, num_resources = get_or_abort(puppetdb.metric,
'com.puppetlabs.puppetdb.query.population:type=default,name=num-resources') 'com.puppetlabs.puppetdb.query.population:type=default,name=num-resources')
@@ -91,24 +91,27 @@ def index():
latest_event_count = puppetdb._query('aggregate-event-counts', query='["=", "latest-report?", true]', summarize_by='certname') latest_event_count = puppetdb._query('aggregate-event-counts', query='["=", "latest-report?", true]', summarize_by='certname')
latest_event_count['noopskip'] = latest_event_count['noops']+latest_event_count['skips'] latest_event_count['noopskip'] = latest_event_count['noops']+latest_event_count['skips']
latest_events = puppetdb._query('event-counts', query='["=", "latest-report?", true]', summarize_by='certname') latest_events = puppetdb._query('event-counts', query='["=", "latest-report?", true]', summarize_by='certname')
unreported = [] unreported = []
for node in puppetdb.nodes(): for node in puppetdb.nodes():
node_last_seen = node.report_timestamp.replace(tzinfo=None) try:
if node_last_seen < (datetime.utcnow()-timedelta(hours=app.config['UNRESPONSIVE_HOURS'])): node_last_seen = node.report_timestamp.replace(tzinfo=None)
delta = (datetime.utcnow()-node_last_seen) if node_last_seen < (datetime.utcnow()-timedelta(hours=app.config['UNRESPONSIVE_HOURS'])):
node.noresponse = str(delta.days) + "d " + str(int(delta.seconds/3600)) +"h " + str(int((delta.seconds%3600)/60))+ "m" delta = (datetime.utcnow()-node_last_seen)
node.noresponse = str(delta.days) + "d " + str(int(delta.seconds/3600)) +"h " + str(int((delta.seconds%3600)/60))+ "m"
unreported.append(node)
except AttributeError:
unreported.append(node) unreported.append(node)
return render_template('index.html', metrics=metrics, latest_event_count=latest_event_count, latest_events=latest_events, unreported=unreported) return render_template('index.html', metrics=metrics, latest_event_count=latest_event_count, latest_events=latest_events, unreported=unreported)
@app.route('/nodes') @app.route('/nodes')
def nodes(): def nodes():
"""Fetch all (active) nodes from PuppetDB and stream a table displaying """Fetch all (active) nodes from PuppetDB and stream a table displaying
those nodes. those nodes.
Downside of the streaming aproach is that since we've already sent our Downside of the streaming aproach is that since we've already sent our
headers we can't abort the request if we detect an error. Because of this headers we can't abort the request if we detect an error. Because of this
we'll end up with an empty table instead because of how yield_or_stop we'll end up with an empty table instead because of how yield_or_stop