#!/usr/bin/perl # # Generate list of nodes to load from /etc/munin/munin.conf to check # all the machines reporting to sitesummary. use strict; use warnings; use SiteSummary; use Getopt::Std; sub usage { print <<EOF; Usage: $0 [-hmnw] -h Show usage information -m Generate munin configuration for all munin clients -n Generate nagios configuration for all nagios clients -w List all client DNS/IP-addresses and MAC addresses EOF } my %opts; getopts("hmnw", \%opts) || (usage(), exit(1)); my %hostnames; for_all_hosts(\&handle_host); if ($opts{'h'}) { usage(); exit 0; } elsif ($opts{'m'}) { print_munin_list(); } elsif ($opts{'w'}) { print_ip_hw_list(); } elsif ($opts{'n'}) { # XXX Nagios config generation do not work yet generate_nagios_config(); } else { print_list(); } exit 0; sub handle_host { my $hostid = shift; my $address = get_dns_address($hostid); $hostnames{$address} = $hostid; } sub print_list { for my $hostname (sort keys %hostnames) { print "$hostname\n"; } } sub is_pkg_installed { my ($hostid, $pkgname) = @_; # Check debian/dpkg-l for 'ii *pkgname ' my $path = get_filepath_current($hostid, "/debian/dpkg-l"); if (open (my $fh, $path)) { while(<$fh>) { if (m/^ii *$pkgname /) { close($fh); return 1 } } close($fh); } return undef; } sub is_munin_client { my $hostid = shift; return is_pkg_installed($hostid, "munin-node"); } sub is_nagios_client { my $hostid = shift; return is_pkg_installed($hostid, "nagios-nrpe-server") || is_pkg_installed($hostid, "nagios-text") || is_pkg_installed($hostid, "nagios2") || is_pkg_installed($hostid, "nagios3"); } sub print_munin_list { for my $hostname (sort keys %hostnames) { next unless (is_munin_client($hostnames{$hostname})); # Using hostname as address, to avoid hardcoding IP addresses in # the file. Might be an idea