From b05529c5a30a196f89bef3837523efaa24cb3d9e Mon Sep 17 00:00:00 2001 From: Markus Fischbacher <453368+rockaut@users.noreply.github.com> Date: Thu, 9 Jan 2020 01:25:10 +0100 Subject: [PATCH] adding proxy_address field for active proxies (#66247) Since 4.0.0 there is a field proxy_address for limiting proxy requests. Official Docs: "Proxy address If specified then active proxy requests are only accepted from this list of comma-delimited IP addresses, optionally in CIDR notation, or DNS names of active Zabbix proxy. This field is only available if an active proxy is selected in the Proxy mode field. Macros are not supported. This option is supported since Zabbix 4.0.0." updated documentation/help fixed test issues fixed version_added not a string fix suggestions by D3DeFi added changelog fragment applied D3DeFi suggestions way cleaner and better readable --- .../66247-zabbix_proxy-address-field.yaml | 2 ++ .../modules/monitoring/zabbix/zabbix_proxy.py | 28 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/66247-zabbix_proxy-address-field.yaml diff --git a/changelogs/fragments/66247-zabbix_proxy-address-field.yaml b/changelogs/fragments/66247-zabbix_proxy-address-field.yaml new file mode 100644 index 00000000000..d0be347d925 --- /dev/null +++ b/changelogs/fragments/66247-zabbix_proxy-address-field.yaml @@ -0,0 +1,2 @@ +minor_changes: + - zabbix_proxy - added option proxy_address for comma-delimited list of IP/CIDR addresses or DNS names to accept active proxy requests from diff --git a/lib/ansible/modules/monitoring/zabbix/zabbix_proxy.py b/lib/ansible/modules/monitoring/zabbix/zabbix_proxy.py index 83cafc2e0a6..df2ba3552f6 100644 --- a/lib/ansible/modules/monitoring/zabbix/zabbix_proxy.py +++ b/lib/ansible/modules/monitoring/zabbix/zabbix_proxy.py @@ -42,6 +42,13 @@ options: description: - Name of the proxy in Zabbix. required: true + proxy_address: + description: + - Comma-delimited list of IP/CIDR addresses or DNS names to accept active proxy requests from. + - Requires I(status=active). + - Works only with >= Zabbix 4.0. ( remove option for <= 4.0 ) + required: false + version_added: '2.10' description: description: - Description of the proxy. @@ -113,6 +120,7 @@ EXAMPLES = ''' description: ExampleProxy status: active state: present + proxy_address: ExampleProxy.local interface: type: 0 main: 1 @@ -165,6 +173,12 @@ class Proxy(object): if data[item]: parameters[item] = data[item] + if 'proxy_address' in data and data['status'] != '5': + parameters.pop('proxy_address', False) + + if 'interface' in data and data['status'] != '6': + parameters.pop('interface', False) + proxy_ids_list = self._zapi.proxy.create(parameters) self._module.exit_json(changed=True, result="Successfully added proxy %s (%s)" % @@ -216,6 +230,12 @@ class Proxy(object): if 'interface' in parameters: parameters.pop('interface') + if 'proxy_address' in data and data['status'] != '5': + parameters.pop('proxy_address', False) + + if 'interface' in data and data['status'] != '6': + parameters.pop('interface', False) + if 'interface' in data and data['status'] == '6': new_interface = self.compile_interface_params(data['interface']) if len(new_interface) > 0: @@ -242,6 +262,7 @@ def main(): login_user=dict(type='str', required=True), login_password=dict(type='str', required=True, no_log=True), proxy_name=dict(type='str', required=True), + proxy_address=dict(type='str', required=False), http_login_user=dict(type='str', required=False, default=None), http_login_password=dict(type='str', required=False, default=None, no_log=True), @@ -273,6 +294,7 @@ def main(): http_login_password = module.params['http_login_password'] validate_certs = module.params['validate_certs'] proxy_name = module.params['proxy_name'] + proxy_address = module.params['proxy_address'] description = module.params['description'] status = module.params['status'] tls_connect = module.params['tls_connect'] @@ -334,7 +356,8 @@ def main(): 'tls_subject': tls_subject, 'tls_psk_identity': tls_psk_identity, 'tls_psk': tls_psk, - 'interface': interface + 'interface': interface, + 'proxy_address': proxy_address }) else: if state == "absent": @@ -351,7 +374,8 @@ def main(): 'tls_subject': tls_subject, 'tls_psk_identity': tls_psk_identity, 'tls_psk': tls_psk, - 'interface': interface + 'interface': interface, + 'proxy_address': proxy_address })