From 3e330c37e2b6498e0ed5dc3db682265a8177e926 Mon Sep 17 00:00:00 2001 From: Frederik Lindenaar <frederik@lindenaar.nl> Date: Tue, 18 Oct 2016 01:59:46 +0200 Subject: [PATCH] rewrote use of map() to list comprehension as use of map() is an anti-pattern as part of the fix. --- plugins/check_otp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/check_otp b/plugins/check_otp index 2678b11..a617c88 100755 --- a/plugins/check_otp +++ b/plugins/check_otp @@ -359,9 +359,8 @@ def checkotp(url, subject, secret, isserial=False, nas=None): if not isempty(nas): params['nas'] = nas if logger.isEnabledFor(logging.DEBUG): - logger.debug('HTTP request parameters: %s', - ', '.join(map(lambda (k,v): '%s="%s"' % (k, v if k!='pass' - else '***MASKED***'), params.iteritems()))) + logger.debug('HTTP request parameters: %s', ', '.join([ '%s=%s' % (k, + v if k!='pass' else '***MASKED***') for k,v in params.iteritems()])) # Perform the API authentication request response = json.load(urlopen(Request(url, data=urlencode(params)))) @@ -372,16 +371,15 @@ def checkotp(url, subject, secret, isserial=False, nas=None): def nagios_exit(status, message, data=None): - """exit 'nagios-style', print status and message followed by the data""" + """exit 'nagios-style', print status and message followed by perf. data""" if logger.isEnabledFor(logging.CRITICAL): if data is not None and len(data) > 0: - perfdata=map(lambda (k,v): "'%s'=%s" %(k,v if not isinstance(v,list) - else ';'.join(map(lambda x:'' if x is None else str(x),v))) - ,data.iteritems()) - perfstr = ' | ' + ' '.join(perfdata) + perfdata = ' | ' + ' '.join([ "'%s'=%s" % (k, + ';'.join(['' if x is None else str(x) for x in v]) + if isinstance(v,list) else v) for k,v in data ]) else: - perfstr = '' - print 'OTP %s: %s%s' % (status[0], message, perfstr) + perfdata = '' + print 'OTP %s: %s%s' % (status[0], message, perfdata) sys.exit(status[1]) @@ -478,5 +476,5 @@ if __name__ == '__main__': if 'message' in detaildata: message += ': ' + detaildata.get('message') - nagios_exit(nagiosresult, message, { - 'time': [ elapse, args.warn, args.critical, 0, None]}) + nagios_exit(nagiosresult, message, [ + ('time', [ elapse, args.warn, args.critical, 0, None ])]) -- libgit2 0.22.2