Page 1 of 3

JSON Parsing and saving

Posted: Wed Nov 27, 2013 3:03 pm
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

Re: JSON Parsing and saving

Posted: Wed Nov 27, 2013 3:17 pm
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

Re: JSON Parsing and saving

Posted: Tue Dec 10, 2013 11:49 am
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.

Re: JSON Parsing and saving

Posted: Tue Dec 10, 2013 12:07 pm
by abrist
You could use the string match ( -s, --string=STRING ) or regex ( -r, --regex, --ereg=STRING ) to parse the output to a state.

Re: JSON Parsing and saving

Posted: Tue Dec 10, 2013 12:39 pm
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

Re: JSON Parsing and saving

Posted: Tue Dec 10, 2013 12:45 pm
by abrist
If you want to retrieve and save the json, just use wget or curl. What is the usage case for this?

Re: JSON Parsing and saving

Posted: Tue Dec 10, 2013 1:06 pm
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

Re: JSON Parsing and saving

Posted: Tue Dec 10, 2013 1:35 pm
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.

Re: JSON Parsing and saving

Posted: Mon Dec 16, 2013 11:55 am
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?

Re: JSON Parsing and saving

Posted: Mon Dec 16, 2013 11:59 am
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.