Nagios XI API question
Nagios XI API question
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.
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
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'.
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
Re: Nagios XI API question
Ok, we found that information and tried adding it but looks like we are still doing something wrong.
We are getting a 404 error:
Not Found
The requested URL /nagiosxi/api/v1/objects/hoststatus was not found on this server.
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?>Not Found
The requested URL /nagiosxi/api/v1/objects/hoststatus was not found on this server.
Re: Nagios XI API question
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:
To view the syntax of the "new" REST API, go to Help->Object Reference. It this case, you are using the apikey only.
Example:
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=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9araExample:
Code: Select all
http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Nagios XI API question
To view the syntax of the "new" REST API, go to Help->Object Reference. It this case, you are using the apikey only.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
Example:
Code: Select all
http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=<myapikey>&pretty=1When I try this
Code: Select all
http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1Not 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
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?
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!
Re: Nagios XI API question
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.
I am forcing SSL and I am still getting the same thing.
Re: Nagios XI API question
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?
Post the "/etc/httpd/conf.d/nagiosxi.conf" file.
Run the following commands:
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.
Code: Select all
tail -100 /var/log/httpd/error_logRun 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.txtCode: Select all
curl -k -v -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=a0mj9nba9ftmqfhm85hc583diobd74kf2828vch8ocriqd73fnchsfse77od9ara&pretty=1" &> /tmp/debug2.txtBe sure to check out our Knowledgebase for helpful articles and solutions!
Re: Nagios XI API question
Files attached.
You do not have the required permissions to view the files attached to this post.
Re: Nagios XI API question
I believe the issue is this line -jkinning wrote:Files attached.
Code: Select all
Redirect permanent / https://nagiosl1t.ws.wsfgrp.net
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