I have an endpoint that spits out an array of json blobs on a single line, in random order. It looks like this:
The machines are displayed in no particular or reliable order in the array, and the values are in a randomish order within the pair themselves.
What's the best way to separate these values reliably?
Currently what I'm doing is using the zabbix server to hit the api endpoint and digest the data with shell-fu:
This works by breaking the json into newlines, where I can then do various greps and awks to get the values for different keys.
I'd like to call the api once and run regular expressions against the string, but there doesn't seem to be the notion of group matching and printing, which makes it impossible to grab the values.
Anyone have any ideas on how I can accomplish this?
Code:
[{"name":"machine3","status":"up","processes":"2000"},{"name":"machine2","status":"up","processes":"1322"},{"name":"machine5","status":"down","processes":"0"}.... etc]
What's the best way to separate these values reliably?
Currently what I'm doing is using the zabbix server to hit the api endpoint and digest the data with shell-fu:
Code:
system.run[echo $(curl endpoint.api) | tr '}' '\n' | grep 'machine2..... etc]
I'd like to call the api once and run regular expressions against the string, but there doesn't seem to be the notion of group matching and printing, which makes it impossible to grab the values.
Anyone have any ideas on how I can accomplish this?
Comment