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.
How to monitor restful web services?
How to monitor restful web services?
Last edited by dwhitfield on Tue Nov 01, 2016 4:05 pm, edited 1 time in total.
Reason: marking with green check mark
Reason: marking with green check mark
Re: How to monitor restful web services?
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.
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?
Let us know if you have any other help!
Re: How to monitor restful web services?
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?
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?
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.
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
Re: How to monitor restful web services?
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...
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.
Re: How to monitor restful web services?
Looks like you took the
Was there anything else or are we all good to close this up?
route :)tmcdonald wrote:Otherwise, you would need to write your own logic in a script to handle this.
Was there anything else or are we all good to close this up?
Former Nagios employee
Re: How to monitor restful web services?
Good to close 