[ZBX-4134] It is possible to create duplicate objects using API in parallel requests Created: 2011 Sep 12  Updated: 2024 Apr 10

Status: Confirmed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A), Frontend (F)
Affects Version/s: 1.8.5, 3.0.5, 3.2.0
Fix Version/s: None

Type: Problem report Priority: Critical
Reporter: Igor Danoshaites (Inactive) Assignee: Alexei Vladishev
Resolution: Unresolved Votes: 19
Labels: api, consistency, duplicates
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Zabbix_DB_hosts_table.png     PNG File duplicate_hosts_created_using_API.png     PNG File host1.png     PNG File host2.png     PNG File hosts.png     PNG File proxies.png     PNG File triggers.png    
Issue Links:
Causes
Duplicate
is duplicated by ZBX-5868 It's possible to create Graphs with d... Closed
is duplicated by ZBX-12017 Simultaneous API calls cause duplicat... Closed
is duplicated by ZBX-13087 Host group name is not unique Closed
is duplicated by ZBX-13771 Duplicate Host Creation using Auto Re... Closed
is duplicated by ZBX-21464 Creating multiple identical hosts via... Closed
Sub-task
depends on ZBX-22154 Errors occur when the PostgreSQL tran... Confirmed
depends on ZBX-22162 Transactions deadlock detected during... Confirmed
Team: Team A

 Description   

It is possible to create hosts with duplicate hostnames using API, when several simultaneously running processes are trying to create hosts with the same name.

We should think about the possibility how to get rid of such cases.



 Comments   
Comment by ojab [ 2012 Nov 17 ]

