Fixed support for LLD type user macros and added missing validate_certs attribute
This commit is contained in:
parent
f0c290c930
commit
7af8c0e07e
1 changed files with 12 additions and 7 deletions
|
@ -77,8 +77,8 @@ try:
|
||||||
# Extend the ZabbixAPI
|
# Extend the ZabbixAPI
|
||||||
# Since the zabbix-api python module too old (version 1.0, no higher version so far).
|
# Since the zabbix-api python module too old (version 1.0, no higher version so far).
|
||||||
class ZabbixAPIExtends(ZabbixAPI):
|
class ZabbixAPIExtends(ZabbixAPI):
|
||||||
def __init__(self, server, timeout, user, passwd, **kwargs):
|
def __init__(self, server, timeout, user, passwd, validate_certs, **kwargs):
|
||||||
ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd)
|
ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd, validate_certs=validate_certs)
|
||||||
|
|
||||||
HAS_ZABBIX_API = True
|
HAS_ZABBIX_API = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -121,7 +121,7 @@ class HostMacro(object):
|
||||||
if self._module.check_mode:
|
if self._module.check_mode:
|
||||||
self._module.exit_json(changed=True)
|
self._module.exit_json(changed=True)
|
||||||
self._zapi.usermacro.create({'hostid': host_id, 'macro': '{$' + macro_name + '}', 'value': macro_value})
|
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)
|
self._module.exit_json(changed=True, result="Successfully added host macro %s" % macro_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._module.fail_json(msg="Failed to create host macro %s: %s" % (macro_name, e))
|
self._module.fail_json(msg="Failed to create host macro %s: %s" % (macro_name, e))
|
||||||
|
|
||||||
|
@ -134,9 +134,9 @@ class HostMacro(object):
|
||||||
if self._module.check_mode:
|
if self._module.check_mode:
|
||||||
self._module.exit_json(changed=True)
|
self._module.exit_json(changed=True)
|
||||||
self._zapi.usermacro.update({'hostmacroid': host_macro_id, 'value': macro_value})
|
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)
|
self._module.exit_json(changed=True, result="Successfully updated host macro %s" % macro_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._module.fail_json(msg="Failed to updated host macro %s: %s" % (macro_name, e))
|
self._module.fail_json(msg="Failed to update host macro %s: %s" % (macro_name, e))
|
||||||
|
|
||||||
# delete host macro
|
# delete host macro
|
||||||
def delete_host_macro(self, host_macro_obj, macro_name):
|
def delete_host_macro(self, host_macro_obj, macro_name):
|
||||||
|
@ -145,7 +145,7 @@ class HostMacro(object):
|
||||||
if self._module.check_mode:
|
if self._module.check_mode:
|
||||||
self._module.exit_json(changed=True)
|
self._module.exit_json(changed=True)
|
||||||
self._zapi.usermacro.delete([host_macro_id])
|
self._zapi.usermacro.delete([host_macro_id])
|
||||||
self._module.exit_json(changed=True, result="Successfully deleted host macro %s " % macro_name)
|
self._module.exit_json(changed=True, result="Successfully deleted host macro %s" % macro_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._module.fail_json(msg="Failed to delete host macro %s: %s" % (macro_name, e))
|
self._module.fail_json(msg="Failed to delete host macro %s: %s" % (macro_name, e))
|
||||||
|
|
||||||
|
@ -179,12 +179,17 @@ def main():
|
||||||
http_login_password = module.params['http_login_password']
|
http_login_password = module.params['http_login_password']
|
||||||
validate_certs = module.params['validate_certs']
|
validate_certs = module.params['validate_certs']
|
||||||
host_name = module.params['host_name']
|
host_name = module.params['host_name']
|
||||||
macro_name = (module.params['macro_name']).upper()
|
macro_name = (module.params['macro_name'])
|
||||||
macro_value = module.params['macro_value']
|
macro_value = module.params['macro_value']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
timeout = module.params['timeout']
|
timeout = module.params['timeout']
|
||||||
force = module.params['force']
|
force = module.params['force']
|
||||||
|
|
||||||
|
if ':' in macro_name:
|
||||||
|
macro_name = ':'.join([macro_name.split(':')[0].upper(), macro_name.split(':')[1]])
|
||||||
|
else:
|
||||||
|
macro_name = macro_name.upper()
|
||||||
|
|
||||||
zbx = None
|
zbx = None
|
||||||
# login to zabbix
|
# login to zabbix
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue