Skip to content
Permalink
Browse files

futurize fix_except

Change-Id: I5f55563b95e45c1c5422af4bfdce40f12e4e45f6
  • Loading branch information
si-23 committed Jun 27, 2019
1 parent fcc7a8d commit 1ee8286dc3d2b3172e9cb8b580fc1d9ea7b1be4f
Showing with 139 additions and 139 deletions.
  1. +4 −4 active_checks/check_bi_aggr
  2. +3 −3 active_checks/check_cpu_peaks
  3. +6 −6 active_checks/check_form_submit
  4. +7 −7 active_checks/check_mail
  5. +6 −6 active_checks/check_mail_loop
  6. +1 −1 active_checks/check_mailboxes
  7. +1 −1 active_checks/check_notify_count
  8. +1 −1 active_checks/check_sftp
  9. +1 −1 active_checks/check_traceroute
  10. +1 −1 agents/plugins/mk_inotify
  11. +4 −4 agents/plugins/mk_sap
  12. +1 −1 agents/plugins/mtr
  13. +3 −3 agents/plugins/nginx_status
  14. +2 −2 agents/plugins/plesk_backups
  15. +1 −1 agents/plugins/plesk_domains
  16. +1 −1 agents/special/agent_3par
  17. +3 −3 agents/special/agent_activemq
  18. +1 −1 agents/special/agent_emcvnx
  19. +1 −1 agents/special/agent_hivemanager
  20. +2 −2 agents/special/agent_hivemanager_ng
  21. +2 −2 agents/special/agent_hp_msa
  22. +1 −1 agents/special/agent_ibmsvc
  23. +3 −3 agents/special/agent_netapp
  24. +1 −1 agents/special/agent_vsphere.pysphere
  25. +1 −1 agents/windows/msibuild/msi-update
  26. +1 −1 agents/windows/msibuild/msi-update-legacy
  27. +3 −3 bin/check_mk
  28. +2 −2 bin/livedump
  29. +18 −18 bin/mkbackup
  30. +17 −17 bin/mkbench
  31. +1 −1 doc/helpers/fix_newlines_before_def
  32. +3 −3 doc/helpers/guitest
  33. +3 −3 doc/helpers/validate_checks
  34. +2 −2 doc/treasures/Event_Console/get_event_status
  35. +6 −6 doc/treasures/Event_Console/nsca2mkeventd/nsca2mkeventd
  36. +2 −2 doc/treasures/check_cluster_nodes
  37. +1 −1 doc/treasures/check_flapping/check_flapping
  38. +1 −1 doc/treasures/check_imap_folder
  39. +1 −1 doc/treasures/deprecated/agents/plugins/j4p_performance
  40. +3 −3 doc/treasures/downtime
  41. +1 −1 doc/treasures/livedump/livedump-mail-fetch
  42. +2 −2 doc/treasures/multisite_to_mrpe
  43. +1 −1 doc/treasures/notifications/braintower
  44. +1 −1 doc/treasures/notifications/mobilant
  45. +1 −1 doc/treasures/notifications/multitech
  46. +1 −1 doc/treasures/notifications/opcmsg
  47. +5 −5 omd/packages/maintenance/diskspace
  48. +5 −5 web/app/index.wsgi
@@ -85,7 +85,7 @@ long_options = ["help", "in-downtime=", "acknowledged=", "use-automation-user"]

try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
except getopt.GetoptError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)

@@ -209,10 +209,10 @@ try:
except requests.Timeout:
sys.stdout.write('ERROR: Socket timeout while opening URL: %s\n' % (url))
sys.exit(3)
except requests.URLRequired, e:
except requests.URLRequired as e:
sys.stdout.write("UNKNOWN: %s\n" % e)
sys.exit(3)
except Exception, e:
except Exception as e:
sys.stdout.write(
'ERROR: Exception while opening URL: %s - %s\n%s' % (url, e, traceback.format_exc()))
sys.exit(3)
@@ -223,7 +223,7 @@ if raw_response.startswith("ERROR:"):

try:
obj = ast.literal_eval(raw_response)
except Exception, e:
except Exception as e:
sys.stdout.write('ERROR: Invalid response (%s): %s\n' % (e, raw_response))
sys.exit(3)

@@ -106,7 +106,7 @@ try:
step_secs = data[0]
#util_total = [ x for x in datasets[0] if x is not None ]
util_total = [x for x in datasets[0]]
except Exception, e:
except Exception as e:
if opt_debug:
raise
# looks like this is not a windows rrd...
@@ -161,13 +161,13 @@ try:
sys.stdout.write("%s\n" % ": ".join(info))
sys.exit(state)

except MKGeneralException, e:
except MKGeneralException as e:
if opt_debug:
raise
sys.stdout.write("OK - %s\n" % e)
sys.exit(0)

