[ZBX-19726] API configuration.import does not update a trigger but creates a now one Created: 2021 Jul 23  Updated: 2022 Oct 08

Status: Confirmed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 5.0.14
Fix Version/s: None

Type: Problem report Priority: Trivial
Reporter: Michael Schwartzkopff Assignee: Zabbix Development Team
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Zabbix with saltstack using the API and configuration.import.

Zabbix 5.2


Attachments: GIF File Zabbix_2021_08_01_10-trigger-expression-change-results-duplicating-trigger-after-configuration-import.gif    

 Description   

Steps to reproduce:

I use saltstack to provision monitring, but I think the error lies within Zabbix API. Basically I use the zabbix API to create templates. After a change in the template source I also want to update zabbix. But this fails. The API create a new trigger instead of updating the existing one.

 

Creation of the template with the following yaml works:

 

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}.'

Now I want to update that template with the expression "

{last()}

=0". Running the API call creates a new trigger in the template instead of updating the existing one. My saltstack state is

 

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

Result:

Additional trigger with the new expression created. The API by the way, does not complain about any error.

Expected:
Update the existing trigger with the new expression.



 Comments   
Comment by Antons Sincovs [ 2021 Aug 01 ]

Dear Michael!

In the field "Affects Verion/s" you have specified version "5.0.14" - but when exporting the template - the second line states " version: '5.2'". So which version are we talking about?
Configuration export to YAML has only become possible starting with Zabbix version 5.2, please notice that for versions 5.0.x only JSON and XML formats are supported for configuation export .

But still I have been able to replicate the issue in Zabbix 5.0.13 with export and import in JSON format. After the export I have changed the trigger evaluation expression from ">" to "=" and when importing and additional trigger with "=" has been created instead of updating the existing one. Also tested with the "createMissing" rule for "triggers" set to "false" and "updateExisting" set to "true" - the API call's result still was "true" but had no impact on the trigger at all.

Thank you for the enquiry.

Kind regards,

Antons Sincovs

Comment by Michael Schwartzkopff [ 2021 Aug 01 ]

Hi,

 

I exported the template from a 5.2 version and did my test on a 5.0.14 version. But I think that is a basic problem of zabbix import. Piter Punk who helped me setting up the salt formula to configure Zabbix pointed out that Zabbix API uses the expression as a part of the match properties of a trigger. That would be really undesirable, because to update a trigger, I would have to delete old one and then add a new one. See: https://github.com/saltstack/salt/issues/60614

Comment by Michael Schwartzkopff [ 2021 Aug 01 ]

Are you going to fix this?

 

I would help my work a lot.

Comment by Antons Sincovs [ 2021 Aug 01 ]

Dear Michael!

I have passed the inquiry to our development team for a review. You can follow the ZBX for status updates.

Meanwhile you can try to make use of additional parameter in the "configuration.import" API method:

deleteMissing - (boolean) if set to true, triggers not present in the imported data will be deleted from the database; default: false.

and combine it this with:

 "createMissing":true

Thus all the triggers not present in the template which is being imported will be deleted and those triggers that are present in the imported configuration will be created:

 "triggers":{
                "createMissing":true,
                "updateExisting": false,
                "deleteMissing":true
            }

I have tested this with the case you provided and it got the expected result.

Alternatively you can try to work with trigger object using its specific API methods - like "trigger.update".

Kind regards,
Antons Sincovs

Comment by Michael Schwartzkopff [ 2021 Aug 01 ]

Nice idea. I will give it a try.

Comment by Michael Schwartzkopff [ 2021 Aug 06 ]

hi,

 

deleteMissing: true works for me. Thanks for the hint.

 

Fixing the code would be better anyway.

Generated at Sat Mar 15 09:54:56 EET 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.