From 844df480339f9479dd18fb87ed784ae0e72834c1 Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Fri, 28 Jan 2011 18:24:14 +0100 Subject: [PATCH] check_tl500: Change regexp and use file mtime instead of content Signed-off-by: Sven Velt --- check_tl500.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/check_tl500.py b/check_tl500.py index 4b80363..915dd26 100755 --- a/check_tl500.py +++ b/check_tl500.py @@ -3,6 +3,7 @@ from monitoringplugin import MonitoringPlugin +import datetime import time import os import re @@ -39,7 +40,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'(....-..-.. ..:..:..)\s+Sensor:\s*([0-9]+)\s+Raw:\s*(-?[0-9]+)\s+Value:\s*(-?[0-9\.]+)\s+Unit:\s*(...?)$') +searchpattern = re.compile(r'Sensor:\s*([0-9A-Za-z]+)\s+Raw:\s*(-?[0-9\.]+)?\s+Value:\s*(-?[0-9\.]+)\s+Unit:\s*(\S+)$') for sensorid in plugin.options.sensorid: filename = os.path.join(plugin.options.path, 'tl-500_%s' % sensorid) @@ -52,7 +53,8 @@ for sensorid in plugin.options.sensorid: plugin.verbose(2, 'Read line: %s' % data) plugin.verbose(2, 'Checking age of file') - fileage = time.time() - os.path.getmtime(filename) + readtime = os.path.getmtime(filename) + fileage = time.time() - readtime if fileage > plugin.options.maxage: plugin.add_output('Data of sensor "%s" to old' % sensorid) plugin.add_returncode(3) @@ -63,7 +65,10 @@ for sensorid in plugin.options.sensorid: result = searchpattern.search(data) if result: sensor_type = None - (readtime, sid, raw, value, unit) = result.groups() + (sid, raw, value, unit) = result.groups() + + readtime = datetime.datetime.fromtimestamp(long(readtime)) + readtime = readtime.isoformat(' ') if unit == '\xc2\xb0C': sensor_type = 'temp'