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

Zabbix API not returning empty fields

Open dudehro opened this issue 6 months 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