Ad Widget

Collapse

JSONPath for LLD macros (HTTP agent discovery rule)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • remaeder
    Junior Member
    • Apr 2014
    • 6

    #1

    JSONPath for LLD macros (HTTP agent discovery rule)

    I am trying to write a discovery rule for an HTTP agent to query a REST API. The REST API to query is the one from deconz,

    and the result of the query looks like this

    Code:
    {
    "1": {
        "name": "Light 1",
        "uniqueid": "00:21:2E:FF:FF:00:73:9F-0A"
        ...
       },
    
    "2": {
        "name": "Light 2",
        "type": "Dimmable light",
        "uniqueid": "00:21:2E:FF:FF:00:73:9F-0B"
       ...
       }
    ...
    }
    there are more fields, but what I need for the LLD macros is the index (1, 2,...) and the name. All examples I could find assume that all data is inside the records, usually in an array, but here the index is the key for the respective record. What magic JSONPath expressions would deliver the keys and names?

    Is it possible to test such HTTP agent discovery rules somehow?
    Perhaps I am better off writing an external script that shuffles the data around in a form that is easier to read.

    This is for Zabbix 4.4.10/CentOS 7

    Roman

  • remaeder
    Junior Member
    • Apr 2014
    • 6

    #2
    To answer my own question:
    I played around with "jq" and this concoction formats the reply from the controller as an array with the required LLD macros:
    Code:
    curl http://deconz.example.com/api/1234567890/lights | \
    jq 'to_entries | map({"{#LIGHTID}": .key, "{#LIGHTNAME}": .value.name, "{#LIGHTTYPE}": .value.type})'
    so it looks like this:
    Code:
    [
     {
       "{#LIGHTID}": "1",
       "{#LIGHTNAME}": "Configuration tool 1",
       "{#LIGHTTYPE}": "Configuration tool"
     },
     {
       "{#LIGHTID}": "2",
       "{#LIGHTNAME}": "Büro N",
       "{#LIGHTTYPE}": "Color temperature light"
     },
    ...
    ]
    I set this up as an external script.

    Comment

    Working...