ansible-collections / community.zabbix

Zabbix Ansible modules
http://galaxy.ansible.com/community/zabbix
Other
322 stars 284 forks source link

Wrong usage of template.create/update API calls? #519

Closed D3DeFi closed 2 years ago

D3DeFi commented 2 years ago
SUMMARY

See #518

Apparently, we link templates in a wrong way?

"templates": ["12345"] which result in the above error on Zabbix 5.0. It worked on version 4.0. I didn't found any documented change in API, but it was already required before to send templateid property according to the documentation: https://www.zabbix.com/documentation/5.0/manual/api/reference/template/create

This commit changes request that it is sending: "templates": [{"templateid": "12345"}] 

I wonder why our zabbix_template module even works in actual state, since doc for 4.0 also notes using templates: [templateid: val]

ISSUE TYPE
COMPONENT NAME

plugins/modules/zabbix_template.py

mu1f407 commented 2 years ago

@D3DeFi thanks for creating an issue. Internally I fixed it in another way than in original PR. Successful tests, where I saw that template linking is used, is exactly what makes me curious as well. I wanted to run tests against Zabbix 5.0 before submitting another PR, but I will need some time to prepare the test environment.

mu1f407 commented 2 years ago

I've managed to install Docker testing environment and I found that it fails only on template.create API call and there is no test which could catch this error, because the template create test does not links any templates.

I added another test for create with linked templates and it fails:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: zabbix_api.ZabbixAPIException: ('Error -32500: Application error., No permissions to referred object or it does not exist! while sending {"jsonrpc": "2.0", "method": "template.create", "params": {"host": "ExampleHostWithLinked", "groups": [{"groupid": "1"}, {"groupid": "2"}], "templates": ["10048", "10093"], "macros": null}, "auth": "0150fb7d8f1b8e2caafa73da969bddb5", "id": 8}', -32500)

I think it would be best to fix the template.update according to API docs as well. Even if it doesn't fail now, because it could in the future. I will try to send a PR this week with added create test with linked templates and fixed linked templates handling for create and update calls.

D3DeFi commented 2 years ago

@mu1f407 awesome! Thank you :) I will then assign this issue to you