Page 1 of 2
How to post json with check_http
Posted: Fri Mar 14, 2014 12:38 pm
by chevb
Hello
Does anyone knows how to post json with check_http plugin. I`m trying to do something like this :
Code: Select all
[root@server01 user01]# /usr/lib64/nagios/plugins/check_http -H serverx.xyz -u /MY-URI --header=content-type:application/json --method=POST --post={"profileId":"anyId","site":"mywebsite","gender":"male","bikeType":"tri","unit":"in","inseam":"10.0","trunk":"10.0","forearm":"10.0","arm":"10.0","thigh":"10.0","lowerLeg":"10.0","sternalNotch":"10.0","overallHeight":"10.0","fitCalcResults":{"aero":{"top_tube_length":"21.9 - 23.9 cm","stem_length":"8 - 10 cm","bb_saddle_position":"22.9 cm","saddle_pedal":"40.1 cm","saddle_ground":"47.9 cm","cranklength":"170 cm","aero_bar_size":"XS","aero_bar_drop_minimal":"-4.2 cm","aero_bar_drop_moderate":"-2.6 cm","aero_bar_drop_intense":"-2 cm","aero_bar_drop_maximal":"-0.8 cm","pad_ground_minimal":"52.1 cm","pad_ground_moderate":"50.5 cm","pad_ground_intense":"49.8 cm","pad_ground_maximal":"48.7 cm"}}} -t 3 -e 404 -p 80
HTTP CRITICAL - Invalid HTTP response received from host: HTTP/1.1 400 Bad Request
[root@server01 user01]#
I need to see as result ( -e 404 ) 404 but i`m getting 400 so I think my mistake is related to syntax
Any help is deeply appreciated
Re: How to post json with check_http
Posted: Fri Mar 14, 2014 2:09 pm
by abrist
Specifying json from the shell is quite an academic task when dealing with escapes, etc. Try posting with a very small bit of json, and then try escaping till you get the expected error, and then fix up your json string with the necessary escapes.
Code: Select all
/usr/lib64/nagios/plugins/check_http -H serverx.xyz -u /MY-URI --header=content-type:application/json --method=POST --post="{\"test\": 0}" -t 3 -e 404 -p 80
You may have to escape ALL quotes in the json string . . .
Re: How to post json with check_http
Posted: Tue Jan 06, 2015 2:22 pm
by nshah11
Hi,
I am trying to POST JSON string in the check_http command as follows:
/usr/local/nagios/libexec/check_http -H localhost -p 8080 -u /service/storestatus -T "Content-Type:application/json" -k "API_KEY: 0XXX" -j POST --post="{\"store_id\":\"1953\"}" -v
I am trying to escape all the quotes - and tried several things in the --post="<string>" but it does not seem to recognize the JSON sting. I receive the following:
Code: Select all
STATUS: HTTP/1.1 500 Internal Server Error
CONTENT:
{"ack":"1","errors":[{"msg":"REQUEST IS NULL","code":"ERR0004"}],"store_status":null}
Any suggestions would be appreciated. Thanks
Re: How to post json with check_http
Posted: Tue Jan 06, 2015 5:48 pm
by sreinhardt
How about enclosing it in single quotes and not escaping them? Something like:
Code: Select all
./check_http -H localhost -p 8080 -u /service/storestatus -T "Content-Type:application/json" -k "API_KEY: 0XXX" -j POST --post='{"store_id":"1953"}' -v
Re: How to post json with check_http
Posted: Tue Jan 06, 2015 6:22 pm
by nshah11
Thanks for your prompt response sreinhardt.
I tried using the single quote ' ' for the POST string but that gives me the same error. I try the same thing using curl command and it gives me the expected JSON response.
Basically, I want to make sure that the service URL is live and up and monitor the response time - I am fine with using different plugins for each if I have to:
1) For checking if the URL service is up (Post using JSON string)
2) Monitor the response time
Any other suggestions for the check_http POST string syntax? Do you suggest any other plugins based on the use?
Thanks
Re: How to post json with check_http
Posted: Thu Jan 08, 2015 12:47 pm
by lgroschen
Have you accounted for standard htaccess authentication? then '-a username:password' could be required.
Re: How to post json with check_http
Posted: Mon Aug 17, 2015 3:44 am
by jraj90
Hi guys,
I am also facing similar problem trying to post JSON using the check_http plugin.
Did anyone manage to resolve this ? May I know if this is solved.
Thanks
Regards,
- jay -
Re: How to post json with check_http
Posted: Mon Aug 17, 2015 3:54 pm
by tmcdonald
Could you give us more specific errors? What is your current check output and how are you running the check?
Re: How to post json with check_http
Posted: Tue Aug 18, 2015 5:34 am
by jraj90
Hi tmcdonald,
I am performing checks using the check_http plugin to an API service. It requires a POST method sending data in JSON. Here is the requests and respond using check_http.
Check command using the exact JSON Data:-
Code: Select all
./check_http -H test.com -S -k 'Authorization: Bearer fdb6f896xvxvxvxvxvxvx' -u '/smsmessaging/v1/outbound/212830/requests' -j 'POST' -P '{"outboundSMSMessageRequest":{"address":["tel:+8801847111111"],"senderAddress":"tel:12345678","outboundSMSTextMessage":{"message":"Hello World"},"clientCorrelator":"123456","receiptRequest":{"notifyURL":"http://application.example.com/notifications/DeliveryInfoNotification","callbackData":"some-data-useful-to-the-requester"},"senderName":"Test."}}'
Respond:-
HTTP CRITICAL: HTTP/1.1 500 Internal Server Error - 1382 bytes in 0.529 second response time |time=0.528722s;;;0.000000 size=1382B;;;0
Check command by escaping ALL quotes in the json string:-
Code: Select all
./check_http -H test.com -S -k 'Authorization: Bearer fdb6f896xvxvxvxvxvxvx' -u '/smsmessaging/v1/outbound/212830/requests' -j 'POST' -P '{\"outboundSMSMessageRequest\":{\"address\":[\"tel:+8801847111111\"],\"senderAddress\":\"tel:12345678\",\"outboundSMSTextMessage\":{\"message":"Hello World\"},\"clientCorrelator\":\"123456\",\"receiptRequest\":{\"notifyURL\":\"http://application.example.com/notifications/DeliveryInfoNotification\",\"callbackData\":\"some-data-useful-to-the-requester\"},\"senderName\":\"Test.\"}}'
Respond:-
HTTP CRITICAL: HTTP/1.1 500 Internal Server Error - 1382 bytes in 0.573 second response time |time=0.572900s;;;0.000000 size=1382B;;;0
There is also another service which uses GET method, hence no data post required and it works fine
Check command:-
./check_http -H test.com -S -k 'Authorization: Bearer fdb6f896xvxvxvxvxvxvx' -u '/location/v1/queries/location?address=tel%3A%2B8801819210809&requestedAccuracy=1000'
Respond:
HTTP OK: HTTP/1.1 200 OK - 620 bytes in 2.148 second response time |time=2.147742s;;;0.000000 size=620B;;;0
If I tried to post the JSON data using Curl it works fine too. Therefore, can you please guide me how can I post the JSON data.
Thanks
Regards,
- jay -
Re: How to post json with check_http
Posted: Tue Aug 18, 2015 3:55 pm
by ssax
Looks like you had some mistakes in your escaping, try this:
http://www.infobyip.com/jsonencoderdecoder.php
If that doesn't work, try this one:
http://codebeautify.org/url-encode-string
Let us know if that works for you.