Page 1 of 1

How to monitor an API in Nagios XI

Posted: Thu Sep 03, 2020 8:45 am
by deek
Hello ,

Is there a way to monitor API in Nagios XI ?
I have to monitor a API and they have provided me a API key also . Please let me know if there is a way to monitor .

Re: How to monitor an API in Nagios XI

Posted: Thu Sep 03, 2020 4:30 pm
by benjaminsmith
Hi,

If you're looking to parse some type JSON or XML output from the API, then I would recommend using the JSON or XML wizards that come with Nagios XI.

Just go to Configure > Start Monitoring Now and search for JSON or XML.

Otherwise, you might also be able to set up a simple check using the check_http plugin.

https://www.monitoring-plugins.org/doc/ ... _http.html

Let us know if you have more questions.

Re: How to monitor an API in Nagios XI

Posted: Wed Sep 09, 2020 1:41 am
by deek
Hi ,

Actually we wanted to monitor a URL using an api key . And I want the response code as my output . I have tried using check_json plugin , but we are not getting a proper output .

Check command :
check_json

Command view :
php $USER1$/check_json.php $ARG1$

$ARG1$ :
-u 'https://abcd.com:9002/aims_plus/was/status' -k 'lkAIdVfC.nuRMZYMzZAIwuqtapOKACBtpAHsTZEmQVjO' -h 'api-key'
run check capture.PNG
Talend Capture.PNG

Re: How to monitor an API in Nagios XI

Posted: Wed Sep 09, 2020 5:34 pm
by benjaminsmith
Hi,

Typically, what I've seen is to pass the API key with the URL string. They -k parameter would be for the key value of the son output and -s option would be to match the string.
-u url
-k json key
-s treat key as a string
-r status code if <string> matches <key> value (defaults to 0 when -s used)
-n status code if <string> does not match <key> value (defaults to 2 when -s is used)
-c critical threshold
-w warning threshold
-h additional header add to request
For example:

Try modifying th header option ( h) to include the API key and let me know if you able to connect.

Code: Select all

$ARG1$ :
-u 'https://abcd.com:9002/aims_plus/was/status' -k 'json key to check' -h 'api-key:12345'

Re: How to monitor an API in Nagios XI

Posted: Mon Sep 14, 2020 7:13 am
by deek
Hi ,

I tried as you have suggested , but im not getting the output .
Capture new.PNG

Re: How to monitor an API in Nagios XI

Posted: Mon Sep 14, 2020 7:25 am
by deek
Hi ,

Is there a way to do it through check_http plugin ?

Re: How to monitor an API in Nagios XI

Posted: Mon Sep 14, 2020 5:44 pm
by benjaminsmith
Hi,
Is there a way to do it through check_http plugin ?
This can be accomplished using the check_http, but you'll need to create on regex patterns to match the appropriate JSON key/values.
Example:

Code: Select all

./check_http -H 192.168.23.115 -u /nagiosxi/api/v1/objects/hoststatus?apikey=JdqXNOLmVmGgt7l5NNVDinUho2OUJuuscmIqDM2Xsu8RjJMK0fJbdcnTC7aYalfU -r "localhost"
Checking with a team member on passing API authorizations in the HTTP header and I'll follow up with you on that.

Benjamin

Re: How to monitor an API in Nagios XI

Posted: Mon Oct 05, 2020 2:17 am
by deek
Hi ,

Any update on this ?

Re: How to monitor an API in Nagios XI

Posted: Mon Oct 05, 2020 4:42 pm
by benjaminsmith
Hi Deek,

Thanks for your patience. For that plugin, the -k option would allow you to pass data in the header.
-k, --header=STRING
Any other tags to be sent in http header. Use multiple times for additional header
--Benjamin

Reference:
https://www.monitoring-plugins.org/doc/ ... _http.html