Ad Widget

Collapse

How to read an array with LLD from JSON with macros?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • galvcom
    Junior Member
    • May 2024
    • 13

    #1

    How to read an array with LLD from JSON with macros?

    Hello, no native English speaker here, I have an api that gives me data of two components that form one device, let say something like:
    Code:
    | ----------------------- |
    || component A ||
    | ----------------------- | ====> API call ===> JSON response
    || component B ||
    | ----------------------- |
    Device A
    So after some preprocessing in python I get the following json structure:
    Code:
    [
    {
      "{#DEVICETYPE}": "a",
      "{#UTCTIMESTAMPNS}": #################,
      "{#DEVICEID}": "ID-#################",
     ...
     ...
      "{#ACTIVEALERTS}": [
        ##,
        ##,
        ##
      ],
      "{#LATLNG}": [
        Lat,
        Lng
      ]
    },
    {
      "{#DEVICETYPE}": "b",
      "{#UTCTIMESTAMPNS}": #################,
      "{#DEVICEID}": "ID-#################",
     ...
     ...
      "{#DEVICEAID}":  "ID-#################"
    }​​
    ]
    My first try was to add all data at once (component a and b) but this don't work, so i followed this method:
    - First modify the output of python preprocessing to only send one component data at once.
    - Use an item to catch all data of each component.
    - Use discovery rule with the previous item to generate a host for each one of the components and assign them another template for discover each characteristic of the json and filter the response to match only the actual host id.
    Click image for larger version

Name:	imagen.png
Views:	577
Size:	10.4 KB
ID:	484144
    - In the template assigned to each new discovered host i have item prototypes that get the data using a script with the macro value (I know maybe this isn't the best method)
    Click image for larger version

Name:	imagen.png
Views:	577
Size:	13.8 KB
ID:	484143
    Code:
    var test = JSON.parse(value);
    var alarms = test.valor;
    return alarms;​
    - This work somehow but for the items that have an array in the json i can't get the array only the macro value.
    Click image for larger version

Name:	imagen.png
Views:	726
Size:	2.6 KB
ID:	484141
    - In the "cache" item i get the right value
    Click image for larger version

Name:	imagen.png
Views:	577
Size:	1.6 KB
ID:	484142
    Can anyone guide me to make this work?

    In addition to this, I have the problem that the API generates multiple outputs for each component, but zabbix only gets the first match for each component. Is there a method to use the "additional" outputs as new data inputs on already created hosts? Or should I limit the data to the first occurrence in the preprocessing part?
Working...