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

Import template by API successful response but no hosts row

    XMLWordPrintable

Details

    • Problem report
    • Status: Closed
    • Trivial
    • Resolution: Won't fix
    • 5.4.0
    • None
    • API (A)
    • None

    Description

      Steps to reproduce:

      **Make any valid template. Here's a super-simple TEST:

      {{{{ "zabbix_export": { "groups": [

      { "name": "Zabbix servers",  "uuid": "6f6799aa69e844b4b3918f779f2abf08" }

      ],  "templates": [ { "groups": [

      { "name": "Zabbix servers" }

      ],  "name": "TEST",  "template": "TEST",  "uuid": "e4ad7acc1a804011b7b8161663e1f31b" } ],  "version": "5.4" }}}}

       

      ++Import (in my case with Ansible) - I am NOT using the zabbix_template module which right now seems to be broken with 5.4, because they are still trying to set "applications"

      Ansible task for reference:

      {norformat}
      - name: Zabbix API - Import template
      uri:
      url: "https://{{ cert_domain }}.{{ domain }}/api_jsonrpc.php"
      method: POST
      body: "{{ lookup('template','/etc/ansible/enlite/files/zabbix/template.import.test.json.j2') }}"
      body_format: json
      return_content: yes
      register: api_result
      failed_when: "'error' in api_result.content"

      - debug:
      var: api_result{norformat}

       and template.import.test.json.j2 contents:

      {
          "jsonrpc": "2.0",
          "method": "configuration.import",
          "params": {
              "format": "xml",
              "rules": {
                  "valueMaps": {
                      "createMissing": true,
                      "updateExisting": false
                  },
                  "hosts": {
                      "createMissing": true,
                      "updateExisting": true
                  },
                  "items": {
                      "createMissing": true,
                      "updateExisting": true,
                      "deleteMissing": true
                  }
              },
              "source": "<zabbix_export><version>5.4</version><groups><group><uuid>f2481361f99448eea617b7b1d4765566</uuid><name>Discovered hosts</name></group></groups><templates><template><uuid>62925bc2fc844fa6a531cbb6d5515d65</uuid><template>TEST</template><name>TEST</name><groups><group><name>Discovered hosts</name></group></groups></template></templates></zabbix_export>"
          },
          "auth": "{{ auth_token }}",
          "id": 1
      }
      

      Result:

      SEEMS successful:

      {norformat}
      "json": { "id": 1, "jsonrpc": "2.0", "result": true }{norformat}

       

      Full Ansible task output:

      {norformat}
      TASK [Zabbix API - Import template] ********************************************
      ok: [localhost]

      TASK [debug] *******************************************************************
      ok: [localhost] => {
      "api_result": {
      "access_control_allow_headers": "Content-Type",
      "access_control_allow_methods": "POST",
      "access_control_allow_origin": "*",
      "access_control_max_age": "1000",
      "changed": false,
      "connection": "close",
      "content": "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}",
      "content_security_policy_report_only": "default-src https:; script-src https: 'unsafe-eval' 'unsafe-inline'; style-src https: 'unsafe-inline'; img-src https: data:; font-src https: data:; report-uri /csp-report",
      "content_type": "application/json",
      "cookies": {},
      "cookies_string": "",
      "date": "Fri, 28 May 2021 18:21:29 GMT",
      "elapsed": 0,
      "failed": false,
      "failed_when_result": false,
      "json": { "id": 1, "jsonrpc": "2.0", "result": true },
      "msg": "OK (unknown bytes)",
      "redirected": false,
      "server": "nginx",
      "status": 200,
      "strict_transport_security": "max-age=31536000; preload",
      "transfer_encoding": "chunked",
      "url": "https://dev-monitor.intertalk.cloud/api_jsonrpc.php",
      "x_powered_by": "PHP/7.4.19"
      }
      }{norformat}

       

      However, no template was imported. This is best reflected in the DB:

      {norformat}
      mysql> select * from hosts where uuid = 'e4ad7acc1a804011b7b8161663e1f31b';
      Empty set (0.00 sec){norformat}

       

      But of course you can see this in the GUI by the lack of the "TEST" template:

      Expected:
      I expect it to create the row for the template in the hosts table, and to show up in the GUI list.

      NOTES:

      • Import works using the same json if performed via the GUI. The problem is only encountered with API.
      • I'm showing a very simple one but you can test with any template.

      Attachments

        Activity

          People

            igorbach Igor Gorbach
            Warren Josh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: