From d76966cca80c66fe996c40140a22af13c6530201 Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Fri, 28 Jan 2011 18:48:16 +0100 Subject: [PATCH] check_sensors: Re-add timestamp to regexp, use it in output, accept "degC" as unit Signed-off-by: Sven Velt --- check_sensors.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/check_sensors.py b/check_sensors.py index 2c8d249..608da8b 100755 --- a/check_sensors.py +++ b/check_sensors.py @@ -41,7 +41,7 @@ for idx in xrange(len(plugin.options.sensorid)): plugin.options.sensorid.sort() plugin.verbose(1, 'Sensor id(s): ' + ' - '.join([str(s) for s in plugin.options.sensorid])) -searchpattern = re.compile(r'Sensor:\s*([0-9A-Za-z]+)\s+Raw:\s*(-?[0-9\.]+)?\s+Value:\s*(-?[0-9\.]+)\s+Unit:\s*(\S+)$') +searchpattern = re.compile(r'(\d+)\s+Sensor:\s*([0-9A-Za-z]+)\s+Raw:\s*(-?[0-9\.]+)?\s+Value:\s*(-?[0-9\.]+)\s+Unit:\s*(\S+)\b') for sensorid in plugin.options.sensorid: filename = os.path.join(plugin.options.path, '%s%s' % (plugin.options.basefilename, sensorid)) @@ -54,8 +54,7 @@ for sensorid in plugin.options.sensorid: plugin.verbose(2, 'Read line: %s' % data) plugin.verbose(2, 'Checking age of file') - readtime = os.path.getmtime(filename) - fileage = time.time() - readtime + fileage = time.time() - os.path.getmtime(filename) if fileage > plugin.options.maxage: plugin.add_output('Data of sensor "%s" to old' % sensorid) plugin.add_returncode(3) @@ -66,12 +65,12 @@ for sensorid in plugin.options.sensorid: result = searchpattern.search(data) if result: sensor_type = None - (sid, raw, value, unit) = result.groups() + (readtime, sid, raw, value, unit) = result.groups() readtime = datetime.datetime.fromtimestamp(long(readtime)) readtime = readtime.isoformat(' ') - if unit == '\xc2\xb0C': + if unit in ['degC', '\xc2\xb0C']: sensor_type = 'temp' sensor_name = 'temp_' + str(sensorid) warn = plugin.options.tempwarn