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

Details

    • Team C
    • 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)
    • 1

    Description

      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:

      Attachments

        1. error_message.gif
          error_message.gif
          922 kB
        2. image-2022-07-27-09-18-36-760.png
          image-2022-07-27-09-18-36-760.png
          26 kB
        3. image-2022-07-27-09-19-23-498.png
          image-2022-07-27-09-19-23-498.png
          18 kB
        4. image-2022-07-27-09-19-48-129.png
          image-2022-07-27-09-19-48-129.png
          19 kB
        5. image-2022-07-27-09-20-23-349.png
          image-2022-07-27-09-20-23-349.png
          17 kB
        6. linking_templates_with_matching_items.gif
          linking_templates_with_matching_items.gif
          3.21 MB
        7. MicrosoftTeams-image (2).png
          MicrosoftTeams-image (2).png
          146 kB
        8. screenshot-1.png
          screenshot-1.png
          39 kB
        9. screenshot-2.png
          screenshot-2.png
          25 kB
        10. screenshot-3.png
          screenshot-3.png
          26 kB
        11. screenshot-4.png
          screenshot-4.png
          47 kB
        12. screenshot-5.png
          screenshot-5.png
          43 kB
        13. screenshot-6.png
          screenshot-6.png
          11 kB
        14. screenshot-7.png
          screenshot-7.png
          11 kB
        15. screenshot-8.png
          screenshot-8.png
          47 kB
        16. ZBX-20263-5.0.patch
          0.8 kB

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: