How to monitor an API in Nagios xi

This support forum board is for support questions relating to Nagios xi, our flagship commercial network monitoring solution.
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

How to monitor an API in Nagios xi

Post 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 .
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: How to monitor an API in Nagios xi

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: How to monitor an API in Nagios xi

Post 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
You do not have the required permissions to view the files attached to this post.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: How to monitor an API in Nagios xi

Post 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'
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: How to monitor an API in Nagios xi

Post by deek »

Hi ,

I tried as you have suggested , but im not getting the output .
Capture new.PNG
You do not have the required permissions to view the files attached to this post.
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: How to monitor an API in Nagios xi

Post by deek »

Hi ,

Is there a way to do it through check_http plugin ?
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: How to monitor an API in Nagios xi

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: How to monitor an API in Nagios xi

Post by deek »

Hi ,

Any update on this ?
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: How to monitor an API in Nagios xi

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!