Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In Nagios 2 and 3, I'm looking for a way to export a list of all monitored hosts to either CSV or XML or something similar.

share|improve this question

3 Answers 3

up vote 0 down vote accepted

How about this...

root@box:/etc/nagios3# cat conf.d/hosts/*.cfg | grep "host_name\|address\|alias" |grep -v localhost | perl -ne '$line = $_; 
chomp($line); 
if ($line =~ /host_name(.*)/) {
$match = $1 ;
$match =~ s/ |\t//g; 
print "\n".$match."\t";
}; 
if ($line =~ /address(.*)/) {
$match = $1 ;
$match =~ s/ |\t//g; 
print $match."\t";
}
if ($line =~ /alias(.*)/) {
$match = $1 ;
$match =~ s/^\s+//; 
$match =~ s/\t//g; 
print $match."\t";
}; 
'

It ll spit out a tab separated list with hostname, ip address and alias for each host in your nagios config.

share|improve this answer
    
This worked for me, but for some reason the hosts were in another subfolder. –  Lars May 27 '13 at 13:11

If you're not configuring your hosts in conf.d/hosts you may try this:

grep host_name /var/log/nagios/objects.cache | cut -f3 | sort -u | paste -d, -s
share|improve this answer

Take a look at MK Livestatus:

echo -e 'GET hosts\nColumns: address' | unixcat /var/nagios/rw/live
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.