How to monitor restful web services?

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
aashraf
Posts: 5
Joined: Tue Nov 01, 2016 11:34 am

How to monitor restful web services?

Post 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.
Last edited by dwhitfield on Tue Nov 01, 2016 4:05 pm, edited 1 time in total.
Reason: marking with green check mark
aashraf
Posts: 5
Joined: Tue Nov 01, 2016 11:34 am

Re: How to monitor restful web services?

Post 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.
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: How to monitor restful web services?

Post by dwhitfield »

Let us know if you have any other help!
aashraf
Posts: 5
Joined: Tue Nov 01, 2016 11:34 am

Re: How to monitor restful web services?

Post 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?
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: How to monitor restful web services?

Post 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.
Former Nagios employee
aashraf
Posts: 5
Joined: Tue Nov 01, 2016 11:34 am

Re: How to monitor restful web services?

Post 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...
Last edited by aashraf on Tue Nov 01, 2016 3:59 pm, edited 2 times in total.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: How to monitor restful web services?

Post 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?
Former Nagios employee
aashraf
Posts: 5
Joined: Tue Nov 01, 2016 11:34 am

Re: How to monitor restful web services?

Post by aashraf »

Good to close :)
Locked