community.zabbix icon indicating copy to clipboard operation
community.zabbix copied to clipboard

Zabbix API not returning empty fields

Open dudehro opened this issue 2 years ago • 1 comments

Hi,

we are running Zabbix 7 and community.zabbix 2.1.0.

Creating a host inside zabbix is working but running the same play again causes an error:

Traceback (most recent call last): File "/home/work/.ansible/tmp/ansible-local-667774yryaih66/ansible-tmp-1701785335.188994-667821-129341199475699/AnsiballZ_zabbix_host.py", line 107, in _ansiballz_main() File "/home/work/.ansible/tmp/ansible-local-667774yryaih66/ansible-tmp-1701785335.188994-667821-129341199475699/AnsiballZ_zabbix_host.py", line 99, in _ansiballz_main invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS) File "/home/work/.ansible/tmp/ansible-local-667774yryaih66/ansible-tmp-1701785335.188994-667821-129341199475699/AnsiballZ_zabbix_host.py", line 47, in invoke_module runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_host', init_globals=dict(_module_fqn='ansible_collections.community.zabbix.plugins.modules.zabbix_host', _modlib_path=modlib_path), File "", line 226, in run_module File "", line 98, in _run_module_code File "", line 88, in _run_code File "/tmp/ansible_zabbix_host_payload_zldr7lj8/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py", line 1250, in File "/tmp/ansible_zabbix_host_payload_zldr7lj8/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py", line 1198, in main File "/tmp/ansible_zabbix_host_payload_zldr7lj8/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py", line 738, in check_all_properties KeyError: 'proxy_hostid'

The key proxy_hostid is missing. Which is caused by this line So I added a line to the zabbix_host.py to print out the answer from self._zapi.host.get(params) and voila, no proxy_hostid in sight:

[{'hostid': '10611', 'host': 'ansible-test', 'status': '0', 'ipmi_authtype': '-1', 'ipmi_privilege': '2', 'ipmi_username': '', 'ipmi_password': '', 'maintenanceid': '0', 'maintenance_status': '0', 'maintenance_type': '0', 'maintenance_from': '0', 'name': 'ansible-test', 'flags': '0', 'templateid': '0', 'description': '', 'tls_connect': '1', 'tls_accept': '1', 'tls_issuer': '', 'tls_subject': '', 'custom_interfaces': '0', 'uuid': '', 'inventory_mode': '-1', 'macros': [], 'inventory': [], 'tags': []}]

We are not working with proxies, so there is nothing to return for zabbix. But the code looks like the api did returned requested, empty fields in the past.

Maybe change if int(host["proxy_hostid"]) != int(proxy_id): return True to if "proxy_hostid" in host and int(host["proxy_hostid"]) != int(proxy_id):

dudehro avatar Dec 05 '23 14:12 dudehro

I will tell you that as of right now we have not done anything against Zabbix 7.0 since it still hasn't actually been released. Once it is, we'll get to work on making whatever changes are required to support it.

pyrodie18 avatar Jan 30 '24 04:01 pyrodie18

@BGmot is this closed out with your previous work?

pyrodie18 avatar Jun 08 '24 18:06 pyrodie18

I just tested today with version 2.5.1, the same error persists: An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'proxy_hostid'

ricardoklein avatar Jun 12 '24 07:06 ricardoklein

@BGmot is this closed out with your previous work?

Yes. Sorry for delay in replying - somehow missed this. -(

BGmot avatar Jun 12 '24 11:06 BGmot

I just tested today with version 2.5.1, the same error persists: An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'proxy_hostid'

This will be working only in version 3.0.0 that we are about to release. Please stand by.

BGmot avatar Jun 12 '24 11:06 BGmot