[ZBX-24662] Confusing error when creating many hosts with zabbix API Created: 2024 Jun 17  Updated: 2024 Jun 19  Resolved: 2024 Jun 18

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A), Frontend (F)
Affects Version/s: 7.0.0
Fix Version/s: None

Type: Incident report Priority: Minor
Reporter: Bartosz Mickiewicz (Inactive) Assignee: Zabbix Development Team
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Causes
Duplicate
duplicates ZBX-24622 Impossible to perform many hosts mass... Closed

 Description   

I’ve created a python script, to replicate this issue:

#!/usr/bin/env python3

import json, requests

# Functions
def zabbixApi(method, params):
    response = requests.post('https://localhost/api_jsonrpc.php', verify=False, headers={'Content-Type': 'application/json-rpc'}, json={
        'jsonrpc': '2.0',
        'auth': 'redacted',
        'id': 'id',
        'method': method,
        'params': params,
    })
    response.raise_for_status()

    if 'error' in response.json(): raise Exception('Zabbix error (%s)' % response.json()['error'])
    if response.json()['id'] != 'id': raise Exception('Invalid result')

    return response.json()['result']

# Main
if __name__ != '__main__':
    raise Exception('Not meant to be run as a module.')

requests.packages.urllib3.disable_warnings(category=requests.packages.urllib3.exceptions.InsecureRequestWarning)

zabbixApi('host.create', [{
    'host': 'test host '+str(i),
    'tags': [ { 'tag': 'imported', 'value': 'yes' } ],
    'groups': [ { 'groupid': '32' } ],
    'templates': [ { 'templateid': '10351' } ],
    'tls_connect': 2,
    'tls_accept': 2,
    'tls_psk_identity': 'test',
    'tls_psk': 'redacted',
} for i in list(range(300))])

When i run it, i get errors like this:

capmon@docker01 ~ $ ./bugtest.py 
Traceback (most recent call last):
  File "/home/capmon/./bugtest.py", line 32, in <module>
    zabbixApi('host.create', [{
  File "/home/capmon/./bugtest.py", line 18, in zabbixApi
    if 'error' in response.json(): raise Exception('Zabbix error (%s)' % response.json()['error'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: Zabbix error ({'code': -32602, 'message': 'Invalid params.', 'data': 'Cannot inherit item with key "vm.memory.size[used]" of template "Windows by Zabbix agent active" to host "test host 100", because an item with the same key is already inherited from template "Windows by Zabbix agent active".'})

If i only add 100 hosts it works. 



 Comments   
Comment by Vladimirs Maksimovs [ 2024 Jun 18 ]

This issue will be fixed in ZBX-24622, and therefore should be closed.

Generated at Wed Jul 09 12:47:48 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.