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
This commit is contained in:
Igor 2017-12-07 16:06:54 +03:00 committed by ansibot
parent 2caae251ff
commit 22f4074daa

View file

@ -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(