Missing API documentation

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
OUberLord
Posts: 17
Joined: Wed Mar 25, 2015 8:31 am

Missing API documentation

Post by OUberLord »

Hello,

I am trying to figure out how to use the API to get the relationship between our hosts and what their associated contacts/contactgroups are. The API reference within the web interface doesn't seem to have anything that indicates this either way. What am I missing?

I was hoping to put together something that would use the API to export all hosts within a hostgroup, and any contacts or contactgroups they are associated with.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Missing API documentation

Post by lmiltchev »

Currently, this is not possible thing to do via the REST API. I can submit a feature request on your behalf if you'd like. Please keep in mind that the decision to implement the enhancement is at the discretion of our development team.
Be sure to check out our Knowledgebase for helpful articles and solutions!
OUberLord
Posts: 17
Joined: Wed Mar 25, 2015 8:31 am

Re: Missing API documentation

Post by OUberLord »

Thank you for the reply. So, I dug into it a bit more and thought I may have found a way, but then hit a wall and am wondering if it's the same wall that you are already aware of.

If I use the API (/nagiosxi/api/v1/config/host), I can get a list of all hosts which also seems to contain host group, contact, and contact group info. For example, here is some PowerShell code I used:

Code: Select all

$Nagios_Hosts = Invoke-RestMethod -Method GET -Uri "http://$NagiosXI_Server/nagiosxi/api/v1/config/host?apikey=$NagiosXI_APIKey"

$Nagios_Hosts | Select-Object Host_Name,Address,@{N='host_groups';E={$_.hostgroups -join ","}},@{N='contacts';E={$_.contacts -join ","}},@{N='contact_groups';E={$_.contact_groups -join ","}} | Export-Csv -NoTypeInformation .\Documents\NagiosHostExport.csv
This does result in a CSV that looks like it has what I need:
CSV_output.png
However, I am finding that the results from the API do not match the GUI / the system at large. For example, if I check on the same host as in that example of the CSV output, in the GUI it shows that it does have a relationship, and is in fact a member of the "Network" host group whereas the API output shows it is not a member of any host groups:
GUI_Relationship.png
Is this mismatch what leads you to say that for now this isn't supported via the API, or am I just doing something incorrectly?
You do not have the required permissions to view the files attached to this post.
OUberLord
Posts: 17
Joined: Wed Mar 25, 2015 8:31 am

Re: Missing API documentation

Post by OUberLord »

Worth noting that the PowerShell code and subsequent CSV export does work for some hosts, and shows their host groups etc. I don't know what the difference is between the hosts that work properly and the ones that it shows incorrectly "empty" data.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Missing API documentation

Post by ssax »

That won't work because you can define the hostgroup in multiple locations in the configs and each is technically unique to that config that you're modifying:

Using /nagiosxi/api/v1/config/host will only show you the hostgroups defined directly on that host config.

Using /nagiosxi/api/v1/config/hostgroups would show the hostgroup members defined directly on that hostgroup config.

If you pass the host into the objects/hostgroupmembers API endpoint it should show them all:

Code: Select all

https://YOURXISERVER/nagiosxi/api/v1/objects/hostgroupmembers?apikey=XXXXXXXX&pretty=1&host_name=THEHOSTNAME
Another place you can look to get that type of info is in the backend Core interface here:

Code: Select all

https://YOURXISERVER/nagios/cgi-bin/config.cgi
Locked