except Exception, e:
except Exception as e:
if opt_debug:
raise
# TODO: Exception handling could be improved.
@@ -142,11 +142,11 @@ def open_url(client, url, method='GET', data=None, timeout=None):
else:
debug('GET %s' % url)
fd = client.open(url, timeout=timeout) # GET
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
new_state(2, 'Unable to open %s: [%d] %s' % (url, e.code, e))
except urllib2.URLError, e:
except urllib2.URLError as e:
new_state(2, 'Unable to open %s: %s' % (url, e.reason))
except socket.timeout, e:
except socket.timeout as e:
new_state(2, 'Unable to open %s: %s' % (url, e))
real_url = fd.geturl()
code = fd.getcode()
@@ -244,7 +244,7 @@ def main():

try:
opts = getopt.getopt(sys.argv[1:], short_options, long_options)[0]
except getopt.GetoptError, err:
except getopt.GetoptError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)

@@ -337,7 +337,7 @@ def main():
expect_regex)
else:
new_state(0, 'Form has been submitted')
except HostResult, e:
except HostResult as e:
if not multiple:
bail_out(*e.result)
states[host] = e.result
@@ -363,7 +363,7 @@ def main():
txt += ' (%s)' % ', '.join(['%s: %s' % (n, msg[1]) for n, msg in failed])
bail_out(sum_state, txt)

except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(3, 'Exception occured: %s\n' % e)
@@ -141,7 +141,7 @@ required_params = [

try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
except getopt.GetoptError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)

@@ -232,7 +232,7 @@ def connect():
g_M = fetch_class(fetch_server, fetch_port)
g_M.login(fetch_user, fetch_pass)
g_M.select('INBOX', readonly=False) # select INBOX
except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(3, 'Failed connect to %s:%d: %s' % (fetch_server, fetch_port, parse_exception(e)))
@@ -255,7 +255,7 @@ def fetch_mails():
try:
data = g_M.fetch(num, '(RFC822)')[1]
mails[num] = email.message_from_string(data[0][1])
except Exception, e:
except Exception as e:
raise Exception('Failed to fetch mail %s (%s). Available messages: %r' %
(num, parse_exception(e), messages))

@@ -267,7 +267,7 @@ def fetch_mails():
del mails[index]

return mails
except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(3, 'Failed to check for mails: %s' % parse_exception(e))
@@ -309,7 +309,7 @@ def cleanup_mailbox():

if fetch_proto == 'IMAP':
g_M.expunge()
except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(2, 'Failed to delete mail: %s' % parse_exception(e))
@@ -431,7 +431,7 @@ def forward_to_ec(mails):

bail_out(0, 'Forwarded %d messages to event console' % len(messages),
[('messages', len(messages))])
except Exception, e:
except Exception as e:
bail_out(
3, 'Unable to forward messages to event console (%s). Left %d messages untouched.' %
(e, len(messages)))
@@ -456,7 +456,7 @@ socket.setdefaulttimeout(conn_timeout)

try:
main()
except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(2, 'Unhandled exception: %s' % parse_exception(e))
@@ -151,7 +151,7 @@ required_params = [

try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
except getopt.GetoptError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)

@@ -337,7 +337,7 @@ def fetch_mails():
try:
data = g_M.fetch(num, '(RFC822)')[1]
mails[num] = email.message_from_string(data[0][1])
except Exception, e:
except Exception as e:
raise Exception('Failed to fetch mail %s (%s). Available messages: %r' %
(num, parse_exception(e), messages))

@@ -365,7 +365,7 @@ def fetch_mails():

g_mails[ts + '-' + key] = (index, rx_ts)

except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(3, 'Failed to check for mails: %s' % parse_exception(e))
@@ -391,7 +391,7 @@ def send_mail():
S.quit()

add_expected_msg(now, key)
except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(3, 'Failed to send mail: %s' % parse_exception(e))
@@ -477,7 +477,7 @@ def cleanup_mailbox():

if fetch_proto == 'IMAP':
g_M.expunge()
except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(2, 'Failed to delete mail: %s' % parse_exception(e))
@@ -521,7 +521,7 @@ def main():

try:
main()
except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(2, 'Unhandled exception: %s' % parse_exception(e))
@@ -322,7 +322,7 @@ if __name__ == "__main__":
opts = parse_args()
try:
main(opts)
except Exception, e:
except Exception as e:
output("An exception occured (Run in debug mode for details): %s" % e)
if opts.debug:
output(traceback.format_exc())
@@ -57,7 +57,7 @@ short_options = 'hr:w:c:l:'

try:
opts, args = getopt.getopt(sys.argv[1:], short_options)
except getopt.GetoptError, err:
except getopt.GetoptError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)

@@ -88,7 +88,7 @@ long_options = [

try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
except getopt.GetoptError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)

@@ -190,7 +190,7 @@ try:
sys.stdout.write(output.strip() + "\n" + long_output)
sys.exit(status)

except Exception, e:
except Exception as e:
if opt_debug:
raise
bail_out(e)
@@ -134,7 +134,7 @@ if not opt_foreground:
os.close(fd)
except OSError:
pass
except Exception, e:
except Exception as e:
sys.stderr.write("Error forking mk_inotify: %s" % e)

