Make zabbix modules compile on python 3

Since the module is not compatible with python 2.4, we
do not need to use the get_exception trick
This commit is contained in:
Michael Scherer 2016-10-16 09:41:02 +02:00 committed by Matt Clay
parent c1f7fa2f3b
commit 1948bcb9e7
5 changed files with 16 additions and 20 deletions

View file

@ -127,7 +127,7 @@ class HostMacro(object):
else:
host_id = host_list[0]['hostid']
return host_id
except Exception, e:
except Exception as e:
self._module.fail_json(msg="Failed to get the host %s id: %s." % (host_name, e))
# get host macro
@ -138,7 +138,7 @@ class HostMacro(object):
if len(host_macro_list) > 0:
return host_macro_list[0]
return None
except Exception, e:
except Exception as e:
self._module.fail_json(msg="Failed to get host macro %s: %s" % (macro_name, e))
# create host macro
@ -148,7 +148,7 @@ class HostMacro(object):
self._module.exit_json(changed=True)
self._zapi.usermacro.create({'hostid': host_id, 'macro': '{$' + macro_name + '}', 'value': macro_value})
self._module.exit_json(changed=True, result="Successfully added host macro %s " % macro_name)
except Exception, e:
except Exception as e:
self._module.fail_json(msg="Failed to create host macro %s: %s" % (macro_name, e))
# update host macro
@ -161,7 +161,7 @@ class HostMacro(object):
self._module.exit_json(changed=True)
self._zapi.usermacro.update({'hostmacroid': host_macro_id, 'value': macro_value})
self._module.exit_json(changed=True, result="Successfully updated host macro %s " % macro_name)
except Exception, e:
except Exception as e:
self._module.fail_json(msg="Failed to updated host macro %s: %s" % (macro_name, e))
# delete host macro
@ -172,7 +172,7 @@ class HostMacro(object):
self._module.exit_json(changed=True)
self._zapi.usermacro.delete([host_macro_id])
self._module.exit_json(changed=True, result="Successfully deleted host macro %s " % macro_name)
except Exception, e:
except Exception as e:
self._module.fail_json(msg="Failed to delete host macro %s: %s" % (macro_name, e))
def main():
@ -211,7 +211,7 @@ def main():
try:
zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password)
zbx.login(login_user, login_password)
except Exception, e:
except Exception as e:
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)
host_macro_class_obj = HostMacro(module, zbx)