python / shorts / zabbix · February 27, 2024 0

Shorts – Zabbix LLD Macros with JSON

Below is the clarification how to do a LLD of a json.

Code:
[{
  "AP01 Upstairs": {
    "name": "AP01 Upstairs",
    "mac": "dfgdfg",
    "type": "uap",
    "intraclients": 2,
    "guestclients": 1,
    "clients": 3
  },
  "AP02 Lobby": {
    "name": "AP02 Lobby",
    "mac": "dfgdfg",
    "type": "uap",
    "intraclients": 2,
    "guestclients": 3,
    "clients": 5
  },
  "Total-AP": {
    "name": "Total-AP",
    "clients": 41,
    "intraclients": 19,
    "guestclients": 22,
    "mac": "none",
    "type": "none"
  }
}]​

In the Zabbix master item:
- set preprosessing rule: JSONPath = $[*].*
​(it flattens the JSON as you have "duplicate" levels there)

In the discovery rule:
- set LLD macro: {#APNAME} = $..name.first()

(.first() removes the list notation)

In the Zabbix item prototype:
- set first preprosessing rule: JSONPath = $.[?(@.name == "{#APNAME}")].first()
- set second preprocessing rule: JSONPath = $.clients

The preprocessing rule in the item prototype did not accept .clients so using them in steps seems to help.