Nagios XI API question

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Nagios XI API question

Post by jkinning »

I will start with saying we are new to Nagios and the API and I am not a Developer nor do I play one on TV.

I have a Developer who is wanting to leverage the API to check some hosts and specific service checks and present this data in a custom web "dashboard". I sent him the Nagios backend API link - nagios server/nagiosxi/help/?xiwindow=api.php and he has read through it. He tried accessing the nagios server/nagiosxi/api/v1/ but is getting {"error":"No API Key provided"}. If he is a contact for the host and services what does the syntax need to look like to get that information with the API? I asked if the Nagios XI dashboard was enough but I guess they have some other items they want to include on the Dashboard custom to their Business Unit.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios XI API question

Post by rkennedy »

Contacts are actually not assigned an API key. You will need to create a user for him, once he has a username to access XI with, he will be able to click his username in the top right.

The API key will be disabled on this page. When accessing the API, he will need to append two variables. &username=billy&ticket=fsdf3hs

In the above example, 'billy' is the username you assign him, and the API key is 'fsdf3hs'.
Former Nagios Employee
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Re: Nagios XI API question

Post by jkinning »

Ok, we found that information and tried adding it but looks like we are still doing something wrong.

Code: Select all

https://<nagios server>/nagiosxi/api/v1/objects/hoststatus?apikey=<api key listed>&pretty=1&username=<username in Nagios>&ticket=<this api key appears to be the same one listed previously, is it still needed?>
We are getting a 404 error:
Not Found
The requested URL /nagiosxi/api/v1/objects/hoststatus was not found on this server.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI API question

Post by lmiltchev »

I believe you are mixing up the "old" (deprecated) API with the "new" REST API.

To view the syntax of the "old" API, go to Admin->Manage Components->Backend API URL->Edit Settings, select your user from the drop-down menu, and hit "Apply Settings". With this URL, you would use "&username=xxx&ticket=xxx".

Example:

Code: Select all

http://x.x.x.x/nagiosxi/backend/?cmd=gethoststatus&username=test&ticket=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara
To view the syntax of the "new" REST API, go to Help->Object Reference. It this case, you are using the apikey only.

Example:

Code: Select all

http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1
Be sure to check out our Knowledgebase for helpful articles and solutions!
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Re: Nagios XI API question

Post by jkinning »

lmiltchev wrote:I believe you are mixing up the "old" (deprecated) API with the "new" REST API.

To view the syntax of the "old" API, go to Admin->Manage Components->Backend API URL->Edit Settings, select your user from the drop-down menu, and hit "Apply Settings". With this URL, you would use "&username=xxx&ticket=xxx".

Example:

Code: Select all

http://x.x.x.x/nagiosxi/backend/?cmd=gethoststatus&username=test&ticket=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara
To view the syntax of the "new" REST API, go to Help->Object Reference. It this case, you are using the apikey only.

Example:

Code: Select all

http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=<myapikey>&pretty=1
[/quote]


When I try this

Code: Select all

http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1
I am getting a 404
Not Found

The requested URL /nagiosxi/api/v1/objects/hoststatus was not found on this server.

Apache/2.2.15 (CentOS) Server at nagios.westernsouthernlife.com Port 443
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI API question

Post by lmiltchev »

Is this user allowed to see this information? Can you go to Admin->Manage Users->Edit, and set this user as "Admin"? Click on "Update User", then log in as this user, and try accessing the same URL. Did it work this time?

BTW, are you forcing SSL? Are you getting 404 error if you are NOT using SSL?
Be sure to check out our Knowledgebase for helpful articles and solutions!
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Re: Nagios XI API question

Post by jkinning »

I tried with my account which I am an Admin and getting the same thing.

I am forcing SSL and I am still getting the same thing.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI API question

Post by lmiltchev »

What is the Nagios XI version that you are currently using? Do you see any errors in the apache error log when trying to access the objects/hoststatus URL?

Code: Select all

tail -100 /var/log/httpd/error_log
Post the "/etc/httpd/conf.d/nagiosxi.conf" file.

Run the following commands:

Code: Select all

curl -v -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1" &> /tmp/debug1.txt

Code: Select all

curl -k -v -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1" &> /tmp/debug2.txt
Substitute the "x.x.x.x" with the actual IP address of your Nagios XI server, and post the two debug files that got created in the "/tmp/" directory.
Be sure to check out our Knowledgebase for helpful articles and solutions!
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Re: Nagios XI API question

Post by jkinning »

Files attached.
You do not have the required permissions to view the files attached to this post.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios XI API question

Post by rkennedy »

jkinning wrote:Files attached.
I believe the issue is this line -

Code: Select all

Redirect permanent / https://nagiosl1t.ws.wsfgrp.net
It looks like you're using a redirect that is affecting Nagios XI. Can you upload the 3 files these commands produce?

Code: Select all

curl -v -XGET "http://x.x.x.x/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1" &> /tmp/debug1.txt
curl -v -XGET "https://x.x.x.x/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1" &> /tmp/debugssl1.txt
curl -v -XGET "https://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1" &> /tmp/debugssln1.txt
Former Nagios Employee
Locked