Page 1 of 3

Nagios XI API question

Posted: Wed Mar 23, 2016 12:37 pm
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.

Re: Nagios XI API question

Posted: Wed Mar 23, 2016 12:48 pm
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'.

Re: Nagios XI API question

Posted: Thu Mar 24, 2016 8:56 am
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.

Re: Nagios XI API question

Posted: Thu Mar 24, 2016 1:00 pm
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

Re: Nagios XI API question

Posted: Thu Mar 24, 2016 1:17 pm
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

Re: Nagios XI API question

Posted: Thu Mar 24, 2016 1:46 pm
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?

Re: Nagios XI API question

Posted: Thu Mar 24, 2016 2:11 pm
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.

Re: Nagios XI API question

Posted: Thu Mar 24, 2016 2:34 pm
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.

Re: Nagios XI API question

Posted: Mon Mar 28, 2016 6:51 am
by jkinning
Files attached.

Re: Nagios XI API question

Posted: Mon Mar 28, 2016 10:13 am
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