Page 1 of 1

How to monitor restful web services?

Posted: Tue Nov 01, 2016 11:36 am
by aashraf
Does anyone know of a plugin I can use to monitor restful webservices with Nagios?

I need to authenticate by passing an auth header. Thanks.

Re: How to monitor restful web services?

Posted: Tue Nov 01, 2016 11:53 am
by aashraf
I just realized I can pass headers with check_http

ex: ./check_http -H api.somedomain.com -u /api/data -k blablah

I will try going down that route.

Re: How to monitor restful web services?

Posted: Tue Nov 01, 2016 12:00 pm
by dwhitfield
Let us know if you have any other help!

Re: How to monitor restful web services?

Posted: Tue Nov 01, 2016 12:08 pm
by aashraf
It looks like in order to authenticate I have to:
Perform an HTTP POST with a username and pass to the API. This post will return a key.
Then I can pass the key as a header along with all subsequent requests.

I don't know if Nagios is capable of handling this. Does anyone know what the best way to achieve this is?

Re: How to monitor restful web services?

Posted: Tue Nov 01, 2016 1:27 pm
by tmcdonald
You might look into Selenium (doc is for XI but applies to Core as well):

https://assets.nagios.com/downloads/nag ... ios-XI.pdf

or in XI we have the Web Transactions Wizard (page 5):

https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Otherwise, you would need to write your own logic in a script to handle this.

Re: How to monitor restful web services?

Posted: Tue Nov 01, 2016 3:33 pm
by aashraf
There might be a better solution out there... but if anyone ever wants to monitor a restful web api that requires token authentication here's what I did.

Create a bash script that uses CURL to call the API and pass the auth headers (example below) get the token back and write that token to the RESOURCES.CFG file as a user variable and make this script run whenever you need (I have it running once a day). Then I created a custom check_api command that pulls in the user variable as header data (-k).

Example: The command below will get the JSON data back and parse it.

Script:
OUTPUT=`curl --data 'grant_type=password&username=[email protected]&password=securePass123&clientid=someApp' https://api.mySite.com/token | jq -r '.access_token'`;
sed -i "s|.*USER8.*|\$USER8\$=\"Authorization: Bearer ${OUTPUT}\"|" /usr/local/nagios/etc/resource.cfg
service nagios restart

Hope this helps someone down the line...

Re: How to monitor restful web services?

Posted: Tue Nov 01, 2016 3:50 pm
by tmcdonald
Looks like you took the
tmcdonald wrote:Otherwise, you would need to write your own logic in a script to handle this.
route :)

Was there anything else or are we all good to close this up?

Re: How to monitor restful web services?

Posted: Tue Nov 01, 2016 3:54 pm
by aashraf
Good to close :)