Ad Widget

Collapse

Beginners help - getting a list of value pairs from a json output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crummy
    Junior Member
    • Jul 2023
    • 1

    #1

    Beginners help - getting a list of value pairs from a json output

    Hi

    I am really struggling to understand the right process behind this.

    Essentially i have a script that runs and pulls back a load of Host Names and their associated Running Status (in JSON formatted to let Zabbix read it. I.e. {"data": [{"Host_Name": "example 1", "Running": True}, {"Host_Name": "example 2", "Running": False},

    Try as i might i can not work out how to pull this into Zabbix to display as a list of hosts and their running status. Any assistance would be much appreciated.

    Regards

  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2
    Hey there.

    1. Setup an item to collect the JSON into Zabbix. There are multiple ways to do it, as one of possible examples:
    Create a new item of Zabbix Agent type, set key as systme.run[/bin/bash /path/to/script.sh]

    2. Setup discovery rule, type Dependent Item, as master item select the item you created in step 1.
    In LLD Macros define:
    {#SERVER} - $.Host_name


    3. In discovery rule create item prototype, type dependent item, master item select the item you created in step 1
    Name: {#SERVER} Status
    Key: whatever_you_want[{#SERVER}]
    Preprocessing -> add
    JSONPath -> $.data[?(@.Host_Name == "{#SERVER}")].Running.first()
    (here I write from top of my head with a bit of guide from Zabbix doc, so might be some mistake in JSON path, you should be able to test it in Zabbix UI with Test Now button to see if it's working as expected ot not)

    4. Add trigger prototype based on your requirements.


    P.S. that is all under assumption that your actual JSON is correct. AFAIK
    "Running": True
    is not correct syntax and should be
    "Running": "True"
    or
    "Running": true
    .

    Comment

    Working...