check_sensors: Add support for multiple data lines per file
Signed-off-by: Sven Velt <sven@velt.de>
This commit is contained in:
parent
ff3b795663
commit
bc11e7f665
|
@ -44,12 +44,15 @@ searchpattern = re.compile(r'(\d+)\s+Sensor:\s*([0-9A-Za-z]+)\s+Raw:\s*(-?[0-9\.
|
||||||
for sensorid in plugin.options.sensorid:
|
for sensorid in plugin.options.sensorid:
|
||||||
filename = os.path.join(plugin.options.path, '%s%s' % (plugin.options.basefilename, sensorid))
|
filename = os.path.join(plugin.options.path, '%s%s' % (plugin.options.basefilename, sensorid))
|
||||||
try:
|
try:
|
||||||
plugin.verbose(3, 'Reading sensor %s' % sensorid)
|
plugin.verbose(2, 'Reading sensor %s' % sensorid)
|
||||||
data = file(filename).read().lstrip().rstrip()
|
data = file(filename).readlines()
|
||||||
except IOError:
|
except IOError:
|
||||||
plugin.back2nagios(3, 'Could not read file "%s"' % filename)
|
plugin.back2nagios(3, 'Could not read file "%s"' % filename)
|
||||||
|
|
||||||
plugin.verbose(2, 'Read line: %s' % data)
|
if plugin.options.verbose >= 3:
|
||||||
|
plugin.verbose(3, 'Read line(s):' % data)
|
||||||
|
for line in data:
|
||||||
|
plugin.verbose(3, '--> ' + line.lstrip().rstrip())
|
||||||
|
|
||||||
plugin.verbose(2, 'Checking age of file')
|
plugin.verbose(2, 'Checking age of file')
|
||||||
fileage = time.time() - os.path.getmtime(filename)
|
fileage = time.time() - os.path.getmtime(filename)
|
||||||
|
@ -60,40 +63,45 @@ for sensorid in plugin.options.sensorid:
|
||||||
else:
|
else:
|
||||||
plugin.verbose(2, 'File age OK, age: %s and %s seconds are allowed'% (long(fileage), plugin.options.maxage))
|
plugin.verbose(2, 'File age OK, age: %s and %s seconds are allowed'% (long(fileage), plugin.options.maxage))
|
||||||
|
|
||||||
result = searchpattern.search(data)
|
valuesinfile = 0
|
||||||
if result:
|
|
||||||
sensor_type = None
|
|
||||||
(readtime, sid, raw, value, unit) = result.groups()
|
|
||||||
|
|
||||||
readtime = datetime.datetime.fromtimestamp(long(readtime))
|
for line in data:
|
||||||
readtime = readtime.isoformat(' ')
|
result = searchpattern.search(line)
|
||||||
|
if result:
|
||||||
if unit in ['degC', '\xc2\xb0C']:
|
sensor_type = None
|
||||||
sensor_type = 'temp'
|
(readtime, sid, raw, value, unit) = result.groups()
|
||||||
sensor_name = 'temp_' + str(sensorid)
|
|
||||||
warn = plugin.options.tempwarn
|
readtime = datetime.datetime.fromtimestamp(long(readtime))
|
||||||
crit = plugin.options.tempcrit
|
readtime = readtime.isoformat(' ')
|
||||||
unit = 'C'
|
|
||||||
pdunit = ''
|
if unit in ['degC', '\xc2\xb0C']:
|
||||||
elif unit == '%RH':
|
sensor_type = 'temp'
|
||||||
sensor_type = 'hum'
|
sensor_name = 'temp_' + str(sensorid)
|
||||||
sensor_name = 'hum_' + str(sensorid)
|
warn = plugin.options.tempwarn
|
||||||
warn = plugin.options.humwarn
|
crit = plugin.options.tempcrit
|
||||||
crit = plugin.options.humcrit
|
unit = 'C'
|
||||||
pdunit = '%'
|
pdunit = ''
|
||||||
|
elif unit == '%RH':
|
||||||
if sensor_type:
|
sensor_type = 'hum'
|
||||||
returncode = plugin.value_wc_to_returncode(float(value), warn, crit)
|
sensor_name = 'hum_' + str(sensorid)
|
||||||
if returncode == 0:
|
warn = plugin.options.humwarn
|
||||||
plugin.add_output('%s: %s%s' % (sensor_name, value, unit))
|
crit = plugin.options.humcrit
|
||||||
|
pdunit = '%'
|
||||||
|
|
||||||
|
if sensor_type:
|
||||||
|
valuesinfile += 1
|
||||||
|
returncode = plugin.value_wc_to_returncode(float(value), warn, crit)
|
||||||
|
if returncode == 0:
|
||||||
|
plugin.add_output('%s: %s%s' % (sensor_name, value, unit))
|
||||||
|
else:
|
||||||
|
plugin.add_output('%s: %s %s%s' % (sensor_name, plugin.RETURNSTRINGS[returncode], value, unit))
|
||||||
|
plugin.add_returncode(returncode)
|
||||||
|
plugin.add_multilineoutput('%s %s: %s%s (%s)' % (sensor_name, plugin.RETURNSTRINGS[returncode], value, unit, readtime))
|
||||||
|
plugin.format_add_performancedata(sensor_name, value, pdunit, warn=warn, crit=crit)
|
||||||
else:
|
else:
|
||||||
plugin.add_output('%s: %s %s%s' % (sensor_name, plugin.RETURNSTRINGS[returncode], value, unit))
|
plugin.verbose(1, 'Unknown sensor type "%s" on %s' % (unit, sensorid))
|
||||||
plugin.add_returncode(returncode)
|
|
||||||
plugin.add_multilineoutput('%s %s: %s%s (%s)' % (sensor_name, plugin.RETURNSTRINGS[returncode], value, unit, readtime))
|
if valuesinfile == 0:
|
||||||
plugin.format_add_performancedata(sensor_name, value, pdunit, warn=warn, crit=crit)
|
|
||||||
else:
|
|
||||||
plugin.verbose(1, 'Unknown sensor type "%s" on %s' % (unit, sensorid))
|
|
||||||
else:
|
|
||||||
plugin.verbose(2, 'No data found for sensor %s' % sensorid)
|
plugin.verbose(2, 'No data found for sensor %s' % sensorid)
|
||||||
|
|
||||||
plugin.exit()
|
plugin.exit()
|
||||||
|
|
Loading…
Reference in a new issue