# Save pid of working process.
@@ -51,7 +51,7 @@ import datetime
# already loaded.
try:
import sapnwrfc
except ImportError, e:
except ImportError as e:
if 'sapnwrfc.so' in str(e):
sys.stderr.write(
'Unable to find the library sapnwrfc.so. Maybe you need to put a file pointing to\n'
@@ -494,12 +494,12 @@ try:
try:
check(entry)
sys.stdout.write('<<<sap_state:sep(9)>>>\n%s\tOK\n' % entry['ashost'])
except sapnwrfc.RFCCommunicationError, e:
except sapnwrfc.RFCCommunicationError as e:
sys.stderr.write('ERROR: Unable to connect (%s)\n' % e)
sys.stdout.write('<<<sap_state:sep(9)>>>\n%s\tUnable to connect (%s)\n' %\
(entry['ashost'], e))
processed_all = False
except Exception, e:
except Exception as e:
sys.stderr.write('ERROR: Unhandled exception (%s)\n' % e)
sys.stdout.write('<<<sap_state:sep(9)>>>\n%s\tUnhandled exception (%s)\n' %\
(entry['ashost'], e))
@@ -523,7 +523,7 @@ try:
os.close(state_fd)
os.rename(STATE_FILE + '.new', STATE_FILE)

except Exception, e:
except Exception as e:
sys.stderr.write('ERROR: Unhandled exception (%s)\n' % e)

sys.exit(0)
@@ -282,7 +282,7 @@ def parse_report(host):
'wrst': parts[7],
'stddev': parts[8],
}
except Exception, e:
except Exception as e:
sys.stdout.write("**ERROR** Could not parse report file %s, "
"tossing away invalid data %s\n" % (reportfile, e))
del status[host]
@@ -130,7 +130,7 @@ for server in servers:
try:
request = urllib2.Request(url, headers={"Accept": "text/plain"})
fd = urllib2.urlopen(request)
except urllib2.URLError, e:
except urllib2.URLError as e:
if 'SSL23_GET_SERVER_HELLO:unknown protocol' in str(e):
# HACK: workaround misconfigurations where port 443 is used for
# serving non ssl secured http
@@ -146,8 +146,8 @@ for server in servers:
# seems to be html output. Skip this server.
break
sys.stdout.write("%s %s %s\n" % (address, port, line))
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
sys.stderr.write('HTTP-Error (%s:%d): %s %s\n' % (address, port, e.code, e))

except Exception, e:
except Exception as e:
sys.stderr.write('Exception (%s:%d): %s\n' % (address, port, e))
@@ -50,7 +50,7 @@ def connect():
passwd=file('/etc/psa/.psa.shadow').read().strip(),
charset='utf8',
)
except MySQLdb.Error, e:
except MySQLdb.Error as e:
sys.stderr.write("MySQL-Error %d: %s\n" % (e.args[0], e.args[1]))
sys.exit(1)

@@ -149,7 +149,7 @@ for domain, p in domains.iteritems():
output.append(
'%s 0 %s %d %d' % (domain, last_backup[1].strftime('%s'), last_backup[2], total_size))

except Exception, e:
except Exception as e:
output.append('%s 2 %s' % (domain, e))

# Write cache and output
@@ -40,7 +40,7 @@ try:
passwd=file('/etc/psa/.psa.shadow').read().strip(),
charset='utf8',
)
except MySQLdb.Error, e: # pylint: disable=no-member
except MySQLdb.Error as e: # pylint: disable=no-member
sys.stderr.write("MySQL-Error %d: %s\n" % (e.args[0], e.args[1]))
sys.exit(1)

@@ -81,7 +81,7 @@ long_options = ["help", "user=", "password=", "values=", "verify-certs="]

try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
except getopt.GetoptError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)

@@ -42,7 +42,7 @@ long_options = ["piggyback", "servername=", "port=", "username=", "password="]

try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
except getopt.GetoptError as err:
usage()
sys.stderr.write("%s\n" % err)
sys.exit(1)
@@ -83,7 +83,7 @@ try:

xml = response.text
data = ET.fromstring(xml)
except Exception, e:
except Exception as e:
sys.stderr.write("Unable to connect. Credentials might be incorrect: %s\n" % e)
sys.exit(1)

@@ -117,7 +117,7 @@ try:
add_output("<<<<>>>>")
add_output("<<<local>>>")
add_output("0 Active_MQ - Found %s Queues in total" % count)
except Exception, e: # Probably an IndexError
except Exception as e: # Probably an IndexError
sys.stderr.write("Unable to process data. Returned data might be incorrect: %r" % e)
sys.exit(1)

@@ -86,7 +86,7 @@ long_options = ['help', 'user=', 'password=', 'debug', 'timeout=', 'profile', 'm

try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
except getopt.GetoptError as err:
sys.stderr.write("%s\n" % err)
sys.exit(1)

0 comments on commit 1ee8286

Please sign in to comment.
You can’t perform that action at this time.