Commit fd109cdada72c9ae3e061a943ed10025720aed7b
1 parent
d5ca8d76
changed way how performance data is handled so that the order is preserved (fixes #1)
rewrote use of map() to list comprehension as use of map() is an anti-pattern as part of the fix. improved the status message when warn or critical thresholds are exceeded
Showing
1 changed file
with
17 additions
and
18 deletions
plugins/check_temperature
... | ... | @@ -168,8 +168,8 @@ def get_sensor_device_filename(args, dev_dir=SENSOR_DEV_DIR, |
168 | 168 | if len(device_folders) == 0: |
169 | 169 | errmsg = 'no supported temperature sensors in %s' % dev_dir |
170 | 170 | else: |
171 | - serials=map(lambda x: basename(x) if x.find(prefix)<0 | |
172 | - else basename(x)[len(prefix):], device_folders) | |
171 | + serials = [ basename(x)[len(prefix):] if x.find(prefix)>=0 | |
172 | + else basename(x) for x in device_folders ] | |
173 | 173 | errmsg = 'found multiple temperature sensors (%s), please '\ |
174 | 174 | 'specify which one to use' % ', '.join(serials) |
175 | 175 | logger.critical(errmsg) |
... | ... | @@ -219,13 +219,12 @@ def nagios_exit(status, message, data=None): |
219 | 219 | """exit 'nagios-style', print status and message followed by perf. data""" |
220 | 220 | if logger.isEnabledFor(logging.CRITICAL): |
221 | 221 | if data is not None and len(data) > 0: |
222 | - perfdata=map(lambda (k,v): "'%s'=%s" %(k,v if not isinstance(v,list) | |
223 | - else ';'.join(map(lambda x:'' if x is None else str(x),v))) | |
224 | - ,data.iteritems()) | |
225 | - perfstr = ' | ' + ' '.join(perfdata) | |
222 | + perfdata = ' | ' + ' '.join([ "'%s'=%s" % (k, | |
223 | + ';'.join(['' if x is None else str(x) for x in v]) | |
224 | + if isinstance(v,list) else v) for k,v in data ]) | |
226 | 225 | else: |
227 | - perfstr = '' | |
228 | - print 'Temperature %s: %s%s' % (status[0], message, perfstr) | |
226 | + perfdata = '' | |
227 | + print 'Temperature %s: %s%s' % (status[0], message, perfdata) | |
229 | 228 | exit(status[1]) |
230 | 229 | |
231 | 230 | |
... | ... | @@ -254,20 +253,20 @@ if __name__ == '__main__': |
254 | 253 | logger.info('Got temperature reading of %.2f degrees %s in %fs', |
255 | 254 | temperature, args.converter[2], elapse) |
256 | 255 | |
257 | - temp_unit = args.converter[1] | |
258 | - message = 'current temperature is %.2f%s' % (temperature, temp_unit) | |
256 | + unit = args.converter[1] | |
257 | + message = 'current temperature is %.2f%s' % (temperature, unit) | |
259 | 258 | if args.critical is not None and temperature > args.critical: |
260 | 259 | nagiosresult = NAGIOS_CRITICAL |
261 | - message += ', above critical threshold %.2f%s'%(args.critical,temp_unit) | |
260 | + message+= ' and exceeds critical threshold %.2f%s' %(args.critical,unit) | |
262 | 261 | elif args.warn is not None and temperature > args.warn: |
263 | 262 | nagiosresult = NAGIOS_WARN |
264 | - message += ', above warning threshold %.2f%s' % (args.warn, temp_unit) | |
263 | + message+= ' and exceeds warning threshold %.2f%s' % (args.warn,unit) | |
265 | 264 | else: |
266 | 265 | nagiosresult = NAGIOS_OK |
267 | 266 | |
268 | - nagios_exit(nagiosresult, message, { | |
269 | - 'temperature': [ '%f%s' % (temperature, temp_unit), | |
270 | - args.warn, args.critical, None, None], | |
271 | - 'retries': [ tries-1, None, args.retries, 0, None ], | |
272 | - 'checktime': [ '%fs' % elapse, None, None, 0, None] | |
273 | - }) | |
267 | + nagios_exit(nagiosresult, message, [ | |
268 | + ('temperature', [ '%f%s' % (temperature, unit), | |
269 | + args.warn, args.critical, None, None]), | |
270 | + ('retries', [ tries-1, None, args.retries, 0, None ]), | |
271 | + ('checktime', [ '%fs' % elapse, None, None, 0, None]) | |
272 | + ]) | |
... | ... |