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

Zabbix 4.2.3 error Incorrect item key when importing configuration by api

XMLWordPrintable

    • Team B
    • Sprint 56 (Sep 2019), Sprint 57 (Oct 2019)
    • 0.1

      Error 1:
      1.Create a template.
      2. In it, we create a web verification script:

      3. Create a verification step:

      4. Create a trigger for this step:

      5. We export by api in json format. I make it with bash script:
      Code:

      #!/bin/bash auth=$(curl -s -H "Content-Type: application/json-rpc" -X POST 'localhost/zabbix/api_jsonrpc.php' -d ' {"jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "ХХХХХХХХХХХХ"},"id": 1,"auth": null}' | jq '.result') test=$(curl -s -H "Content-Type: application/json-rpc" -X POST 'zabbix-1/zabbix/api_jsonrpc.php' -d "{\"jsonrpc\": \"2.0\",\"method\": \"template.get\",\"params\": {\"output\": \"extend\",\"filter\": {\"host\": [\"Test\"]}},\"auth\": $auth,\"id\": 8}" | jq '.result[0].templateid') curl -s -H "Content-Type: application/json-rpc" -X POST 'zabbix-1/zabbix/api_jsonrpc.php' -d "{\"jsonrpc\": \"2.0\",\"method\": \"configuration.export\",\"params\": {\"options\": {\"templates\": [$test]},\"format\": \"json\"},\"auth\": $auth,\"id\": 14}" | jq '.result' > test.txt
       In response, we get:

      Code:

      "{\"zabbix_export\":{\"version\":\"4.2\",\"date\":\"2019-08-27T11:49:48Z\",\"groups\":[\{\"name\":\"Test\"}],\"templates\":[{\"template\":\"Test\",\"name\":\"Test\",\"description\":\"\",\"groups\":[\{\"name\":\"Test\"}],\"applications\":[],\"items\":[],\"discovery_rules\":[],\"httptests\":[{\"name\":\"Test\",\"application\":null,\"delay\":\"1m\",\"attempts\":\"1\",\"agent\":\"Zabbix\",\"http_proxy\":\"\",\"variables\":[],\"headers\":[],\"status\":\"0\",\"authentication\":\"0\",\"http_user\":\"\",\"http_password\":\"\",\"verify_peer\":\"0\",\"verify_host\":\"0\",\"ssl_cert_file\":\"\",\"ssl_key_file\":\"\",\"ssl_key_password\":\"\",\"steps\":[{\"name\":\"test\",\"url\":\"google.com\",\"query_fields\":[],\"posts\":[],\"variables\":[],\"headers\":[],\"follow_redirects\":\"1\",\"retrieve_mode\":\"0\",\"timeout\":\"15s\",\"required\":\"\",\"status_codes\":\"\"}]}],\"macros\":[],\"templates\":[],\"screens\":[],\"tags\":[]}],\"triggers\":[{\"expression\":\"{Test:web.test.rspcode[Test,test].last()}=0\",\"recovery_mode\":\"0\",\"recovery_expression\":\"\",\"name\":\"Test\",\"correlation_mode\":\"0\",\"correlation_tag\":\"\",\"url\":\"\",\"status\":\"0\",\"priority\":\"3\",\"description\":\"\",\"type\":\"0\",\"manual_close\":\"0\",\"dependencies\":[],\"tags\":[]}]}}"

      6. We transfer this answer to another machine and tried to import:
      Code:

      #!/bin/bash auth=$(curl -s -H "Content-Type: application/json-rpc" -X POST 'localhost/zabbix/api_jsonrpc.php' -d ' {"jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "XXXXXXXXXXX"},"id": 1,"auth": null}' | jq '.result') export=$(< test.txt) curl -s -H "Content-Type: application/json-rpc" -X POST 'localhost/zabbix/api_jsonrpc.php' -d "{\"jsonrpc\": \"2.0\",\"method\": \"configuration.import\",\"params\": {\"format\": \"json\",\"rules\": {\"applications\": {\"createMissing\": true,\"deleteMissing\": false},\"discoveryRules\": {\"createMissing\": true,\"updateExisting\": true,\"deleteMissing\": true},\"graphs\":{\"createMissing\": true,\"updateExisting\": true,\"deleteMissing\": true},\"groups\": {\"createMissing\": true},\"hosts\": {\"createMissing\": true,\"updateExisting\": true},\"images\": {\"createMissing\": true,\"updateExisting\": true},\"items\": {\"createMissing\": true,\"updateExisting\": true,\"deleteMissing\": true},\"maps\":{\"createMissing\": true,\"updateExisting\": true},\"screens\":{\"createMissing\": true,\"updateExisting\": true},\"templateLinkage\":{\"createMissing\": true},\"templates\": {\"createMissing\": true,\"updateExisting\": true},\"templateScreens\":{\"createMissing\": true,\"updateExisting\": true,\"deleteMissing\": true},\"triggers\": {\"createMissing\": true,\"updateExisting\": true,\"deleteMissing\": true},\"valueMaps\": {\"createMissing\": true,\"updateExisting\": true}},\"source\": $export},\"auth\": $auth,\"id\": 12}"

      In response, we get:
      Code:

      {"jsonrpc":"2.0","error":{"code":-32500,"message":"Application error.","data":"Invalid tag \"/zabbix_export/templates/template(1)/httptests/httptest(1)/application\": an array is expected."},"id":12}

      I understand that it is enough to simply specify application in the web, but this field is not necessary and zabbix itself filled it like this: "application": null
      Error 2:
      1. Correct the first error and make the application.
      2. After repeating step 5, we get another json:
      Code:

      "{\"zabbix_export\":{\"version\":\"4.2\",\"date\":\"2019-08-27T12:12:39Z\",\"groups\":[\{\"name\":\"Test\"}],\"templates\":[{\"template\":\"Test\",\"name\":\"Test\",\"description\":\"\",\"groups\":[\{\"name\":\"Test\"}],\"applications\":[\{\"name\":\"test\"}],\"items\":[],\"discovery_rules\":[],\"httptests\":[{\"name\":\"Test\",\"application\":{\"name\":\"test\"},\"delay\":\"1m\",\"attempts\":\"1\",\"agent\":\"Zabbix\",\"http_proxy\":\"\",\"variables\":[],\"headers\":[],\"status\":\"0\",\"authentication\":\"0\",\"http_user\":\"\",\"http_password\":\"\",\"verify_peer\":\"0\",\"verify_host\":\"0\",\"ssl_cert_file\":\"\",\"ssl_key_file\":\"\",\"ssl_key_password\":\"\",\"steps\":[{\"name\":\"test\",\"url\":\"google.com\",\"query_fields\":[],\"posts\":[],\"variables\":[],\"headers\":[],\"follow_redirects\":\"1\",\"retrieve_mode\":\"0\",\"timeout\":\"15s\",\"required\":\"\",\"status_codes\":\"\"}]}],\"macros\":[],\"templates\":[],\"screens\":[],\"tags\":[]}],\"triggers\":[{\"expression\":\"{Test:web.test.rspcode[Test,test].last()}=0\",\"recovery_mode\":\"0\",\"recovery_expression\":\"\",\"name\":\"Test\",\"correlation_mode\":\"0\",\"correlation_tag\":\"\",\"url\":\"\",\"status\":\"0\",\"priority\":\"3\",\"description\":\"\",\"type\":\"0\",\"manual_close\":\"0\",\"dependencies\":[],\"tags\":[]}]}}"

      3. Again we transfer and again we try to import the same code from step 6. This time we get an error:
      Code:

      {"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"Incorrect item key \"web.test.rspcode[Test,test]\" provided for trigger expression on \"Test\"."},"id":12}

        1. image_14336.png
          image_14336.png
          36 kB
        2. image_14336.png
          image_14336.png
          36 kB
        3. image_14337.png
          image_14337.png
          49 kB
        4. image_14337.png
          image_14337.png
          49 kB
        5. image_14339.png
          image_14339.png
          31 kB
        6. image_14339.png
          image_14339.png
          31 kB

            Miks.Kronkalns Miks Kronkalns
            Kohionor46 Anatoliy Grachev
            Team B
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: