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:
|
||||
filename = os.path.join(plugin.options.path, '%s%s' % (plugin.options.basefilename, sensorid))
|
||||
try:
|
||||
plugin.verbose(3, 'Reading sensor %s' % sensorid)
|
||||
data = file(filename).read().lstrip().rstrip()
|
||||
plugin.verbose(2, 'Reading sensor %s' % sensorid)
|
||||
data = file(filename).readlines()
|
||||
except IOError:
|
||||
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')
|
||||
fileage = time.time() - os.path.getmtime(filename)
|
||||
|
@ -60,7 +63,10 @@ for sensorid in plugin.options.sensorid:
|
|||
else:
|
||||
plugin.verbose(2, 'File age OK, age: %s and %s seconds are allowed'% (long(fileage), plugin.options.maxage))
|
||||
|
||||
result = searchpattern.search(data)
|
||||
valuesinfile = 0
|
||||
|
||||
for line in data:
|
||||
result = searchpattern.search(line)
|
||||
if result:
|
||||
sensor_type = None
|
||||
(readtime, sid, raw, value, unit) = result.groups()
|
||||
|
@ -83,6 +89,7 @@ for sensorid in plugin.options.sensorid:
|
|||
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))
|
||||
|
@ -93,7 +100,8 @@ for sensorid in plugin.options.sensorid:
|
|||
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:
|
||||
|
||||
if valuesinfile == 0:
|
||||
plugin.verbose(2, 'No data found for sensor %s' % sensorid)
|
||||
|
||||
plugin.exit()
|
||||
|
|
Loading…
Reference in a new issue