-
Problem report
-
Resolution: Fixed
-
Trivial
-
4.0.37rc1, 5.0.18rc1, 5.4.9rc1, 6.0.0beta1
-
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:
- Create two templates with an item with key "agent.ping"
- 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. - 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.