Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-20263

It is possible to simultaneously link 2 templates with matching item keys to a template or host

XMLWordPrintable

    • Sprint 82 (Nov 2021), Sprint 83 (Dec 2021), Sprint 84 (Jan 2022), Sprint 85 (Feb 2022), Sprint 86 (Mar 2022), Sprint 87 (Apr 2022), Sprint 88 (May 2022), Sprint 89 (Jun 2022), Sprint 90 (Jul 2022), Sprint 91 (Aug 2022), Sprint 92 (Sep 2022), Sprint 93 (Oct 2022), Sprint 94 (Nov 2022), Sprint 95 (Dec 2022), Sprint 96 (Jan 2023), Sprint 97 (Feb 2023), Sprint 98 (Mar 2023), Sprint 99 (Apr 2023), Sprint 100 (May 2023), Sprint 101 (Jun 2023)
    • 1

      Problem description:
      In Zabbix 5.0, 5.4 and 6.0 it is possible to create two templates having items with the same keys and then successfully link both templates to another template or host.
      In Zabbix 4.0 simultaneous linkage of two templates with matching item keys to another template results in a database error like below:

      pg_query(): Query failed: ERROR: duplicate key value violates unique constraint "items_1"
      DETAIL: Key (hostid, key_)=(99066, agent.ping) already exists. [templates.php:240 → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → CTemplate->update() → CTemplate->massUpdate() → CTemplate->massAdd() → CHostGeneral->massAdd() → CHostGeneral->link() → CItem->syncTemplates() → CItemGeneral->inherit() → CItemGeneral->_inherit() → CItem->createReal() → DB::insert() → DB::insertBatch() → DBexecute() → pg_query() in include/db.inc.php:487]
      Error in query [INSERT INTO items (type,snmp_community,snmp_oid,hostid,name,description,key_,master_itemid,delay,history,trends,status,value_type,trapper_hosts,units,snmpv3_contextname,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authprotocol,snmpv3_authpassphrase,snmpv3_privprotocol,snmpv3_privpassphrase,formula,logtimefmt,valuemapid,params,ipmi_sensor,authtype,username,password,publickey,privatekey,flags,port,inventory_link,lifetime,jmx_endpoint,url,timeout,query_fields,posts,status_codes,follow_redirects,post_type,http_proxy,headers,retrieve_mode,request_method,output_format,allow_traps,ssl_cert_file,ssl_key_file,ssl_key_password,verify_peer,verify_host,templateid,itemid) VALUES ('0','','','99066','Admin','','agent.ping',NULL,'30s','90d','365d','0','3','','','','','0','0','','0','','','',NULL,'','','0','','','','','0','','0','30d','','','3s','','','200','1','0','','','0','0','0','0','','','','0','0','99096','99098'),('0','','','99066','222','','agent.ping',NULL,'30s','90d','365d','0','3','','','','','0','0','','0','','','',NULL,'','','0','','','','','0','','0','30d','','','3s','','','200','1','0','','','0','0','0','0','','','','0','0','99097','99099')] [ERROR: duplicate key value violates unique constraint "items_1"
      DETAIL: Key (hostid, key_)=(99066, agent.ping) already exists.]
      SQL statement execution has failed "INSERT INTO items (type,snmp_community,snmp_oid,hostid,name,description,key_,master_itemid,delay,history,trends,status,value_type,trapper_hosts,units,snmpv3_contextname,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authprotocol,snmpv3_authpassphrase,snmpv3_privprotocol,snmpv3_privpassphrase,formula,logtimefmt,valuemapid,params,ipmi_sensor,authtype,username,password,publickey,privatekey,flags,port,inventory_link,lifetime,jmx_endpoint,url,timeout,query_fields,posts,status_codes,follow_redirects,post_type,http_proxy,headers,retrieve_mode,request_method,output_format,allow_traps,ssl_cert_file,ssl_key_file,ssl_key_password,verify_peer,verify_host,templateid,itemid) VALUES ('0','','','99066','Admin','','agent.ping',NULL,'30s','90d','365d','0','3','','','','','0','0','','0','','','',NULL,'','','0','','','','','0','','0','30d','','','3s','','','200','1','0','','','0','0','0','0','','','','0','0','99096','99098'),('0','','','99066','222','','agent.ping',NULL,'30s','90d','365d','0','3','','','','','0','0','','0','','','',NULL,'','','0','','','','','0','','0','30d','','','3s','','','200','1','0','','','0','0','0','0','','','','0','0','99097','99099')". [templates.php:240 → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → CTemplate->update() → CTemplate->massUpdate() → CTemplate->massAdd() → CHostGeneral->massAdd() → CHostGeneral->link() → CItem->syncTemplates() → CItemGeneral->inherit() → CItemGeneral->_inherit() → CItem->createReal() → DB::insert() → DB::insertBatch() → DB::exception() in include/classes/db/DB.php:517]
      

      Steps to reproduce:

      1. Create two templates with an item with key "agent.ping"
      2. Simultaneously link both of these templates to some 3rd template
        Result 4.0: the above error is observed.
        Result 5.0+ : both templates are successfully linked to the 3rd template, even though the keys of items in these templates match.
      3. Attempt to link this 3rd template to a Host.

      Result 5.0+ : Template is successfully linked to host. The host now has two items with exactly the same key.
      Expected: in all zabbix versions it should not be possible to link templates with same item keys to another template or host in the first place. In this case a human readable error should be shown when attempting to link the two templates to the 3rd template, instead of the huge database error.

      Example:

        1. 6_template_link.gif
          2.02 MB
          Kirils Seve
        2. error_message.gif
          922 kB
          Kirils Seve
        3. image-2022-07-27-09-18-36-760.png
          26 kB
          Kirils Seve
        4. image-2022-07-27-09-19-23-498.png
          18 kB
          Kirils Seve
        5. image-2022-07-27-09-19-48-129.png
          19 kB
          Kirils Seve
        6. image-2022-07-27-09-20-23-349.png
          17 kB
          Kirils Seve
        7. image-2023-04-11-11-02-36-561.png
          21 kB
          Vladimirs Maksimovs
        8. image-2023-04-18-11-11-13-442.png
          7 kB
          Kirils Seve
        9. image-2023-04-28-12-04-29-715.png
          20 kB
          Kirils Seve
        10. linking_templates_with_matching_items.gif
          3.21 MB
          Sergejs Olonkins
        11. MicrosoftTeams-image (2).png
          146 kB
          Vladimirs Maksimovs
        12. screenshot-1.png
          39 kB
          Kirils Seve
        13. screenshot-10.png
          10 kB
          Kirils Seve
        14. screenshot-2.png
          25 kB
          Kirils Seve
        15. screenshot-3.png
          26 kB
          Kirils Seve
        16. screenshot-4.png
          47 kB
          Kirils Seve
        17. screenshot-5.png
          43 kB
          Kirils Seve
        18. screenshot-6.png
          11 kB
          Kirils Seve
        19. screenshot-7.png
          11 kB
          Kirils Seve
        20. screenshot-8.png
          47 kB
          Kirils Seve
        21. screenshot-9.png
          121 kB
          Kirils Seve
        22. subbisue14_templates.yaml
          1.0 kB
          Kirils Seve
        23. subissue14_hosts.yaml
          0.8 kB
          Kirils Seve
        24. subissue15_templates.yaml
          1 kB
          Kirils Seve
        25. template_link_twice.gif
          1.55 MB
          Kirils Seve
        26. validation_error_5.0.gif
          1002 kB
          Kirils Seve
        27. ZBX-20263-5.0.patch
          0.8 kB
          Miks Kronkalns

            vmaksimovs Vladimirs Maksimovs
            solonkins Sergejs Olonkins
            Team C
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: