-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linked Templates not updated with xml/json templates #66720
Comments
Files identified in the description: If these files are inaccurate, please update the |
Also:
Linking on creation of a new template is working. |
Actually I can't really wrap my head around that propblem. Maybe @sky-joker @D3DeFi can comment on it. As i see it, the linked templates are read out in the Also I don't know how this currently could work with multiple templates in one file as those nodes aren't iterated over. If you look at zabbix_template.py line 680: # Identify template names for IDs retrieval
# Template names are expected to reside in ['zabbix_export']['templates'][*]['template'] for both data types
template_content, template_type = None, None
if template_json is not None:
template_type = 'json'
template_content = template_json
json_parsed = template.load_json_template(template_content)
template_names = list(t['template'] for t in json_parsed['zabbix_export']['templates'])
elif template_xml is not None:
template_type = 'xml'
template_content = template_xml
xml_parsed = template.load_xml_template(template_content)
template_names = list(t.find('template').text for t in list(xml_parsed.find('templates')))
else:
template_names = [template_name] Here only the content and the names of the templates are "read" out but things like macros not. What I don't get: the whole thing is then "just" imported in function |
Now I get it ... but it's still cumbersome. There are two ways to do this in the Zabbix API: with template.update and with configuration.import. If you use template.update - which i thought where the case for ansible - all would work as I was expecting it. If you look at https://www.zabbix.com/documentation/4.4/manual/api/reference/template/update there is this statement for templates:
So if you want to unlink a template from another template just don't pass it. The current Ansible implementation for importing xml/json file is using configuration.import instead. And here this whole process doesn't work as describe. In fact if you use the import function of the zabbix frontend it also doesn't work this way. What do you others think of this? |
I opened a Zabbix issue too ( https://support.zabbix.com/browse/ZBX-17215 ) - I think this might be a issue for the Zabbix team as the API should work consistently here. That said I'm not shure if it shouldn't be covered in the Ansible module too somehow. At least it should be mentioned in the docs? |
!component =lib/ansible/modules/monitoring/zabbix/zabbix_template.py |
Files identified in the description: If these files are inaccurate, please update the |
fixes ansible#66720 adding a check for versions >= 4.0.16 or >= 4.4.4 to enable deleteMissing for templateLinkage
New update rule is available from 4.0.16 and 4.4.4 up. Add check for version and enable new update rule. fixes ansible#66720
Tested with Zabbix 4.4.4 against the new options metioned in Zabbix Issue. Works now as expected. Added PR for new API update rule. |
Thanks @rockaut for such a deep analysis of the problem. The thing with importing multiple templates at once is only supported thanks to If we would to change to Anyways, thanks for providing a PR for this issue! Good job. |
Oh I totally get why it is how it is and I also think it's better than actually parse the xml/json as it would be way to error-prone. That's why I thought it should be handled in Zabbix API ... and now it's already present :D That said ... I still think it should somehow be mentioned in the readme for the ansible module somehow. Booth things actually, the configuration.import and the multi-object thing. Multi-object isn't only hitting templates but also host as I see it? I will wrap my thoughts about it next week and maybe contribute something so that we can discuss this aside from this issue/pr. |
…plates (ansible#66747) * enable new update rule to delete missing linked templates New update rule is available from 4.0.16 and 4.4.4 up. Add check for version and enable new update rule. fixes ansible#66720 * adding fragment file * Update zabbix_template.py * Update zabbix_template.py
SUMMARY
If you import a template with a xml/json file the linked templates of a templates ( so the child templates not the root ones ) aren't processed if you want to remove linked templates.
ISSUE TYPE
COMPONENT NAME
zabbix_templates
ANSIBLE VERSION
OS / ENVIRONMENT
Zabbix 4.4.4 on RHEL7
STEPS TO REPRODUCE
Export a template (no matter if with Zabbix itself or ansible). Change the corresponding linked template section of a template and reimport it.
Exported with Zabbix:
Change to this with removing all linked templates ( fismb in above example ).
EXPECTED RESULTS
fismb should be unlinked from fisma.
ACTUAL RESULTS
fismb is still linked with fisma.
The text was updated successfully, but these errors were encountered: