From 5124802c9cd8c5df609142b9c78d95cf48f1e9ed Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 24 Mar 2015 10:23:18 -0400 Subject: [PATCH] Change nodesensors output Be more sparing with 'ok' and '()' in output. Many of the sensors have no particular meaning if they are 'ok'. For a sensor witohut a value, the states are no longer surrounded by () to reflect that they are more first class rather than describing a primary value. --- confluent_client/bin/nodesensors | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/confluent_client/bin/nodesensors b/confluent_client/bin/nodesensors index 6a38c09c..377d0d89 100644 --- a/confluent_client/bin/nodesensors +++ b/confluent_client/bin/nodesensors @@ -98,7 +98,7 @@ def sensorpass(showout=True, appendtime=False): if 'sensors' not in reading[node]: continue for sensedata in reading[node]['sensors']: - for redundant_state in ('Ok', 'Non-Critical', 'Critical'): + for redundant_state in ('Non-Critical', 'Critical'): try: sensedata['states'].remove(redundant_state) except ValueError: @@ -116,9 +116,18 @@ def sensorpass(showout=True, appendtime=False): showval = u' {0} '.format(sensedata['value']) if sensedata['units'] not in (None, u''): showval += sensedata['units'] - datadescription = [sensedata['health']] + if sensedata['health'] != 'ok': + datadescription = [sensedata['health']] + else: + datadescription = [] datadescription.extend(sensedata['states']) - showval += u' ({0})'.format(','.join(datadescription)) + if datadescription: + if showval == '': + showval += u' {0}'.format( + ','.join(datadescription)) + else: + showval += u' ({0})'.format( + ','.join(datadescription)) if appendtime: showval += ' @' + time.strftime( '%Y-%m-%dT%H:%M:%S') @@ -137,10 +146,17 @@ def format_csv(csvwriter, orderedsensors, resdata, showtime=True): try: datum = resdata[nodekey][sensorkey]['value'] if datum is None: - datum = resdata[nodekey][sensorkey]['health'] + if resdata[nodekey][sensorkey]['health'] != 'ok': + datum = resdata[nodekey][sensorkey]['health'] + else: + datum = '' if resdata[nodekey][sensorkey]['states']: - datum += ',' + ','.join( + healthstates = ','.join( resdata[nodekey][sensorkey]['states']) + if datum != '': + datum = ','.join([datum, healthstates]) + else: + datum = healthstates rowdata.append(datum) except KeyError: rowdata.append('N/A')