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

This forum is intended for the discussion of Nagios plugin development. Feature requests, patches, bug fixes, and all types of development-related discussions are welcome!

NOTE: The SourceForge.net nagiosplug-devel mailing list has been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

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

Postby debdutta » Thu Mar 08, 2018 4:12 am

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

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

Postby cdienger » Thu Mar 08, 2018 5:20 pm

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

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

Postby debdutta » Fri Mar 09, 2018 5:43 am

output.zip
Output of Single and Multiple Parameter cases in zip format
(2.66 KiB) Downloaded 23 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

[b]Multiple Parameter case :----[/b]

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

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

Postby cdienger » Fri Mar 09, 2018 4:36 pm

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

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

Postby debdutta » Sat Mar 10, 2018 2:25 am

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

Please help.
debdutta
 
Posts: 17
Joined: Thu Feb 22, 2018 7:57 am

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

Postby cdienger » Mon Mar 12, 2018 10:45 am

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

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

Postby debdutta » Tue Mar 13, 2018 3:52 am

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

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

Postby cdienger » Tue Mar 13, 2018 4:06 pm

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

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

Postby debdutta » Wed Mar 14, 2018 6:47 am

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

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

Postby cdienger » Wed Mar 14, 2018 3:23 pm

Glad to help :)
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
cdienger
Support Tech
 
Posts: 1874
Joined: Tue Feb 07, 2017 11:26 am


Return to Nagios Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests