Ad Widget

Collapse

Ошибка Incorrect item key, при импорте конфигурации по api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kohinor
    Junior Member
    • Aug 2019
    • 8

    #1

    Ошибка Incorrect item key, при импорте конфигурации по api

    Добрый день.

    Столкнулся с 2 проблема. Пишу сюда, т.к. на сайте support.zabbix.com не могу зарегистрироваться (после ввода данных страница вечно грузится).
    Ошибка 1:
    1.Создаем шаблон.
    2. В нем создаем сценарий web проверки:

    3. Создаем шаг проверки:

    4. Создаем триггер на этот шаг:

    5. Экспортируем по апи в формате json. Я делаю это башем:
    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
    В ответ получаем:
    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. Переносим данный ответ на другую машину и пытался выполнить импорт:
    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}"
    И получаем ошибку:
    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}
    Да я понимаю, что достаточно просто указать application в web, но это поле не обязательно и его заполнил сам zabbix так: "application":null
    Ошибка 2:
    1. Исправляем первую ошибку и вносим application.
    2. После повторения шага 5 получаем другую 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. Опять переносим и опять пытаемся выполнить импорт тем же кодом из шага 6. На этот раз получаем ошибку:
    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}
    И вот как исправить это я себе уже не представляю. Может есть у сообщества идеи?
    Заранее спасибо.
Working...