Page 1 of 1

Develop a new Plugin or upda to post Json for APi monitoring

Posted: Thu Mar 08, 2018 4:12 am
by debdutta
Hi,
I want to create a new plugin or using an existing one to create alert in Nagios for API Monitoring for 'POST' method.

For this I already tried Nagios 'check_http' plugin to post "Json". However we are getting expected response for "Failure" case whereas Json String is not recognized for 'Success' cases. I tried using both single & double 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.

Pl. find below the 'cURL' & corresponding 'check_http' command we are using now , output screenshots are also attached---
cURL command ---> curl -X POST -H "Content-Type: application/json" -d "{'catalogRefId':'9780545791342'}" http://test.com/rest/model/api/v1/atg/c ... tInventory

check_http command----> ./check_http -H test.com -u /rest/model/api/v1/atg/commerce/inventory/InventoryActor/getInventory -T "Content-Type:application/json" -j 'POST' --post="{'catalogRefId':'9780545791342'}" -v

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Thu Mar 08, 2018 5:20 pm
by cdienger
The content-type header isn't formatted correctly. Try:

./check_http -H test.com -u /rest/model/api/v1/atg/commerce/inventory/InventoryActor/getInventory -T "application/json" -j 'POST' --post="{'catalogRefId':'9780545791342'}" -v

Please provide the output of both commands if this doesn't help resolve the problem.

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Fri Mar 09, 2018 5:43 am
by debdutta
output.zip
Output of Single and Multiple Parameter cases in zip format
(2.66 KiB) Downloaded 281 times
Hi cdienger,
Many many thanks for your early response. Following your suggestion I am getting success for those cases where 'post' required only one parameter and corresponding value(e.g post='{"skuId":"9780155061392"}), however for those cases where it's required multiple parameter and value(e.g --post="{'login':'bnmonitoring01\@gmail.com','password':'Bn\@123'}").
Below are commands I am using for single & multiple parameter cases, I also uploading the output for both cases for your reference ---

Single parameter case :---

./check_http -H bn-api.bn-web.com -u /rest/model/api/v1/atg/commerce/pricing/PricingActor/skuPrices -T "application/json" -j 'POST' --post='{"skuId":"9780155061392"}' -v

Multiple Parameter case :----

./check_http -H test.com -u /rest/model/api/v1/atg/userprofiling/ProfileActor/login -T "application/json" -j 'POST' --post="{'login':'bnmonitoring01\@gmail.com','password':'Bn\@123'}" -v

Once again thanks for your help. Appreciating your early response.

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Fri Mar 09, 2018 4:36 pm
by cdienger
The \ to escape @ isn't necessary. Try the following instead:

./check_http -H test.com -u /rest/model/api/v1/atg/userprofiling/ProfileActor/login -T "application/json" -j 'POST' --post="{'login':'bnmonitoring01@gmail.com','password':'Bn@123'}" -v

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Sat Mar 10, 2018 2:25 am
by debdutta
Hi cdienger,
Thanks for your prompt reply.
I tried the command without escape character '\' also, however same result is coming.

Please help.

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Mon Mar 12, 2018 10:45 am
by cdienger
Can you provide us with the output of the command please?

./check_http -H test.com -u /rest/model/api/v1/atg/userprofiling/ProfileActor/login -T "application/json" -j 'POST' --post="{'login':'bnmonitoring01@gmail.com','password':'Bn@123'}" -v

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Tue Mar 13, 2018 3:52 am
by debdutta
Hi,
Thanks for your reply. Please find attached the output(login.txt) of below command for login API. Instead of '200', return code is coming '302', login success message is also not coming. However if we are using below URL, we are getting 'login successful' message ---

Nagios Command for Login ---

./check_http -H test.com -u /rest/model/api/v1/atg/userprofiling/ProfileActor/login -T "application/json" -j 'POST' --post="{'login':'bnmonitoring01@gmail.com','password':'Bn@123'}" -v

Login URL ---------------------

http://test.com/rest/model/api/v1/atg/u ... ord=Bn@123

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Tue Mar 13, 2018 4:06 pm
by cdienger
The 302 is a redirect. You can have the check follow the redirect with:

./check_http -H test.com -u /rest/model/api/v1/atg/userprofiling/ProfileActor/login -T "application/json" -j 'POST' --post="{'login':'bnmonitoring01@gmail.com','password':'Bn@123'}" -v -f follow

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Wed Mar 14, 2018 6:47 am
by debdutta
Hi cdienger,
Many many thanks for your excellent help. after adding the -f followup, command is working as expected.

Appreciate all your extended help.

Looking forward for your future help/suggestion.

Re: Develop a new Plugin or upda to post Json for APi monito

Posted: Wed Mar 14, 2018 3:23 pm
by cdienger
Glad to help :)