Using psql to query list of hosts and addresses

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Using psql to query list of hosts and addresses

Post by Box293 »

How do I use psql to display a list of host's "host_name" and "address" directives?

Example:
host_name,address
server1,10.0.0.1
server2,10.0.0.2
server3,10.0.0.3

I just used a , in the example, the output does not need to be like this, the forums do not allow typing of multiple spaces

Is psql the best way to do this? If not what other ways are available?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Using psql to query list of hosts and addresses

Post by mguthrie »

Would the backend API data be of any help?

http://library.nagios.com/library/produ ... ackend-api

There's a plugin for Nagios XI that generates all of the backend data from every host and service and puts it into an XML format (including the host and address data). You could use whatever programming language you're comfortable with to grab the host and address elements. And do what you want with them from there. That'd be the easiest way to grab that data and use it somewhere. Does that help at all?
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Using psql to query list of hosts and addresses

Post by Box293 »

Yes this looks like the easiest way to get the data I need. I've had a quick play and it looks impressive.

I've been learning some more linux and another way I could obtain the information is with fgrep.
No pretty formatting but it does show the data I was looking for.

Code: Select all

for i in $(ls /usr/local/nagios/etc/hosts/*); do fgrep -e host_name -e address $i; done
I'll still continue down the API path as this seems more logical.

Cheers
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Using psql to query list of hosts and addresses

Post by mguthrie »

Good deal. Thanks for posting your alternative as well. That may come in handy.
mmestnik
Posts: 972
Joined: Mon Feb 15, 2010 2:23 pm

Re: Using psql to query list of hosts and addresses

Post by mmestnik »

If you are talking about php programming then the current environment, of say a wizard, already has this information in core memory. To access it you'll need some API foo, like the does host exist check.

I don't have that information, but I know the API is there.
Locked