Zabbix pre-processing item get item within an array with javascript

Viewed 951

I don't have any experience with Javascript so I'm reaching out for the community to accomplish the below. I have a few API calls configured on Zabbix which are working just fine. The thing is, not all of the results within an item is importante for me so I need to grab just what I want out of the array.

I'm using the pre-processing option on Zabbix to grab what I'm after but I can't get the code correct.

For instance, the below is one of the results Zabbix is getting.

[
{
    "batteryLife": "15 minutes",
    "communityString": "public",
    "instanceId": "260596.1",
    "instanceName": "UPS-01",
    "ipAddress": "10.1.100.44",
    "modelNumber": "GXT4-10000RT230",
    "name": "UPS-01",
    "objectType": "ScUps",
    "scName": "pth-pf-04",
    "scSerialNumber": 260596,
    "serialNumber": "unknown",
    "status": "Up",
    "statusDescription": "Online",
    "type": "Liebert"
}

]

How Can I Use the pre-processing to grab just the "ipAddress" value for instance?

Thanks for the help. PeteF

2 Answers

In case someone have the same doubt as I was having here is how I got it working to return the "ipAdress" value

var json = JSON.parse(value);
return json.ipAddress;

In case there are more than one dictionary inside of an array.

var json = JSON.parse(value);
return json[0].ipAddress;
Related