Ad Widget

Collapse

Item Prototypes Extracting Many Key/Value Pairs From JSON

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • msiekkinen
    Junior Member
    • Aug 2020
    • 1

    #1

    Item Prototypes Extracting Many Key/Value Pairs From JSON

    Hi,

    I'm new to zabbix and trying to figure out how to parameterize some json extraction to avoid tedious hard coding enumerations of dozens of items.

    I'm looking to monitor the SMART output from a Terramaster NAS I have. I can ssh into it and do some things but it doesn't have a package manager on their OS distro so I can't run the agent there. As a work around I've setup a small cronjob to run the smartctl command and repackage it all for all the disks into a json file, then copy that over to the zabbix server for consumption as a local file and processing there.

    The JSON structure looks like

    Code:
    {
    "discs": {
    "/dev/sdd": {
    "info": {
    "Local Time": "Sun Aug 16 14:01:01 2020 CDT",
    ....snip....
    },
    "vendor_attributes": [
    {
    "RAW_VALUE": "21270575",
    "ATTRIBUTE_NAME": "Raw_Read_Error_Rate",
    ....snip...
    },
    {
    "RAW_VALUE": "0",
    "ATTRIBUTE_NAME": "Spin_Up_Time",
    ....snip...
    }
    .....snip....
    }
    I'd like to record many of these RAW_VALUES from vendor_attributes as an item.

    As a first iteration I setup an item using
    Code:
    log
    key type to read the file and JSON Path preprocessing of

    Code:
    $["discs"]["/dev/sdd"]["vendor_attributes"][?(@.ATTRIBUTE_NAME== 'Start_Stop_Count')].RAW_VALUE.first()
    That worked in that it read the value for Start_Stop_Count on /dev/sdd that was visible in Latest Data.

    After getting this far I just then stumbled across this post talking about getting smart info, albeit with a slightly different approach of using regexs from raw smartctl output. I've come this far in the current format so trying to adopt the steps to just read the json I have and use JSON Paths instead of regexes.

    I've added a couple lines to zabbix_agent.conf (same machine server is running on)

    Code:
    $ grep uHDD /etc/zabbix/zabbix_agentd.conf
    UserParameter=uHDD.A[*], jq '.["discs"]["$1"]["vendor_attributes"]' /var/log/nasmaint/smart.json
    UserParameter=uHDD.discovery,cat /var/log/nasmaint/disk.discovery.json
    The smart.json is a full dump for three disks in the format I mentioned above. For now the discovery "command" just outputs a hardcoded text file I have. I'm just trying to emulate actual discovery at this point and minimize other complexities so for right now that disk.discovery.json file just looks like

    Code:
    {
    "data": [
    {
    "{#DISKNAME}": "/dev/sdb"
    },
    {
    "{#DISKNAME}": "/dev/sdc"
    },
    {
    "{#DISKNAME}": "/dev/sdd"
    }
    ]
    }
    Zabbix Configuration


    I created a discovery rule for the key that outputs that text file with a preprocessing step JSON Path
    Code:
    $.data
    Discovery key was
    Code:
    uHDD.discovery

    Running Test here seems to work, giving me results with the filtered json only.


    This is as far as "success" I'm having. Following the guide I linked to above I went to create some prototypes. I created a master Item Prototype

    Code:
    Type: zabbix agent
    Key: uHDD.A[{#DISKNAME}]
    Host: 127.0.0.1: 10050
    Type of info :Text
    I created a dependant prototype with the previous one from the 'select prototype' list on Master Item


    With this preprocessing step: JSON Path
    Code:
    $[?(@.ATTRIBUTE_NAME== 'Raw_Read_Error_Rate')].RAW_VALUE.first()

    I'm at a loss on how to make further progress. I'm not seeing any of this show up in Latest Data. I'm not getting any useful error messages.

    What am I doing wrong?
Working...