From c7f134784121cf86d3ef2c0294cfe782da1d1483 Mon Sep 17 00:00:00 2001 From: ONODERA Masaru <46081939+masa-orca@users.noreply.github.com> Date: Wed, 31 Jul 2024 01:46:19 +0900 Subject: [PATCH 1/3] Delete denied parameters from host interfaces --- plugins/modules/zabbix_host.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/modules/zabbix_host.py b/plugins/modules/zabbix_host.py index bdf010aba..c727e6b9b 100644 --- a/plugins/modules/zabbix_host.py +++ b/plugins/modules/zabbix_host.py @@ -944,7 +944,7 @@ def update_inventory_zabbix(self, host_id, inventory): # Add all default values to all missing parameters for existing interfaces -def update_exist_interfaces_with_defaults(exist_interfaces): +def update_exist_interfaces_with_defaults(exist_interfaces, zabbix_version): new_exist_interfaces = [] default_interface = { @@ -966,9 +966,29 @@ def update_exist_interfaces_with_defaults(exist_interfaces): "privprotocol": 0, "privpassphrase": "" } + allowed_fields = [ + 'hostid', + 'type', + 'ip', + 'dns', + 'port', + 'useip', + 'main', + 'details', + 'interface_ref', + 'items', + 'interfaceid' + ] for interface in exist_interfaces: + normalized_interface = interface + if LooseVersion("7.0") <= LooseVersion(zabbix_version): + denied_fields = list(set(interface.keys()) - set(allowed_fields)) + normalized_interface = zabbix_utils.helper_normalize_data( + interface, del_keys=denied_fields + )[0] + new_interface = default_interface.copy() - new_interface.update(interface) + new_interface.update(normalized_interface) new_interface["details"] = default_interface_details.copy() if "details" in interface: new_interface["details"].update(interface["details"]) @@ -1195,7 +1215,7 @@ def main(): # get existing host's interfaces exist_interfaces = host._zapi.hostinterface.get({"output": "extend", "hostids": host_id}) exist_interfaces.sort(key=lambda x: int(x["interfaceid"])) - exist_interfaces = update_exist_interfaces_with_defaults(exist_interfaces) + exist_interfaces = update_exist_interfaces_with_defaults(exist_interfaces, host._zbx_api_version) # Convert integer parameters from strings to ints for idx, interface in enumerate(copy.deepcopy(exist_interfaces)): From ad37a3f8fd59496592d14eb1999d4c54c0bec838 Mon Sep 17 00:00:00 2001 From: ONODERA Masaru Date: Sat, 3 Aug 2024 05:30:47 +0000 Subject: [PATCH 2/3] Remove checking version condition --- plugins/modules/zabbix_host.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/modules/zabbix_host.py b/plugins/modules/zabbix_host.py index c727e6b9b..b423d4260 100644 --- a/plugins/modules/zabbix_host.py +++ b/plugins/modules/zabbix_host.py @@ -944,7 +944,7 @@ def update_inventory_zabbix(self, host_id, inventory): # Add all default values to all missing parameters for existing interfaces -def update_exist_interfaces_with_defaults(exist_interfaces, zabbix_version): +def update_exist_interfaces_with_defaults(exist_interfaces): new_exist_interfaces = [] default_interface = { @@ -981,11 +981,10 @@ def update_exist_interfaces_with_defaults(exist_interfaces, zabbix_version): ] for interface in exist_interfaces: normalized_interface = interface - if LooseVersion("7.0") <= LooseVersion(zabbix_version): - denied_fields = list(set(interface.keys()) - set(allowed_fields)) - normalized_interface = zabbix_utils.helper_normalize_data( - interface, del_keys=denied_fields - )[0] + denied_fields = list(set(interface.keys()) - set(allowed_fields)) + normalized_interface = zabbix_utils.helper_normalize_data( + interface, del_keys=denied_fields + )[0] new_interface = default_interface.copy() new_interface.update(normalized_interface) @@ -1215,7 +1214,7 @@ def main(): # get existing host's interfaces exist_interfaces = host._zapi.hostinterface.get({"output": "extend", "hostids": host_id}) exist_interfaces.sort(key=lambda x: int(x["interfaceid"])) - exist_interfaces = update_exist_interfaces_with_defaults(exist_interfaces, host._zbx_api_version) + exist_interfaces = update_exist_interfaces_with_defaults(exist_interfaces) # Convert integer parameters from strings to ints for idx, interface in enumerate(copy.deepcopy(exist_interfaces)): From bc52cd8350fd6ec06d0aee2eca0765167c1e6265 Mon Sep 17 00:00:00 2001 From: ONODERA Masaru Date: Sat, 3 Aug 2024 05:36:35 +0000 Subject: [PATCH 3/3] Add changelog fragment --- .../fragments/1356-zabbix_host-delete-denied-parameters.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/1356-zabbix_host-delete-denied-parameters.yml diff --git a/changelogs/fragments/1356-zabbix_host-delete-denied-parameters.yml b/changelogs/fragments/1356-zabbix_host-delete-denied-parameters.yml new file mode 100644 index 000000000..8b804925d --- /dev/null +++ b/changelogs/fragments/1356-zabbix_host-delete-denied-parameters.yml @@ -0,0 +1,2 @@ +bugfixes: + - zabbix_host - delete denied parameter from interfaces