Is it possible to use the API to return the hosts and services associated (linked/configured for) a contact?
Thx
Using api to return hosts and services for a contact
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Using api to return hosts and services for a contact
The short answer is no, however there is an undocumented feature that allows for this using the following endpoint:
for services
for hosts
change nagiosadmin to the user you want to query and replace YOUR_SERVER and APIKEY
for services
Code: Select all
http://YOUR_SERVER/nagiosxi/includes/components/nagioscore/ui/objectjson.php?query=servicelist&contactname=nagiosadmin&apikey=APIKEYCode: Select all
http://YOUR_SERVER/nagiosxi/includes/components/nagioscore/ui/objectjson.php?query=hostlist&contactname=nagiosadmin&apikey=APIKEYRe: Using api to return hosts and services for a contact
Thank you for your suggestion.
I had success executing the query using a chrome add-on (YARC!) that is able to provide the header components. It says that the request it used looked like this:
function ImportJSONViaPost(url, payload, fetchOptions, query, parseOptions)
or
function ImportJSON(url, query, parseOptions)
Is there a way to format the apikey using some url keywords (authorization?)
If I use "http://YOUR_SERVER/nagiosxi/includes/components/nagioscore/ui/objectjson.php?query=servicelist&contactname=nagiosadmin&apikey=APIKEY" as the url, I get a bad request error (after replacing the placeholders.)
Thanks
I had success executing the query using a chrome add-on (YARC!) that is able to provide the header components. It says that the request it used looked like this:
- {
"method": "POST",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http://xx.xx.xx.xx/nagiosxi/includes/co ... ervicelist",
"headers": {
"Accept": "application/json, text/plain, */*",
"Authorization": "apikey=keystring",
"Content-Type": "application/json;charset=utf-8"
},
"data": "",
"timeout": {}
}
function ImportJSONViaPost(url, payload, fetchOptions, query, parseOptions)
or
function ImportJSON(url, query, parseOptions)
Is there a way to format the apikey using some url keywords (authorization?)
If I use "http://YOUR_SERVER/nagiosxi/includes/components/nagioscore/ui/objectjson.php?query=servicelist&contactname=nagiosadmin&apikey=APIKEY" as the url, I get a bad request error (after replacing the placeholders.)
Thanks
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Using api to return hosts and services for a contact
What version of XI are you using? this was added in 5.6.0+
If yuo are using a newer version you should be able to simply put
in your browser whole, that's how I tested it
If yuo are using a newer version you should be able to simply put
Code: Select all
http://YOUR_SERVER/nagiosxi/includes/components/nagioscore/ui/objectjson.php?query=servicelist&contactname=nagiosadmin&apikey=APIKEYRe: Using api to return hosts and services for a contact
We are still on 5.4.4. The url works. I'm trying to try different approaches to get the JSON-formatted information into a spreadsheet. I was just wondering if there was an alternative authentication method.
I don't know enough about host rest urls work to figure out how to use this other function. I'll keep searching. Thanks for the info.
You can close this one.
I don't know enough about host rest urls work to figure out how to use this other function. I'll keep searching. Thanks for the info.
You can close this one.
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Using api to return hosts and services for a contact
I will close the thread but I want to give you another option, you can get this from core to and it may work for you
Code: Select all
http://USERNAME:PASSWORD@YOUR_SERVER/nagios/cgi-bin/objectjson.cgi?query=servicelist&contactname=nagiosadmin