mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-22 09:32:21 +00:00
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.
This commit is contained in:
parent
4beef5bb25
commit
6a4642e9f5
@ -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'))
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user