Page 1 of 1
Using psql to query list of hosts and addresses
Posted: Mon Jul 12, 2010 6:05 am
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?
Re: Using psql to query list of hosts and addresses
Posted: Tue Jul 13, 2010 9:38 am
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?
Re: Using psql to query list of hosts and addresses
Posted: Tue Jul 13, 2010 4:58 pm
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
Re: Using psql to query list of hosts and addresses
Posted: Wed Jul 14, 2010 8:40 am
by mguthrie
Good deal. Thanks for posting your alternative as well. That may come in handy.
Re: Using psql to query list of hosts and addresses
Posted: Wed Jul 14, 2010 3:39 pm
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.