I have the same issue with Graphs on zabbix-2.1.0 (it's possible to create graphs with duplicate names and the same host using API).
Should I create new issue for that?

Comment by richlv [ 2012 Nov 17 ]

yes, please do so (unless it's reported already)

Comment by ojab [ 2012 Nov 17 ]

Done, ZBX-5868.

Comment by Oleksii Zagorskyi [ 2016 Dec 06 ]

A practical way how to reproduce it:

curl -i -X POST -H 'Content-Type: application/json-rpc' -d '{"params": {"rules": {"templateLinkage": {"createMissing": "true"}, "hosts": {"createMissing": "true", "updateExisting": "true"}, "groups": {"createMissing": "true"}}, "source": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><zabbix_export><version>2.0</version><date>2015-09-15T23:41:53Z</date><groups> <group><name>Load Balancer</name> </group></groups><hosts> <host><host>Load Balancer node100</host><name>Load Balancer node100</name><description>satellite Load Balancer: node100 </description><proxy/><status>0</status><ipmi_authtype>-1</ipmi_authtype><ipmi_privilege>2</ipmi_privilege><ipmi_username/><ipmi_password/><groups><group><name>Load Balancer</name></group></groups><interfaces><interface><default>1</default><type>1</type><useip>1</useip><ip>10.33.0.100</ip><dns></dns><port>10050</port><bulk>1</bulk><interface_ref>if1</interface_ref> </interface></interfaces><applications/><items/><discovery_rules/><macros/><inventory/> </host></hosts></zabbix_export>", "format": "xml"}, "jsonrpc": "2.0", "method": "configuration.import","auth": "f45f05ddc5558a7c3a1c72db15162a20", "id": 0}' http://localhost/zabbix/api_jsonrpc.php & \
curl -i -X POST -H 'Content-Type: application/json-rpc' -d '{"params": {"rules": {"templateLinkage": {"createMissing": "true"}, "hosts": {"createMissing": "true", "updateExisting": "true"}, "groups": {"createMissing": "true"}}, "source": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><zabbix_export><version>2.0</version><date>2015-09-15T23:41:53Z</date><groups> <group><name>Load Balancer</name> </group></groups><hosts> <host><host>Load Balancer node101</host><name>Load Balancer node101</name><description>satellite Load Balancer: node101 </description><proxy/><status>0</status><ipmi_authtype>-1</ipmi_authtype><ipmi_privilege>2</ipmi_privilege><ipmi_username/><ipmi_password/><groups><group><name>Load Balancer</name></group></groups><interfaces><interface><default>1</default><type>1</type><useip>1</useip><ip>10.33.0.100</ip><dns></dns><port>10050</port><bulk>1</bulk><interface_ref>if1</interface_ref> </interface></interfaces><applications/><items/><discovery_rules/><macros/><inventory/> </host></hosts></zabbix_export>", "format": "xml"}, "jsonrpc": "2.0", "method": "configuration.import","auth": "f45f05ddc5558a7c3a1c72db15162a20", "id": 0}' http://localhost/zabbix/api_jsonrpc.php

note - replace auth token by yours.

This example creates duplicated host groups.
If you change host name to identical - hosts will be duplicated too.

I've faced with this because I use ansible for a fully automated deploying of zabbix installations with some pre-configuration.
Ansible performs tasks for different targets is parallel, the issue is reproducible in my case for 100%. Using zabbix 3.0.6

Comment by Oleksii Zagorskyi [ 2017 Feb 03 ]

ZBX-5705 contains another particular example how to create duplicates.

Comment by Oleksii Zagorskyi [ 2017 Feb 10 ]

Similar problem for server side reported in ZBX-11799

Comment by Dmitry Verkhoturov [ 2017 Feb 21 ]

This bug results in "Template cannot be linked to another template more than once even through other templates." messages, I've created a patch for 3.0 and 3.2 which show templateid which causes the problem in error message.
Patch is available by name ZBX-5470 in https://github.com/zabbix/zabbix-patches repo, feel free to use it.

Comment by Oleksii Zagorskyi [ 2017 Feb 21 ]

How can you prove that duplicated objects caused the error message ?

Comment by Dmitry Verkhoturov [ 2017 Feb 21 ]

In my case something impossible by Zabbix logic was done via API, which is a bug and I think it is this very bug (it might be not). I am not reporting the bug or adding any information to it, I just giving away a troubleshooting improvement which might help to locate the problem.

Comment by Oleksii Zagorskyi [ 2017 Feb 21 ]

My doubts are directed to the reason why did you get the error message.
I.e. I'm not sure that duplicated objects were the reason. I think that current report is not related to the error you had.

Comment by Minjie Zhang [ 2017 May 05 ]

I have the same issue, multiple hosts created with the same name.
None of these hosts can get monitor data in History any more, even after I deleted the duplicated hosts, and only left one host with unique name (zabbix server also restarted).

Comment by Oleksii Zagorskyi [ 2019 Jan 25 ]

Multiple entries for ServerActive (localhost and another interface IP) cause duplicated host names creation during agents auto-registration.
Yes, that's misconfiguration, but still.

Comment by Oleksii Zagorskyi [ 2020 Jun 25 ]

One more visible sub-issue:
when creating hosts in parallel and linking a template (having triggers or prototypes), it's possible one of those host will get doubled count of triggers from the template, while 2nd host will get 0 triggers inherited.
I.e. on one host triggers/prototypes will be be duplicated: two on a host inherited from single on template.

Comment by dimir [ 2022 Jun 13 ]

After discussion with asitals:

How about splitting current status column.

Current implementation

status 0, HOST_STATUS_MONITORED - Host is monitored
1, HOST_STATUS_NOT_MONITORED - Host is not monitored
3, HOST_STATUS_TEMPLATE - The record is template
5, HOST_STATUS_PROXY_ACTIVE - The record is active proxy
6, HOST_STATUS_PROXY_PASSIVE - The record is passive proxy

Suggested implementation

Split current status column that mixes host/proxy status and the type of the record into 3 dedicated columns:

  • leave status column for host status
  • add proxy_status column
  • add type column to indicate record type:
status 0, HOST_STATUS_MONITORED - Host is monitored
1, HOST_STATUS_NOT_MONITORED - Host is not monitored
proxy_status 0, HOST_STATUS_PROXY_ACTIVE - The record is active proxy
1, HOST_STATUS_PROXY_PASSIVE - The record is passive proxy
type 0, HOST_TYPE_HOST - The record is host
1, HOST_TYPE_TEMPLATE - The record is template
2, HOST_TYPE_PROXY - The record is proxy

Pros:

  • prevent duplicates by adding UNIQUE INDEX ON `hosts`(host, type)
  • allow disabling a Proxy

Cons:

  • host prototypes, there might be a need to allow host prototypes with the same name

Questions:

  • Should host prototype be treated as separate type?
  • Should Zabbix API continue providing only "status" field (API users will not have to change their scripts)?
Generated at Thu Apr 25 22:44:45 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.