saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.17k stars 5.48k forks source link

[BUG]: zabbix.run_query configuration.import does not update objects, but creates new objects #60614

Closed misch42 closed 3 years ago

misch42 commented 3 years ago

Description running the zabbix.run_query with the configuation.import method to update a template does not work correcty. Instead of updating an existing trigger in a template it creates a new trigger in the template.

Setup state:

{% set template_source = salt.cp.get_file_str('salt://zabbix/templates/imap_template.yaml') %}

zabbix.run_query:
  module.run:
    - method: configuration.import
    - params:
        format: yaml
        source: |
          {{ template_source | indent(10) }}
        rules:
          templates:
            createMissing: true
            updateExisting: true
          applications:
            createMissing: true
          items:
            updateExisting: true
            createMissing: true
          triggers:
            updateExisting: true
            createMissing: true

template:

zabbix_export:
  version: '5.2'
  date: '2021-07-23T17:37:28Z'
  groups:
    - name: Templates
    - name: Mailstore
  templates:
    -
      template: IMAP_Service_2
      name: IMAP_Service2
      groups:
        - name: Templates
        - name: Mailstore
      applications:
        - name: 'IMAP Service2'
      items:
        - 
          name: check_imap2
          type: EXTERNAL
          key: 'check_imap.sh["{HOST.NAME}"]'
          trends: '0'
          value_type: TEXT
          description: 'output of the check_imap2 script. Output is JSON that need to be parsed afterwards in dependent items.'
          applications:
            - name: 'IMAP Service2'
        -
          name: imap_code2
          type: DEPENDENT
          key: imap_code2
          delay: '0'
          description: 'Return code of the curl command.'
          applications:
            -
              name: 'IMAP Service2'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - $.code
          master_item:
            key: 'check_imap.sh["{HOST.NAME}"]'
          triggers:
            -
              expression: '{last()}>0'
              name: 'IMAP Acess to test mailbox'
              priority: WARNING
              description: 'The return code of the curl command was {ITEM.VALUE1}.'

applying the state once, works without problems. It creates the template within zabbix. But changing the expression from {last()}>0 to {last()}=0 it should update the existing trigger. But instead applying the state creates a new trigger with the same name but a different expression.

Steps to Reproduce the behavior See above.

Expected behavior The state should update the existing trigger to reflect the changed template.

Screenshots If applicable, add screenshots to help explain your problem.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ``` Salt Version: Salt: 3001.6 Dependency Versions: cffi: 1.14.0 cherrypy: Not Installed dateutil: 2.8.1 docker-py: Not Installed gitdb: 4.0.5 gitpython: 3.1.8 Jinja2: 2.11.2 libgit2: 1.0.1 M2Crypto: 0.36.0 Mako: Not Installed msgpack-pure: Not Installed msgpack-python: 1.0.0 mysql-python: Not Installed pycparser: 2.20 pycrypto: 3.9.8 pycryptodome: 3.9.8 pygit2: 1.3.0 Python: 3.7.9 (default, Nov 3 2020, 12:10:17) python-gnupg: 0.4.6 PyYAML: 5.3.1 PyZMQ: 19.0.1 smmap: 3.0.4 timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.3.3 System Versions: dist: gentoo 2.7 locale: UTF-8 machine: x86_64 release: 4.9.74-grsecurity system: Linux version: Gentoo 2.7 ```

Additional context Add any other context about the problem here.

piterpunk commented 3 years ago

@misch42

This is not related to Salt, but with how the Zabbix API does the trigger match. It uses the expression as part of match properties. Try to change, instead of the expression, the priority from WARNING to HIGH.

The behaviour of zabbix.run_query is totally dependent of Zabbix API, it is a direct call, without treatment. To be fair with zabbix execution module, the idempotent warranties are in the state modules, not the execution ones.

misch42 commented 3 years ago

Thought that this might be an issue with the Zabbix API. Thanks for the clarification.

misch42 commented 3 years ago

Update to the problem: rules.trigger also have an attribute deleteMissing. Setting this to true results in deleting the old trigger and adding a new one. i.e.:

params:
  rules:
    triggers:
      updateExisting: true
      createMissing: true
      deleteMissing: true