Page 2 of 3
Re: JSON Parsing and saving
Posted: Mon Dec 16, 2013 3:42 pm
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
Re: JSON Parsing and saving
Posted: Mon Dec 16, 2013 3:52 pm
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'
Re: JSON Parsing and saving
Posted: Mon Dec 16, 2013 4:17 pm
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
Re: JSON Parsing and saving
Posted: Mon Dec 16, 2013 4:33 pm
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.
Re: JSON Parsing and saving
Posted: Thu Dec 19, 2013 9:25 am
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.
Re: JSON Parsing and saving
Posted: Thu Dec 19, 2013 10:44 am
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.
Re: JSON Parsing and saving
Posted: Thu Dec 19, 2013 1:04 pm
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
}
Re: JSON Parsing and saving
Posted: Thu Dec 19, 2013 4:21 pm
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.
Re: JSON Parsing and saving
Posted: Thu Dec 19, 2013 4:30 pm
by vinothsethuram
| works fine for 'Token2' but not for 'Token1'
Re: JSON Parsing and saving
Posted: Fri Dec 20, 2013 10:41 am
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.