Skip to content

Commit

Permalink
Fixes for Zabbix 6.0 (#683)
Browse files Browse the repository at this point in the history
* In 6.0 "opconditions" is valid only for "trigger" event source.

* Fix lint errors.

* zabbix_action.py: for conditiontype=maintenance_status value attribute must not be provided.

* Fixing ansible-doc errrors.

* zabbix_mediatype.py: if smtp_authentication == False then username and passwd must not be provided in API call (Zabbix 6.0)

* zabbix_mediatype.py: esc_period value update (Zabbix 6.0)

* plugins/modules/zabbix_action.py: when comparing lists ['A', 'B'] should be equal to ['B', 'A'] (Zabbix 6.0).

* Fix integration tests for zabbix_action (Zabbix 6.0).

* zabbix_maintenance.py: fixes for Zabbix 6.0.

* zabbix_proxy.py: fixes for Zabbix 6.0.

* Zabbix Service updated with all features from Zabbix 6.0.

* Fix tests for Zabbix User to run with Zabbix 6.0.

* Fix tests for zabbix_user_info to run with Zabbix 6.0.

* Fix sanity check errors.

* Add Zabbix 6.0 to integration test.

* zabbix_service: accept problem_tag without value (should be populated with default.

* zabbix_service.py: fix backward compatibility to pre 6.0.

* Fix integration tests for zabbix_action.

* Simplify code for zabbix_service tests.

* Fix lint errors.

* zabbix_service.py: improve real and generated config comparison (compare dicts and lists instead of just strings).

* module_utils/helpers.py: lists ['a', 'b'] and ['b', 'a'] should be considered equal.

* Drop local functions in favour of helpers from zabbix_utils.

* zabbix_action.py: fix esc_period for Zabbix 6.0.

* Code clean up.

* changelogs/fragments/683-zbx60.yml added.

* Fix yamllint errors.
  • Loading branch information
BGmot authored May 7, 2022
1 parent 35d8e30 commit eeee550
Show file tree
Hide file tree
Showing 12 changed files with 1,621 additions and 664 deletions.
1 change: 1 addition & 0 deletions .github/workflows/plugins-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- version: "4.0"
- version: "5.0"
# - version: "5.4" # only activate after basic compatibility
- version: "6.0"
ansible:
- stable-2.10
- stable-2.11
Expand Down
5 changes: 5 additions & 0 deletions changelogs/fragments/683-zbx60.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
minor_changes:
- zabbix_action, zabbix_maintenance, zabbix_mediatype, zabbix_proxy, zabbix_service - updated to work with Zabbix 6.0.
- helpers.helper_compare_lists() changed logic to not consider the order of elements in lists.
- (https://github.com/ansible-collections/community.zabbix/pull/683)
9 changes: 7 additions & 2 deletions plugins/module_utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ def helper_compare_lists(l1, l2, diff_dict):
return diff_dict
for i, item in enumerate(l1):
if isinstance(item, dict):
diff_dict.insert(i, {})
diff_dict[i] = helper_compare_dictionaries(item, l2[i], diff_dict[i])
for item2 in l2:
diff_dict2 = {}
diff_dict2 = helper_compare_dictionaries(item, item2, diff_dict2)
if len(diff_dict2) == 0:
break
if len(diff_dict2) != 0:
diff_dict.insert(i, item)
else:
if item != l2[i]:
diff_dict.append(item)
Expand Down
219 changes: 51 additions & 168 deletions plugins/modules/zabbix_action.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion plugins/modules/zabbix_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils
from ansible_collections.community.zabbix.plugins.module_utils.version import LooseVersion


class MaintenanceModule(ZabbixBase):
Expand Down Expand Up @@ -213,7 +214,8 @@ def update_maintenance(self, maintenance_id, group_ids, host_ids,
if tags is not None:
parameters['tags'] = tags
else:
parameters['tags'] = []
if LooseVersion(self._zbx_api_version) < LooseVersion('6.0'):
parameters['tags'] = []
self._zapi.maintenance.update(parameters)
# zabbix_api can call sys.exit() so we need to catch SystemExit here
except (Exception, SystemExit) as e:
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/zabbix_mediatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ def construct_parameters(self):
username=self._module.params['username'],
passwd=self._module.params['password']
))
if LooseVersion(self._zbx_api_version) >= LooseVersion('6.0'):
if parameters['smtp_authentication'] == '0':
parameters.pop('username')
parameters.pop('passwd')
return parameters

elif self._module.params['type'] == 'script':
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/zabbix_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def add_proxy(self, data):

if 'interface' in data and data['status'] != '6':
parameters.pop('interface', False)
else:
if LooseVersion(self._zbx_api_version) >= LooseVersion('6.0'):
parameters['interface'].pop('type')
parameters['interface'].pop('main')

proxy_ids_list = self._zapi.proxy.create(parameters)
self._module.exit_json(changed=True,
Expand Down
Loading

0 comments on commit eeee550

Please sign in to comment.