ansible-collections / community.zabbix

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

Maps with linked nodes returns "KeyError: 'pos'" #675

Open dutrajulio opened 2 years ago

dutrajulio commented 2 years ago
SUMMARY

zabbix_map module always return "KeyError: 'pos'" when map content have linked (-- or ->) nodes.

ISSUE TYPE
COMPONENT NAME

zabbix_map.py

ANSIBLE VERSION
ansible [core 2.12.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = ~/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0]
  jinja version = 3.0.3
  libyaml = True
CONFIGURATION

Default

OS / ENVIRONMENT / Zabbix Version

Target OS: CentOS 8 Stream Zabbix Version: 4.2.8

STEPS TO REPRODUCE

Try to create a map with linked nodes.

ansible localhost -m community.zabbix.zabbix_map -a "server_url=https://**SERVER_URL** login_user=**LOGIN_USER** login_password=**LOGIN_PASSWORD** name='Example' data='graph {\"example-s01\" -- \"example-s02\"}' default_image=Server_(64) label_type=label"
EXPECTED RESULTS

Map created with success.

ACTUAL RESULTS

The commando return "KeyError: 'pos'".

~/.ansible/tmp/ansible-tmp-1650396444.0304828-222827-55587666750293/debug_dir/ansible_collections/community/zabbix/plugins/modules/zabbix_map.py:183: Depr
ecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.version import LooseVersion
Traceback (most recent call last):
  File "~/.ansible/tmp/ansible-tmp-1650396444.0304828-222827-55587666750293/AnsiballZ_zabbix_map.py", line 259, in <module>
    _ansiballz_main()
  File "~/.ansible/tmp/ansible-tmp-1650396444.0304828-222827-55587666750293/AnsiballZ_zabbix_map.py", line 246, in _ansiballz_main
    exitcode = debug(sys.argv[1], zipped_mod, ANSIBALLZ_PARAMS)
  File "~/.ansible/tmp/ansible-tmp-1650396444.0304828-222827-55587666750293/AnsiballZ_zabbix_map.py", line 213, in debug
    runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_map', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "~/.ansible/tmp/ansible-tmp-1650396444.0304828-222827-55587666750293/debug_dir/ansible_collections/community/zabbix/plugins/modules/zabbix_map.py",
 line 790, in <module>
    main()
  File "~/.ansible/tmp/ansible-tmp-1650396444.0304828-222827-55587666750293/debug_dir/ansible_collections/community/zabbix/plugins/modules/zabbix_map.py",
 line 777, in main
    map_config = sysmap.get_map_config()
  File "~/.ansible/tmp/ansible-tmp-1650396444.0304828-222827-55587666750293/debug_dir/ansible_collections/community/zabbix/plugins/modules/zabbix_map.py",
 line 252, in get_map_config
    'selements': self._get_selements(graph, nodes, icon_ids),
  File "~/.ansible/tmp/ansible-tmp-1650396444.0304828-222827-55587666750293/debug_dir/ansible_collections/community/zabbix/plugins/modules/zabbix_map.py",
 line 373, in _get_selements
    pos = self._convert_coordinates(data['pos'], scales, icon_sizes[image_id])
KeyError: 'pos'
dutrajulio commented 1 year ago

After a lot of testing i found a workaround that, maybe, be a clue to a definitive solution.

Our ".dot" files are written in blocks where we have the "nodes declaration block" and the "linking declaration block". The final file looks like this.

graph {
  "example-01" [zbx_group="Group01", zbx_label="example-01"]
  "example-02" [zbx_host="example-02", zbx_label="{HOST.HOST}"]
  "example-03" [zbx_host="example-03", zbx_label="{HOST.HOST}", zbx_image="Server_(64)"]

  "example-01" -- "example-02" [label="link1"]
  "example-01" -- "example-03"
}

The workaround was declare a node without any attributes, at last line of "nodes declaration block", before the "linking declaration block". So, the ".dot" file now looks like this.

graph {
  "example-01" [zbx_group="Group01", zbx_label="example-01"]
  "example-02" [zbx_host="example-02", zbx_label="{HOST.HOST}"]
  "example-03" [zbx_host="example-03", zbx_label="{HOST.HOST}", zbx_image="Server_(64)"]
  "REMOVETHIS"

  "example-01" -- "example-02" [label="link1"]
  "example-01" -- "example-03"
}

With the node "REMOVETHIS" the map is correctly generated without the error "KeyError: 'pos'".

Maybe, this is a bug related with the structure of ".dot" file we use.

RoiCanard commented 1 month ago

Got the same problem, I'm interested to know if anyone understood the exact reason this happens and why adding a random node fixes it.