configuration.importcompare and configuration.import not handling existing groups

XMLWordPrintable

    • Type: Incident report
    • Resolution: Won't fix
    • Priority: Trivial
    • None
    • Affects Version/s: 6.0.0beta2
    • Component/s: None
    • None
    • Environment:
      Ubuntu 20

      Steps to reproduce:

      1. compareimport or import template with a group that already exists using the zabbix api 

      Result:

      Using these import rules for both the compare and the import

      import_rules = {    "groups": {        "createMissing": True,        "updateExisting": True    },    "templates": {        "createMissing": True,        "updateExisting": True    },    "items": {        "createMissing": True,        "updateExisting": True,        "deleteMissing": True    },    "triggers": {        "createMissing": True,        "updateExisting": True,        "deleteMissing": True    },    "discoveryRules": {        "createMissing": True,        "updateExisting": True,        "deleteMissing": True    },    "valueMaps": {        "createMissing": True,        "updateExisting": False    }} 

      The first line of the output is the result of the compare, saying it will be creating the group `ns-templates` which already exists in Zabbix. After that is the output of trying to import the template, complaining that the group already exists.

      {'groups': {'added': [{'after': {'name': 'ns-templates', 'uuid': 'c717c32d0d6548339ab9f49faa1049a1'}}]}, 'templates': {'added': [{'after': {'template': 'test', 'name': 'test', 'uuid': '098f6bcd462143738ade4e832627b4f6'}}]}}
      Traceback (most recent call last):
        File "./import_templates.py", line 102, in <module>
          main()
        File "./import_templates.py", line 98, in main
          import_template(z, template)
        File "./import_templates.py", line 87, in import_template
          template_import = z.configuration.import_({"format":"json", "rules": import_rules['import'], "source": json.dumps(template_json)})
        File "/usr/local/lib/python3.8/dist-packages/zabbix_api.py", line 341, in method
          return self.universal("%s.%s" % (self.data["prefix"], name), opts[0])
        File "/usr/local/lib/python3.8/dist-packages/zabbix_api.py", line 79, in wrapper
          return self.do_request(self.json_obj(method, opts))['result']
        File "/usr/local/lib/python3.8/dist-packages/zabbix_api.py", line 348, in do_request
          return self.parent.do_request(req)
        File "/usr/local/lib/python3.8/dist-packages/zabbix_api.py", line 297, in do_request
          raise Already_Exists(msg, jobj['error']['code'])
      zabbix_api.Already_Exists: ('Error -32602: Invalid params., Host group "ns-templates" already exists. while sending {"jsonrpc": "2.0", "method": "configuration.import", "params": {"format": "json", "rules": {"groups": {"createMissing": true, "updateExisting": true}, "templates": {"createMissing": true, "updateExisting": true}, "items": {"createMissing": true, "updateExisting": true, "deleteMissing": true}, "triggers": {"createMissing": true, "updateExisting": true, "deleteMissing": true}, "discoveryRules": {"createMissing": true, "updateExisting": true, "deleteMissing": true}, "valueMaps": {"createMissing": true, "updateExisting": false}}, "source": "{\\"zabbix_export\\": {\\"groups\\": [{\\"name\\": \\"ns-templates\\"}], \\"date\\": \\"2022-01-19T20:27:38Z\\", \\"version\\": \\"4.2\\", \\"templates\\": [{\\"screens\\": [], \\"groups\\": [{\\"name\\": \\"ns-templates\\"}], \\"description\\": \\"\\", \\"applications\\": [], \\"template\\": \\"test\\", \\"httptests\\": [], \\"templates\\": [], \\"discovery_rules\\": [], \\"name\\": \\"test\\", \\"macros\\": [], \\"items\\": [], \\"tags\\": []}]}}"}, "auth": "__REDACTED__", "id": 2}', -32602)

      Expected:
      Expect the API to see that the group already exists and assign that group rather than trying to create it again even though it already exists.

            Assignee:
            Igor Gorbach (Inactive)
            Reporter:
            Robert Jorgenson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: