From 6ba66273380294be0644d0fbdd988f547f41786c Mon Sep 17 00:00:00 2001 From: Dusan Matejka Date: Thu, 15 Nov 2018 17:00:10 +0100 Subject: [PATCH] Fixed support for LLD type user macros and added missing validate_certs attribute (cherry picked from commit 7af8c0e07e9da01ad0a05631c6094e62532fb21e) --- .../monitoring/zabbix/zabbix_hostmacro.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/monitoring/zabbix/zabbix_hostmacro.py b/lib/ansible/modules/monitoring/zabbix/zabbix_hostmacro.py index ad43fa6798..93ec0ed2d0 100644 --- a/lib/ansible/modules/monitoring/zabbix/zabbix_hostmacro.py +++ b/lib/ansible/modules/monitoring/zabbix/zabbix_hostmacro.py @@ -77,8 +77,8 @@ try: # Extend the ZabbixAPI # Since the zabbix-api python module too old (version 1.0, no higher version so far). class ZabbixAPIExtends(ZabbixAPI): - def __init__(self, server, timeout, user, passwd, **kwargs): - ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd) + def __init__(self, server, timeout, user, passwd, validate_certs, **kwargs): + ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd, validate_certs=validate_certs) HAS_ZABBIX_API = True except ImportError: @@ -121,7 +121,7 @@ class HostMacro(object): if self._module.check_mode: 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) + self._module.exit_json(changed=True, result="Successfully added host macro %s" % macro_name) except Exception as 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: 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) + self._module.exit_json(changed=True, result="Successfully updated host macro %s" % macro_name) 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 def delete_host_macro(self, host_macro_obj, macro_name): @@ -145,7 +145,7 @@ class HostMacro(object): if self._module.check_mode: 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) + self._module.exit_json(changed=True, result="Successfully deleted host macro %s" % macro_name) except Exception as 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'] validate_certs = module.params['validate_certs'] 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'] state = module.params['state'] timeout = module.params['timeout'] 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 # login to zabbix try: