JSON Parsing and saving

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
vinothsethuram
Posts: 147
Joined: Thu Nov 07, 2013 11:44 am

JSON Parsing and saving

Post by vinothsethuram »

Hi,

My http url is giving JSON response. I would like to parse and save the value.Is Nagios Core providing the feature?

Thanks
Vinoth
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: JSON Parsing and saving

Post by tmcdonald »

You would need to find (or create) a plugin to do this. This might be a good starting point:

http://exchange.nagios.org/directory/Pl ... ON/details
Former Nagios employee
vinothsethuram
Posts: 147
Joined: Thu Nov 07, 2013 11:44 am

Re: JSON Parsing and saving

Post by vinothsethuram »

I have script to parse and save the JSON. Now I'm getting JSON response from check_http plugin. How to parse the JSON response which is retrieved from check_http plugin output.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: JSON Parsing and saving

Post by abrist »

You could use the string match ( -s, --string=STRING ) or regex ( -r, --regex, --ereg=STRING ) to parse the output to a state.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
vinothsethuram
Posts: 147
Joined: Thu Nov 07, 2013 11:44 am

Re: JSON Parsing and saving

Post by vinothsethuram »

Can't understand .

-s, --string=STRING
String to expect in the content

-R, --eregi=STRING
Search page for case-insensitive regex STRING

How this parameter will help to retrieve and save the value from JSON response
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: JSON Parsing and saving

Post by abrist »

If you want to retrieve and save the json, just use wget or curl. What is the usage case for this?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
vinothsethuram
Posts: 147
Joined: Thu Nov 07, 2013 11:44 am

Re: JSON Parsing and saving

Post by vinothsethuram »

Here is my scenario.

I'm testing my APIs using check_http plugin. First API will have token in JSON response. I need to parse the token and save it. Then I need to use this token as a parameter for all other APIs. Check_http plugin's verbose command his giving JSON response.

Thanks
Vinoth
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: JSON Parsing and saving

Post by abrist »

This request will require a custom script. You will need to fetch the json, parse it, and then save it to a file. Another script would then wrap check_http to use the new parameter from the previous script. This is out of scope for our support, so my suggestion would be to create the scripts, do some troubleshooting, and then post here when you need help.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
vinothsethuram
Posts: 147
Joined: Thu Nov 07, 2013 11:44 am

Re: JSON Parsing and saving

Post by vinothsethuram »

Hi,

I'm using check_http plugin to check my APIs. Verbose command is giving the response. I want to save the response. Is there any possibility yo save the response?
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: JSON Parsing and saving

Post by sreinhardt »

Sure, write a wrapper script that uses the check_http command, and redirects the output to a flat file. This is not something that core will do on its own, or the check_http plugin, it will need to be custom created.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked