ansible-collections / community.zabbix

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

Group template elements by application unavailable #1211

Closed djdejawu closed 7 months ago

djdejawu commented 7 months ago

With community.zabbix.zabbix_template unable import items and assign them to application group. In API parameter application is available but not imported with configuration.import.

SUMMARY
fatal: [localhost]: FAILED! => {"changed": false, "msg": "connection error occurred: REST API returned {'code': -32500, 'message': 'Application error.', 'data': 'Item \"Device condition\" on \"AAAA_CORE\": application \"Status\" does not exist.'} when sending {\"jsonrpc\": \"2.0\", \"method\": \"configuration.import\", \"id\": \"8264694d-c911-42ae-aadd-ae29204c50ae\", \"params\": {\"format\": \"json\", \"source\": \"{\\\"zabbix_export\\\": {\\\"version\\\": \\\"5.0\\\", \\\"groups\\\": [{\\\"name\\\": \\\"AAAA\\\"}], \\\"templates\\\": [{\\\"name\\\": \\\"AAAA_CORE\\\", \\\"applications\\\": [{\\\"name\\\": \\\"Status\\\"}], \\\"template\\\": \\\"AAAA_CORE\\\", \\\"groups\\\": [{\\\"name\\\": \\\"AAAA\\\"}], \\\"items\\\": [{\\\"name\\\": \\\"Device condition\\\", \\\"applications\\\": [{\\\"name\\\": \\\"Status\\\"}], \\\"key\\\": \\\"state_code\\\"}]}]}}\", \"rules\": {\"discoveryRules\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"graphs\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"httptests\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"items\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"templates\": {\"createMissing\": true, \"updateExisting\": true}, \"templateLinkage\": {\"createMissing\": true, \"deleteMissing\": true}, \"triggers\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"valueMaps\": {\"createMissing\": true, \"updateExisting\": true}, \"templateDashboards\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"groups\": {\"createMissing\": true}}}, \"auth\": \"79da92a458b42d28bc3f65a4f861d228\"}"}
ISSUE TYPE
COMPONENT NAME

community.zabbix.zabbix_template

ANSIBLE VERSION
ansible [core 2.16.6]
  config file = None
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/git/ansible_zabbix/venv/lib64/python3.12/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/git/ansible_zabbix/venv/bin/ansible
  python version = 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/home/user/git/ansible_zabbix/venv/bin/python3)
  jinja version = 3.1.3
  libyaml = True
CONFIGURATION
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/nano
OS / ENVIRONMENT / Zabbix Version
Host: Fedora 39
Python:  3.12.2
Zabbix: 5.2
STEPS TO REPRODUCE
- name: Add templates
      # vars:
      #   ansible_network_os: community.zabbix.zabbix
      #   ansible_connection: httpapi
      #   ansible_httpapi_port: 8080
      #   ansible_httpapi_use_ssl: false
      #   ansible_host: localhost
      community.zabbix.zabbix_template:
        # template_json: "{{ lookup('file', 'zbx_tmpl_aaaa_core.json') }}"
        template_json:
          zabbix_export:
            version: "5.0"
            groups:
              - name: "AAAA"
            templates:
              - name: AAAA_CORE
                applications:
                  - name: Status
                template: AAAA_CORE
                groups:
                  - name: "AAAA"
                items:
                  - name: "Device condition"
                    applications:
                      - name: Status
                    key: state_code
        state: present
EXPECTED RESULTS

Template with keys in applications

ACTUAL RESULTS
  File "/tmp/ansible_community.zabbix.zabbix_template_payload_h6j__z6v/ansible_community.zabbix.zabbix_template_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/api_request.py", line 29, in _httpapi_error_handle
    code, response = self.connection.send_request(data=payload)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/ansible_community.zabbix.zabbix_template_payload_h6j__z6v/ansible_community.zabbix.zabbix_template_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "clear_templates": null,
            "http_login_password": null,
            "http_login_user": null,
            "link_templates": null,
            "macros": null,
            "state": "present",
            "tags": null,
            "template_groups": null,
            "template_json": "{\"zabbix_export\": {\"version\": \"5.0\", \"groups\": [{\"name\": \"AAAA\"}], \"templates\": [{\"name\": \"AAAA_CORE\", \"applications\": [{\"name\": \"Status\"}], \"template\": \"AAAA_CORE\", \"groups\": [{\"name\": \"AAAA\"}], \"items\": [{\"name\": \"Device condition\", \"applications\": [{\"name\": \"Status\"}], \"key\": \"state_code\"}]}]}}",
            "template_name": null,
            "template_xml": null
        }
    },
    "msg": "connection error occurred: REST API returned {'code': -32500, 'message': 'Application error.', 'data': 'Item \"Device condition\" on \"AAAA_CORE\": application \"Status\" does not exist.'} when sending {\"jsonrpc\": \"2.0\", \"method\": \"configuration.import\", \"id\": \"2a6594e6-f13b-4a4b-b1cd-c31c86702c9e\", \"params\": {\"format\": \"json\", \"source\": \"{\\\"zabbix_export\\\": {\\\"version\\\": \\\"5.0\\\", \\\"groups\\\": [{\\\"name\\\": \\\"AAAA\\\"}], \\\"templates\\\": [{\\\"name\\\": \\\"AAAA_CORE\\\", \\\"applications\\\": [{\\\"name\\\": \\\"Status\\\"}], \\\"template\\\": \\\"AAAA_CORE\\\", \\\"groups\\\": [{\\\"name\\\": \\\"AAAA\\\"}], \\\"items\\\": [{\\\"name\\\": \\\"Device condition\\\", \\\"applications\\\": [{\\\"name\\\": \\\"Status\\\"}], \\\"key\\\": \\\"state_code\\\"}]}]}}\", \"rules\": {\"discoveryRules\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"graphs\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"httptests\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"items\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"templates\": {\"createMissing\": true, \"updateExisting\": true}, \"templateLinkage\": {\"createMissing\": true, \"deleteMissing\": true}, \"triggers\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"valueMaps\": {\"createMissing\": true, \"updateExisting\": true}, \"templateDashboards\": {\"createMissing\": true, \"updateExisting\": true, \"deleteMissing\": true}, \"groups\": {\"createMissing\": true}}}, \"auth\": \"2d9c9fdd1a34b73ef403dfd9c1438b50\"}"
}
pyrodie18 commented 7 months ago

I don't see what version of the collection you're running but we don't currently support anything before Zabbix 6.0

djdejawu commented 7 months ago

Currently I'm using latest one. community.zabbix 2.3.1 Why 5th version doesn't supported? It's LTS.

pyrodie18 commented 7 months ago

Because we only support "fully supported" versions. https://github.com/ansible-collections/community.zabbix?tab=readme-ov-file#supported-zabbix-versions

pyrodie18 commented 7 months ago

If you use a version of the collection < 2.0 you should be good.