Ad Widget

Collapse

LLD host discovery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akam
    Junior Member
    • Sep 2011
    • 22

    #1

    LLD host discovery

    Hello, I am trying to do LLD host discovery based on the item output on hosts. (Zabbix 6.4)

    I have created a new template with the item 'Dispatcher hosts discovery' which returns JSON like this:
    Code:
    {
      "jsonrpc":  "2.0",
      "result": {
        "NRSETS": 2,
        "RECORDS":  [{
            "SET":  {
              "ID": 111,
              "TARGETS":  [{
                  "DEST": {
                    "URI":  "sip:1.1.1.1",
                    "FLAGS":  "IP",
                    "PRIORITY": 0,
                    "LATENCY":  {
                      "AVG":  0,
                      "STD":  0,
                      "EST":  0,
                      "MAX":  0,
                      "TIMEOUT":  5
                    }
                  }
                }]
            }
          }, {
            "SET":  {
              "ID": 999,
              "TARGETS":  [{
                  "DEST": {
                    "URI":  "sip:2.2.2.2",
                    "FLAGS":  "AP",
                    "PRIORITY": 0,
                    "LATENCY":  {
                      "AVG":  42,
                      "STD":  0,
                      "EST":  42,
                      "MAX":  42,
                      "TIMEOUT":  0
                    }
                  }
                }, {
                  "DEST": {
                    "URI":  "sip:8.8.8.8",
                    "FLAGS":  "AP",
                    "PRIORITY": 0,
                    "ATTRS":  {
                      "BODY": "zabbix-host=TODO-extract-hostname-from-here",
                      "DUID": null,
                      "MAXLOAD":  0,
                      "WEIGHT": 0,
                      "RWEIGHT":  0,
                      "SOCKET": null,
                      "SOCKNAME": null,
                      "OBPROXY":  null
                    },
                    "LATENCY":  {
                      "AVG":  27,
                      "STD":  0,
                      "EST":  27,
                      "MAX":  27,
                      "TIMEOUT":  0
                    }
                  }
                }]
            }
          }]
      },
      "id": 4043662
    }


    I created a discovery rule dependent item with LLD macros and a host prototype



    $.result.RECORDS[?(@.SET.ID==999)].SET.TARGETS.*.DEST.URI returns ["sip:2.2.2.2", "sip:8.8.8.8"]



    And I created a simple host prototype
    Click image for larger version

Name:	image.png
Views:	172
Size:	161.2 KB
ID:	468617​​
    And I can see the error
    Click image for larger version

Name:	image.png
Views:	120
Size:	54.5 KB
ID:	468618

    Is it necessary to have "data" in output JSON? is there any workaround to fix it?
  • SanMonitor
    Member
    • Aug 2022
    • 48

    #2
    Originally posted by akam
    Hello, I am trying to do LLD host discovery based on the item output on hosts. (Zabbix 6.4)

    I have created a new template with the item 'Dispatcher hosts discovery' which returns JSON like this:
    Code:
    {
    "jsonrpc": "2.0",
    "result": {
    "NRSETS": 2,
    "RECORDS": [{
    "SET": {
    "ID": 111,
    "TARGETS": [{
    "DEST": {
    "URI": "sip:1.1.1.1",
    "FLAGS": "IP",
    "PRIORITY": 0,
    "LATENCY": {
    "AVG": 0,
    "STD": 0,
    "EST": 0,
    "MAX": 0,
    "TIMEOUT": 5
    }
    }
    }]
    }
    }, {
    "SET": {
    "ID": 999,
    "TARGETS": [{
    "DEST": {
    "URI": "sip:2.2.2.2",
    "FLAGS": "AP",
    "PRIORITY": 0,
    "LATENCY": {
    "AVG": 42,
    "STD": 0,
    "EST": 42,
    "MAX": 42,
    "TIMEOUT": 0
    }
    }
    }, {
    "DEST": {
    "URI": "sip:8.8.8.8",
    "FLAGS": "AP",
    "PRIORITY": 0,
    "ATTRS": {
    "BODY": "zabbix-host=TODO-extract-hostname-from-here",
    "DUID": null,
    "MAXLOAD": 0,
    "WEIGHT": 0,
    "RWEIGHT": 0,
    "SOCKET": null,
    "SOCKNAME": null,
    "OBPROXY": null
    },
    "LATENCY": {
    "AVG": 27,
    "STD": 0,
    "EST": 27,
    "MAX": 27,
    "TIMEOUT": 0
    }
    }
    }]
    }
    }]
    },
    "id": 4043662
    }


    I created a discovery rule dependent item with LLD macros and a host prototype



    $.result.RECORDS[?(@.SET.ID==999)].SET.TARGETS.*.DEST.URI returns ["sip:2.2.2.2", "sip:8.8.8.8"]



    And I created a simple host prototype
    Click image for larger version  Name:	image.png Views:	18 Size:	161.2 KB ID:	468617​​
    And I can see the error
    Click image for larger version  Name:	image.png Views:	10 Size:	54.5 KB ID:	468618

    Is it necessary to have "data" in output JSON? is there any workaround to fix it?
    I might be wrong but I think the replace is creating the error? I've never used it myself but seems that the syntax is like this:
    Click image for larger version  Name:	image.png Views:	0 Size:	28.1 KB ID:	468671

    So I wonder if it works when you remove the replace or change it with replace({#DISPATCHER_HOST},"sip:","")
    Last edited by SanMonitor; 10-08-2023, 16:15. Reason: typo

    Comment

    • akam
      Junior Member
      • Sep 2011
      • 22

      #3
      I have changed LLD macros {#DISPATCHER_HOSTNAME} to $.result.RECORDS[?(@.SET.ID==999)].SET.TARGETS.*.DEST.FLAGS, so output now is like ["AP","AP"]
      and set the host prototype to {{#DISPATCHER_HOST}.regsub(""([A-Z].*)"", \1)} to remove "
      but still the same error

      Click image for larger version

Name:	image.png
Views:	108
Size:	105.8 KB
ID:	468697

      Comment

      Working...