在Nagios 2和3中,我正在寻找一种将所有受监视主机的列表导出为CSV或XML或类似的方法。
这个怎么样…
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"; }; '
它会吐出一个选项卡分隔列表与主机名,IP地址和每个主机在你的nagiosconfiguration的别名。
如果你没有在conf.d/hostsconfiguration你的主机,你可以试试这个:
grep host_name /var/log/nagios/objects.cache | cut -f3 | sort -u | paste -d, -s
看看MK Livestatus :
echo -e 'GET hosts\nColumns: address' | unixcat /var/nagios/rw/live