Page 1 of 1

Getting a lists of hosts from the API

Posted: Thu Apr 05, 2018 3:57 pm
by Matthew.Cary
Is there a good way to get a list of all hosts from the API?

I'm not looking to check the status of any given host. My eventual goal is to script a compare/contrast between what is in nagios and what is in another system. It feels like an API call should work, but I'm not finding a way to just dump a list.

Re: Getting a lists of hosts from the API

Posted: Thu Apr 05, 2018 4:12 pm
by npolovenko
Hello, @Matthew.Cary .

There are at least two ways to get a list of hosts:

Option number one is to use a Core jsonquery generator:

1. Paste the following link into your web browser, but replace my Nagios XI IP with yours.

Code: Select all

http://192.168.4.172/nagios/jsonquery.html
2. Sign in with your nagiosadmin login and password.
3. Select Object JSON CGI, Query -> Hostlist and click on Send Query.
You can either view the query result in the right column, or copy the lin kand use it in your script, or elsewhere.

Option 2:
Go to the regular NagiosXI web interface
Open the Help menu at the top
In the left column click on Objects Reference
Scroll down the page till you see the objects/host query

Let me know if you have other questions.

Re: Getting a lists of hosts from the API

Posted: Thu Apr 05, 2018 5:28 pm
by Matthew.Cary
Thank you very much. The JSON approach hadn't occurred to me.

I was hoping to filter down to just hostnames with the API call, but a list host definitions should be fine. I can parse out the hostnames from there.

This should be what I needed!

Re: Getting a lists of hosts from the API

Posted: Fri Apr 06, 2018 9:05 am
by lmiltchev
I am glad this solution worked out for you! As an alternative, you could also go Help > Object Reference, and click on the "GET objects/host" link on the right hand side.

Example URL:
https://nagiosxi.demos.nagios.com/nagio ... h&pretty=1

Next, type "host_name" in the "Filter JSON" box, and hit "Enter". This should give you a list of hosts too.

Let us know if it is OK to close the topic, and mark it as resolved. Thank you!