From 6a4642e9f5e99e3c112bd28a2a22b0541b9b6710 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 23 Mar 2015 13:49:59 -0400 Subject: [PATCH] Functional pass of nodesensors command nodesensors is not roughly at par with rvitals. This means more complete handling and recognizing some of the rvitals shortcuts as well as some mistakes in the draft. Still lacking are interval/repeat queries. --- confluent_client/bin/nodesensors | 40 +++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/confluent_client/bin/nodesensors b/confluent_client/bin/nodesensors index 31999255..dc378f94 100644 --- a/confluent_client/bin/nodesensors +++ b/confluent_client/bin/nodesensors @@ -27,10 +27,12 @@ if path.startswith('/opt'): import confluent.client as client sensorcollections = { - 'all': 'hardware/all/all', - 'temperature': 'hardware/temperature/all', - 'power': 'hardware/power/all', - 'fans': 'hardware/fans/all' + 'all': 'sensors/hardware/all/all', + 'temperature': 'sensors/hardware/temperature/all', + 'temp': 'sensors/hardware/temperature/all', + 'power': 'sensors/hardware/power/all', + 'fans': 'sensors/hardware/fans/all', + 'fanspeed': 'sensors/hardware/fans/all', } @@ -52,14 +54,14 @@ if options.numreadings: noderange = args[0] sensors = [] -for sensorgroup in args[2:]: +for sensorgroup in args[1:]: for sensor in sensorgroup.split(','): - sensor.replace('.', '/') + sensor = sensor.replace('.', '/').replace(' ', '_').lower() if '/' not in sensor: if sensor in sensorcollections: sensors.append(sensorcollections[sensor]) else: - sensors.append('hardware/all/' + sensor) + sensors.append('sensors/hardware/all/' + sensor) if not sensors: sensors = ['sensors/hardware/all/all'] @@ -68,30 +70,36 @@ exitcode = 0 sensornames = set([]) def sensorpass(showout=True): + global exitcode resultdata = {} for reqsensor in sensors: for reading in session.read('/noderange/' + noderange + '/' + reqsensor): - if not isinstance(reading, dict): - sys.stderr.write(reading) + if 'error' in reading: + sys.stderr.write('Error: {0}\n'.format(reading['error'])) + if 'errorcode' in reading: + exitcode |= exitcode + else: + exitcode |= 1 + if 'databynode' not in reading: continue + reading = reading['databynode'] for node in reading: if 'error' in reading[node]: sys.stderr.write( - '{0}: Error: {1}\n'.format(reading[node]['error'])) + '{0}: Error: {1}\n'.format(node, + reading[node]['error'])) if 'sensors' not in reading[node]: continue for sensedata in reading[node]['sensors']: - print repr(sensedata) sensornames.add(sensedata['name']) - try: - sensedata['state'].remove('Ok') + sensedata['states'].remove('Ok') except ValueError: pass resultdata[sensedata['name']] = sensedata if showout: if sensedata['units'] is not None: - showval = '{0} {1}'.format( + showval = u'{0} {1}'.format( sensedata['value'], sensedata['units']) else: showval = sensedata['value'] @@ -100,8 +108,8 @@ def sensorpass(showout=True): datadescription = [sensedata['health']] datadescription.extend(sensedata['states']) showval += ' ({0})'.format(','.join(datadescription)) - print('{0}: {1}: {2}'.format( - node, sensedata['name'], showval)) + print(u'{0}: {1}: {2}'.format( + node, sensedata['name'], showval).encode('utf-8'))