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 A
    • Sprint 82 (Nov 2021), Sprint 83 (Dec 2021)
    • 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

        Activity

          People

            zabbix.dev Zabbix Development Team
            solonkins Sergejs Olonkins
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: