From 22f4074daa9a3a47c42de1f1d2061c5e6ab8a705 Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 7 Dec 2017 16:06:54 +0300 Subject: [PATCH] Zabbix 3.4 support fix for zabbix_template module. (#33462) * Zabbix 3.4 support fix. As of 3.4 Zabbix version application does not have 'updateExisting'. * added updateExisting in applications for old zabbix support. * small codestylefix --- .../monitoring/zabbix/zabbix_template.py | 100 ++++++++++-------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/lib/ansible/modules/monitoring/zabbix/zabbix_template.py b/lib/ansible/modules/monitoring/zabbix/zabbix_template.py index 775bb7f75b..f942aba2c0 100644 --- a/lib/ansible/modules/monitoring/zabbix/zabbix_template.py +++ b/lib/ansible/modules/monitoring/zabbix/zabbix_template.py @@ -202,7 +202,7 @@ template_json: } ''' - +from distutils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native import json @@ -367,55 +367,63 @@ class Template(object): if template_name != parsed_template_json['zabbix_export']['templates'][0]['template']: self._module.fail_json(msg='JSON template name does not match presented name') + # rules schema latest version + update_rules = { + 'applications': { + 'createMissing': True, + 'deleteMissing': True + }, + 'discoveryRules': { + 'createMissing': True, + 'updateExisting': True, + 'deleteMissing': True + }, + 'graphs': { + 'createMissing': True, + 'updateExisting': True, + 'deleteMissing': True + }, + 'httptests': { + 'createMissing': True, + 'updateExisting': True, + 'deleteMissing': True + }, + 'items': { + 'createMissing': True, + 'updateExisting': True, + 'deleteMissing': True + }, + 'templates': { + 'createMissing': True, + 'updateExisting': True + }, + 'templateScreens': { + 'createMissing': True, + 'updateExisting': True, + 'deleteMissing': True + }, + 'triggers': { + 'createMissing': True, + 'updateExisting': True, + 'deleteMissing': True + }, + 'valueMaps': { + 'createMissing': True, + 'updateExisting': True + } + } + try: + # old api version support here + api_version = self._zapi.api_version() + # updateExisting for application removed from zabbix api after 3.2 + if LooseVersion(api_version) <= LooseVersion('3.2.x'): + update_rules['applications']['updateExisting'] = True + self._zapi.configuration.import_({ 'format': 'json', 'source': template_json, - 'rules': { - 'applications': { - 'createMissing': True, - 'updateExisting': True, - 'deleteMissing': True - }, - 'discoveryRules': { - 'createMissing': True, - 'updateExisting': True, - 'deleteMissing': True - }, - 'graphs': { - 'createMissing': True, - 'updateExisting': True, - 'deleteMissing': True - }, - 'httptests': { - 'createMissing': True, - 'updateExisting': True, - 'deleteMissing': True - }, - 'items': { - 'createMissing': True, - 'updateExisting': True, - 'deleteMissing': True - }, - 'templates': { - 'createMissing': True, - 'updateExisting': True - }, - 'templateScreens': { - 'createMissing': True, - 'updateExisting': True, - 'deleteMissing': True - }, - 'triggers': { - 'createMissing': True, - 'updateExisting': True, - 'deleteMissing': True - }, - 'valueMaps': { - 'createMissing': True, - 'updateExisting': True - } - } + 'rules': update_rules }) except ZabbixAPIException as e: self._module.fail_json(