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?
Using psql to query list of hosts and addresses
- 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Using psql to query list of hosts and addresses
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?
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?
- 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
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.
I'll still continue down the API path as this seems more logical.
Cheers
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; doneCheers
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Using psql to query list of hosts and addresses
Good deal. Thanks for posting your alternative as well. That may come in handy.
Re: Using psql to query list of hosts and addresses
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.
I don't have that information, but I know the API is there.