Ad Widget

Collapse

LLD macros in zabbix 4.4.5

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AVZ
    Junior Member
    • Feb 2020
    • 5

    #1

    LLD macros in zabbix 4.4.5

    Hello!

    According to the documentation https://www.zabbix.com/documentation...evel_discovery:
    "Note that since Zabbix 4.2, the format of the JSON returned by low-level discovery rules has been changed. It is no longer expected that the JSON will contain the "data" object. Low-level discovery will now accept a normal JSON containing an array, in order to support new features such as the item value preprocessing and custom paths to low-level discovery macro values in a JSON document."

    I have zabbix 4.4.5. I get the following JSON in the discovery rule using the http agent:


    Code:
    {
                "@attributes": {
                    "version": "1.0"
                },
                "hdd": [
                    {
                        "@attributes": {
                            "version": "1.0"
                        },
                        "id": "1",
                        "hddName": "hdda",
                        "hddPath": {},
                        "hddType": "SATA",
                        "status": "ok",
                        "capacity": "5723166",
                        "freeSpace": "0",
                        "property": "RW"
                    },
                    {
                        "@attributes": {
                            "version": "1.0"
                        },
                        "id": "2",
                        "hddName": "hddb",
                        "hddPath": {},
                        "hddType": "SATA",
                        "status": "ok",
                        "capacity": "5723166",
                        "freeSpace": "0",
                        "property": "RW"
                    }
                ]
            }
    In LLD macros, I specify:
    {#TEST} $..id
    Checking the path to the node in JSONPath I get the result: ["1", "2"].

    But the discovery rule does not work due to an error: "Cannot find the "data" array in the received JSON object.".

    Why doesn't LLD work with json without a "data" object?

    If I add the "data" object to json, then LLD starts working:

    Code:
    {
        "data": [
            {
                "@attributes": {
                    "version": "1.0"
                },
                "hdd": [
                    {
                        "@attributes": {
                            "version": "1.0"
                        },
                        "id": "1",
                        "hddName": "hdda",
                        "hddPath": {},
                        "hddType": "SATA",
                        "status": "ok",
                        "capacity": "5723166",
                        "freeSpace": "0",
                        "property": "RW"
                    },
                    {
                        "@attributes": {
                            "version": "1.0"
                        },
                        "id": "2",
                        "hddName": "hddb",
                        "hddPath": {},
                        "hddType": "SATA",
                        "status": "ok",
                        "capacity": "5723166",
                        "freeSpace": "0",
                        "property": "RW"
                    }
                ]
            }
        ]
    }
    Checking the path to the node $..id in JSONPath I get the same result: ["1", "2"], but only one element of the following form is created from the prototype:
    Имя Триггеры Ключ
    Hik_hdd_lld: SMART_hdd_["1","2"] HIK_SMART_HDD["["1","2"]"]




    Why do values ​​have this form and why was 1 value created, not 2?
    Last edited by AVZ; 12-02-2020, 14:32.
  • vso
    Zabbix developer
    • Aug 2016
    • 190

    #2
    Because it need array, for example the following should work:
    Code:
    [{
        "@attributes": {
            "version": "1.0"
        },
        "id": "1",
        "hddName": "hdda",
        "hddPath": {},
        "hddType": "SATA",
        "status": "ok",
        "capacity": "5723166",
        "freeSpace": "0",
        "property": "RW"
    }, {
        "@attributes": {
            "version": "1.0"
        },
        "id": "2",
        "hddName": "hddb",
        "hddPath": {},
        "hddType": "SATA",
        "status": "ok",
        "capacity": "5723166",
        "freeSpace": "0",
        "property": "RW"
    }]

    Comment

    • AVZ
      Junior Member
      • Feb 2020
      • 5

      #3
      Indeed, this is how LLD works. But why are values ​​inserted in quotation marks and in square brackets?

      This is a prototype:

      Click image for larger version

Name:	prototype.jpg
Views:	1989
Size:	24.6 KB
ID:	395604

      and this is an item:

      Click image for larger version

Name:	item.jpg
Views:	1953
Size:	23.7 KB
ID:	395603

      Comment

      • AVZ
        Junior Member
        • Feb 2020
        • 5

        #4
        To get only the value, you can use {{#LLDMACRO} .regsub (pattern, output)} as a workaround.
        Click image for larger version

Name:	item_regsub.jpg
Views:	1978
Size:	29.5 KB
ID:	396470

        Comment

        • rhysjonas
          Junior Member
          • Feb 2020
          • 1

          #5
          Try using {{#LLDMACRO} .regsub (pattern, output)} as a workaround.
          spanish dictionary

          Comment

          Working...