Page 1 of 1
Missing API documentation
Posted: Tue Aug 24, 2021 1:06 pm
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.
Re: Missing API documentation
Posted: Tue Aug 24, 2021 2:00 pm
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.
Re: Missing API documentation
Posted: Tue Aug 31, 2021 10:18 am
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?
Re: Missing API documentation
Posted: Tue Aug 31, 2021 10:19 am
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.
Re: Missing API documentation
Posted: Tue Aug 31, 2021 4:34 pm
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