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

Re: JSON Parsing and saving

Post by vinothsethuram »

Can check_http plugin read a file?

usr/local/nagios/libexec/check_http -H api.b.com -u 'https://a.b.com/v1/10001/identity?client_id=[b]<data from file >[/b] -j POST -S -T 'application/json' -v
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: JSON Parsing and saving

Post by tmcdonald »

Technically speaking everything check_http reads is a file. If you want it to check for a specific file it should work just the same. However if that file is served up as a redirect, you will need to tack on '-f follow'
Former Nagios employee
vinothsethuram
Posts: 147
Joined: Thu Nov 07, 2013 11:44 am

Re: JSON Parsing and saving

Post by vinothsethuram »

Here is my scenario.

For every 15 min , file A will be updated with new token. I need to access the File A to take the token and then I need use that token as post data . i.e need to assign the retrieved data to -P parameter. So, Is there any possibility to assign the file data to parameter -P in check_http plugin
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: JSON Parsing and saving

Post by sreinhardt »

No it will not directly read the file. You could use a script to read the file as an environment variable and submit that as your post data, or use the same script to read the file and redirect the output into the -P flag.
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.
vinothsethuram
Posts: 147
Joined: Thu Nov 07, 2013 11:44 am

Re: JSON Parsing and saving

Post by vinothsethuram »

Thanks for the suggestion. I wrote shell script and resolved the issue. Is there anyway to execute the service commands sequentially. I want to predefine the order of execution.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: JSON Parsing and saving

Post by abrist »

Not really. You could have one active check that starts the chain. Each step of the chain submits a passive check for the service for that step. This logic would all be handled by your wrapper script.
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 »

Thank you.

Another strange behavior.. Below command is working fine if I execute in command line

Code: Select all

 /usr/local/nagios/libexec/check_http -H a.s.com -u 'https://a.s.com/v1/1/mem/recove/Address?id=Wua' -T 'application/json' -j PUT -S -P '{"email1":"[email protected]"}' -k Token:`/usr/local/Scripts/getTokens.sh && (cat /tmp/getToken.txt|grep "Token" | cut -d: -f2  |tr -d '"' | tr -d ',' | sed -e 's/^[ \t]*//')` -k Token2:`cat /tmp/getToken.txt|grep "Token2" | cut -d: -f2  |tr -d '"' | tr -d ',' | sed -e 's/^[ \t]*//'` -v -w 7.5  -c 10
If use the same one inside command configuration file as shown below, then "Token"value is not assigned, but ''Token2" value is assigned. Any syntax error for "Token".

Code: Select all

define command {
  command_name RESET PASSWORD BY EMAIL

  command_line /usr/local/nagios/libexec/check_http -H a.s.com -u 'https://a.s.com/v1/1/mem/recove/Address?id=Wua' -T 'application/json' -j PUT -S -P '{"email1":"[email protected]"}' -k Token:`/usr/local/Scripts/getTokens.sh && (cat /tmp/getToken.txt|grep "Token" | cut -d: -f2  |tr -d '"' | tr -d ',' | sed -e 's/^[ \t]*//')` -k Token2:`cat /tmp/getToken.txt|grep "Token2" | cut -d: -f2  |tr -d '"' | tr -d ',' | sed -e 's/^[ \t]*//'` -v -w 7.5  -c 10
}
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: JSON Parsing and saving

Post by sreinhardt »

I don't believe you can use | or other redirects with nagios commands, they are considered illegal characters. You should be doing this within a bash script and calling that with your command definition.
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.
vinothsethuram
Posts: 147
Joined: Thu Nov 07, 2013 11:44 am

Re: JSON Parsing and saving

Post by vinothsethuram »

| works fine for 'Token2' but not for 'Token1'
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: JSON Parsing and saving

Post by tmcdonald »

vino, are all these threads related to the same issue of checking a website?

script execution
commands definition

If they are related I am going to merge them into this thread to keep everything in one place.
Former Nagios employee
Locked