check_tl500: Change regexp and use file mtime instead of content
Signed-off-by: Sven Velt <sven@velt.de>
This commit is contained in:
parent
de35c63ad8
commit
844df48033
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from monitoringplugin import MonitoringPlugin
|
from monitoringplugin import MonitoringPlugin
|
||||||
|
|
||||||
|
import datetime
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -39,7 +40,7 @@ for idx in xrange(len(plugin.options.sensorid)):
|
||||||
plugin.options.sensorid.sort()
|
plugin.options.sensorid.sort()
|
||||||
plugin.verbose(1, 'Sensor id(s): ' + ' - '.join([str(s) for s in plugin.options.sensorid]))
|
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:
|
for sensorid in plugin.options.sensorid:
|
||||||
filename = os.path.join(plugin.options.path, 'tl-500_%s' % 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, 'Read line: %s' % data)
|
||||||
|
|
||||||
plugin.verbose(2, 'Checking age of file')
|
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:
|
if fileage > plugin.options.maxage:
|
||||||
plugin.add_output('Data of sensor "%s" to old' % sensorid)
|
plugin.add_output('Data of sensor "%s" to old' % sensorid)
|
||||||
plugin.add_returncode(3)
|
plugin.add_returncode(3)
|
||||||
|
@ -63,7 +65,10 @@ for sensorid in plugin.options.sensorid:
|
||||||
result = searchpattern.search(data)
|
result = searchpattern.search(data)
|
||||||
if result:
|
if result:
|
||||||
sensor_type = None
|
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':
|
if unit == '\xc2\xb0C':
|
||||||
sensor_type = 'temp'
|
sensor_type = 'temp'
|
||||||
|
|
Loading…
Reference in a new issue