Ad Widget

Collapse

JSONPath и LLD-макросы, проблема с распознаванием

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AL32
    Junior Member
    • Dec 2023
    • 3

    #1

    JSONPath и LLD-макросы, проблема с распознаванием

    Добрый день.

    Стоит задача настроить мониторинг СКУД Rubezh, извлекаю из него JSON, содержимое во вложении.

    Далее необходимо через LLD-макросы собрать параметры контроллеров, дверных модулей и дверей, на их основе создать прототипы элементов данных.

    Проблема в том, что для LLD-макросов используется особенный синтаксис JSONPath.

    С простыми параметрами достаточно вместо
    Code:
    $..uuid
    указать
    Code:
    $["uuid"]
    и всё работает.

    Для вложенных параметров используется использую
    Code:
    $..subdevices[?(@.is_in_use=="true" && @.name=="DOOR 1")].access_point
    
    для некоторых парсеров требуется указать
    
    $..subdevices[?(@.is_in_use==true && @.name=="DOOR 1")].access_point
    , но Zabbix с таким path не создаёт LLD макросы.

    Пробовал разные варианты, читал документацию (https://www.zabbix.com/documentation..._functionality), но преобразовать этот path для LLD-макроса не выходит.

    Прошу помощи у опытных коллег.
    Attached Files
    Last edited by AL32; 01-12-2023, 16:53.
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    Покажите пару секций json а тут текстом. включая заголовки

    Comment

    • AL32
      Junior Member
      • Dec 2023
      • 3

      #3
      Добрый день.

      JSON:

      Code:
      [
        [
          {
            "hw_uuid": "99519cd5-1a0c-459f-a48b-5cd205b44f6d",
            "uuid": "dcb93710-a38f-11ed-ad53-ddc1bfb1ff84",
            "model_name": "STR1-AP",
            "controller": "00000",
            "serial_num": "0",
            "sw_ver": "0.34.3",
            "vendor": "RUBEZH, STR1-AP (1.2), ver:0.34.3",
            "oui_code": "487",
            "address": "/1/9",
            "baudrate": 115200,
            "vendor_name": "RUBEZH",
            "name": "00000: STR1-AP /1/9 Блок АР № 9",
            "subdevices": [
              {
                "state": "",
                "notification": "",
                "name": "SENS 1",
                "control": false,
                "type": "input",
                "address": "/input/0",
                "access_point": "",
                "error_status": "",
                "is_in_use": false
              },
              {
                "state": "",
                "notification": "",
                "name": "EXIT 1",
                "control": false,
                "type": "input",
                "address": "/input/1",
                "access_point": "2c278f60-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "DOOR 1",
                "control": false,
                "type": "input",
                "address": "/input/2",
                "access_point": "2c278f60-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "SENS 2",
                "control": false,
                "type": "input",
                "address": "/input/3",
                "access_point": "",
                "error_status": "",
                "is_in_use": false
              },
              {
                "state": "",
                "notification": "",
                "name": "EXIT 2",
                "control": false,
                "type": "input",
                "address": "/input/4",
                "access_point": "74cd4700-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "DOOR 2",
                "control": false,
                "type": "input",
                "address": "/input/5",
                "access_point": "74cd4700-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "Link",
                "control": false,
                "type": "link",
                "address": "/link",
                "access_point": "",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "K 1",
                "control": false,
                "type": "lock",
                "address": "/output/0",
                "access_point": "2c278f60-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "K 2",
                "control": false,
                "type": "lock",
                "address": "/output/1",
                "access_point": "74cd4700-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "READER 1",
                "control": false,
                "type": "reader",
                "address": "/reader/0",
                "access_point": "2c278f60-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "READER 2",
                "control": false,
                "type": "reader",
                "address": "/reader/1",
                "access_point": "74cd4700-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "Tamper",
                "control": false,
                "type": "tamper",
                "address": "/tamper",
                "access_point": "",
                "error_status": "",
                "is_in_use": true
              }
            ]
          },
          {
            "hw_uuid": "99519cd5-1a0c-459f-a48b-5cd205b44f6d",
            "uuid": "dd2f9f90-a38f-11ed-ad53-ddc1bfb1ff84",
            "model_name": "STR1-AP",
            "controller": "0000",
            "serial_num": "0",
            "sw_ver": "0.34.3",
            "vendor": "RUBEZH, STR1-AP (1.2), ver:0.34.3",
            "oui_code": "487",
            "address": "/1/10",
            "baudrate": 115200,
            "vendor_name": "RUBEZH",
            "name": "0000: STR1-AP /1/10  Блок АР № 10",
            "subdevices": [
              {
                "state": "",
                "notification": "",
                "name": "SENS 1",
                "control": false,
                "type": "input",
                "address": "/input/0",
                "access_point": "",
                "error_status": "",
                "is_in_use": false
              },
              {
                "state": "",
                "notification": "",
                "name": "EXIT 1",
                "control": false,
                "type": "input",
                "address": "/input/1",
                "access_point": "cd2b5900-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "DOOR 1",
                "control": false,
                "type": "input",
                "address": "/input/2",
                "access_point": "cd2b5900-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "SENS 2",
                "control": false,
                "type": "input",
                "address": "/input/3",
                "access_point": "",
                "error_status": "",
                "is_in_use": false
              },
              {
                "state": "",
                "notification": "",
                "name": "EXIT 2",
                "control": false,
                "type": "input",
                "address": "/input/4",
                "access_point": "",
                "error_status": "",
                "is_in_use": false
              },
              {
                "state": "",
                "notification": "",
                "name": "DOOR 2",
                "control": false,
                "type": "input",
                "address": "/input/5",
                "access_point": "",
                "error_status": "",
                "is_in_use": false
              },
              {
                "state": "",
                "notification": "",
                "name": "Link",
                "control": false,
                "type": "link",
                "address": "/link",
                "access_point": "",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "K 1",
                "control": false,
                "type": "lock",
                "address": "/output/0",
                "access_point": "cd2b5900-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "K 2",
                "control": false,
                "type": "lock",
                "address": "/output/1",
                "access_point": "",
                "error_status": "",
                "is_in_use": false
              },
              {
                "state": "",
                "notification": "",
                "name": "READER 1",
                "control": false,
                "type": "reader",
                "address": "/reader/0",
                "access_point": "cd2b5900-a398-11ed-92bd-2bff36f5c6d0",
                "error_status": "",
                "is_in_use": true
              },
              {
                "state": "",
                "notification": "",
                "name": "READER 2",
                "control": false,
                "type": "reader",
                "address": "/reader/1",
                "access_point": "",
                "error_status": "",
                "is_in_use": false
              },
              {
                "state": "",
                "notification": "",
                "name": "Tamper",
                "control": false,
                "type": "tamper",
                "address": "/tamper",
                "access_point": "",
                "error_status": "",
                "is_in_use": true
              }
            ]
          }
        ]
      ]​
      JSONPath:

      Code:
      $..subdevices[?(@.is_in_use==true && @.name=="DOOR 1")].access_point
      Ожидаемый результат:

      Code:
      [
        "2c278f60-a398-11ed-92bd-2bff36f5c6d0",
        "cd2b5900-a398-11ed-92bd-2bff36f5c6d0"
      ]​
      JSONPath работает через https://jsonpath.com/ , но не работает через LLD-макросы в Zabbix.

      В элементах данных Zabbix работает такой вариант:

      Code:
      $..subdevices[?(@.is_in_use=="true" && @.name=="DOOR 1")].access_point

      Но в LLD-макросах опять же не отрабатывает.

      Используем Zabbix 6.4.8

      Comment

      • Semiadmin
        Senior Member
        • Oct 2014
        • 1625

        #4
        Думаю, для LLD надо в JS преобразовать JSON в подобную структуру:
        Code:
        [
            {
                "uuid": "uuid1",
                "access_point": "ap1"
            },
            {
                "uuid": "uuid1",
                "access_point": "ap2"
            },
            {
                "uuid": "uuid2",
                "access_point": "ap3"
            },
            {
                "uuid": "uuid2",
                "access_point": "ap4"
            }
        ]​
        и делать прототипы вида key[{#UUID},{#AP}]

        Comment

        • Alex_UUU
          Senior Member
          • Dec 2018
          • 541

          #5
          Originally posted by Semiadmin
          Думаю, для LLD надо в JS преобразовать JSON
          и делать прототипы вида key[{#UUID},{#AP}]
          Тоже склоняюсь к этому. В свое время надо было с ключами работать, так и пришлось преобразовывать через JS.

          Comment

          Working...