Commit 3e330c37e2b6498e0ed5dc3db682265a8177e926
1 parent
fd109cda
rewrote use of map() to list comprehension as use of map() is an anti-pattern as part of the fix.
Showing
1 changed file
with
10 additions
and
12 deletions
plugins/check_otp
... | ... | @@ -359,9 +359,8 @@ def checkotp(url, subject, secret, isserial=False, nas=None): |
359 | 359 | if not isempty(nas): |
360 | 360 | params['nas'] = nas |
361 | 361 | if logger.isEnabledFor(logging.DEBUG): |
362 | - logger.debug('HTTP request parameters: %s', | |
363 | - ', '.join(map(lambda (k,v): '%s="%s"' % (k, v if k!='pass' | |
364 | - else '***MASKED***'), params.iteritems()))) | |
362 | + logger.debug('HTTP request parameters: %s', ', '.join([ '%s=%s' % (k, | |
363 | + v if k!='pass' else '***MASKED***') for k,v in params.iteritems()])) | |
365 | 364 | |
366 | 365 | # Perform the API authentication request |
367 | 366 | response = json.load(urlopen(Request(url, data=urlencode(params)))) |
... | ... | @@ -372,16 +371,15 @@ def checkotp(url, subject, secret, isserial=False, nas=None): |
372 | 371 | |
373 | 372 | |
374 | 373 | def nagios_exit(status, message, data=None): |
375 | - """exit 'nagios-style', print status and message followed by the data""" | |
374 | + """exit 'nagios-style', print status and message followed by perf. data""" | |
376 | 375 | if logger.isEnabledFor(logging.CRITICAL): |
377 | 376 | if data is not None and len(data) > 0: |
378 | - perfdata=map(lambda (k,v): "'%s'=%s" %(k,v if not isinstance(v,list) | |
379 | - else ';'.join(map(lambda x:'' if x is None else str(x),v))) | |
380 | - ,data.iteritems()) | |
381 | - perfstr = ' | ' + ' '.join(perfdata) | |
377 | + perfdata = ' | ' + ' '.join([ "'%s'=%s" % (k, | |
378 | + ';'.join(['' if x is None else str(x) for x in v]) | |
379 | + if isinstance(v,list) else v) for k,v in data ]) | |
382 | 380 | else: |
383 | - perfstr = '' | |
384 | - print 'OTP %s: %s%s' % (status[0], message, perfstr) | |
381 | + perfdata = '' | |
382 | + print 'OTP %s: %s%s' % (status[0], message, perfdata) | |
385 | 383 | sys.exit(status[1]) |
386 | 384 | |
387 | 385 | |
... | ... | @@ -478,5 +476,5 @@ if __name__ == '__main__': |
478 | 476 | if 'message' in detaildata: |
479 | 477 | message += ': ' + detaildata.get('message') |
480 | 478 | |
481 | - nagios_exit(nagiosresult, message, { | |
482 | - 'time': [ elapse, args.warn, args.critical, 0, None]}) | |
479 | + nagios_exit(nagiosresult, message, [ | |
480 | + ('time', [ elapse, args.warn, args.critical, 0, None ])]) | |
... | ... |