Getting a lists of hosts from the API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Matthew.Cary
Posts: 32
Joined: Fri Nov 10, 2017 11:43 am

Getting a lists of hosts from the API

Post 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.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Getting a lists of hosts from the API

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Matthew.Cary
Posts: 32
Joined: Fri Nov 10, 2017 11:43 am

Re: Getting a lists of hosts from the API

Post 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!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Getting a lists of hosts from the API

Post 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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked