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

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.
Locked
debdutta
Posts: 17
Joined: Thu Feb 22, 2018 7:57 am

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

Post 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
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

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

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
debdutta
Posts: 17
Joined: Thu Feb 22, 2018 7:57 am

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

Post by debdutta »

output.zip
Output of Single and Multiple Parameter cases in zip format
(2.66 KiB) Downloaded 275 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.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

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

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
debdutta
Posts: 17
Joined: Thu Feb 22, 2018 7:57 am

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

Post by debdutta »

Hi cdienger,
Thanks for your prompt reply.
I tried the command without escape character '\' also, however same result is coming.

Please help.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

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

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
debdutta
Posts: 17
Joined: Thu Feb 22, 2018 7:57 am

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

Post 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
Attachments
login.txt
Output of above 'Nogios Command for login'
(2.85 KiB) Downloaded 504 times
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

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

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
debdutta
Posts: 17
Joined: Thu Feb 22, 2018 7:57 am

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

Post 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.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

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

Post by cdienger »

Glad to help :)
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked