Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-24662

Confusing error when creating many hosts with zabbix API

XMLWordPrintable

    • Icon: Incident report Incident report
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 7.0.0
    • API (A), Frontend (F)
    • None

      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. 

            zabbix.dev Zabbix Development Team
            bmickiewicz Bartosz Mickiewicz (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: