diff options
-rw-r--r-- | SiteSummary.pm | 43 | ||||
-rw-r--r-- | debian/changelog | 10 | ||||
-rwxr-xr-x | sitesummary-nodes | 50 |
3 files changed, 86 insertions, 17 deletions
diff --git a/SiteSummary.pm b/SiteSummary.pm index f710e15..fec7b09 100644 --- a/SiteSummary.pm +++ b/SiteSummary.pm @@ -12,9 +12,10 @@ our @EXPORT = qw( get_filepath_current get_site get_sitegroup + get_hostname get_linux_kernel_ver - get_debian_edu_profile - get_debian_edu_ver + get_debian_edu_profile + get_debian_edu_ver ); my $pwd = "/var/lib/sitesummary/entries"; # Path to the entries @@ -65,6 +66,14 @@ sub get_sitegroup { } # +# Return the hostname string +# +sub get_hostname { + my $hostid = shift; + return get_file_string($hostid, "/system/hostname"); +} + +# # Return Linux kernel version for the machines using Linux. # sub get_linux_kernel_ver { @@ -77,7 +86,7 @@ sub get_linux_kernel_ver { s/\#.+$//; next if (/^\s*$/); my @f = (split(/\s+/, $_)); - $kver = $f[1] if ("Linux" eq $f[0]); + $kver = $f[1] if ("Linux" eq $f[0]); } close(FILE); return $kver; @@ -90,16 +99,16 @@ sub get_debian_edu_profile { my $hostid = shift; my $path = get_filepath_current($hostid, $debian_edu_config); if ( ! -e $path ) { - return undef; + return undef; } if (open (FILE, $path)) { - while (<FILE>) { - chomp; + while (<FILE>) { + chomp; s/\#.+$//; - next if not (/PROFILE/); - s/^PROFILE=//; - return $_; - } + next if not (/PROFILE/); + s/^PROFILE=//; + return $_; + } } close(FILE); } @@ -108,16 +117,16 @@ sub get_debian_edu_ver { my $hostid = shift; my $path = get_filepath_current($hostid, $debian_edu_config); if ( ! -e $path ) { - return undef; + return undef; } if (open (FILE, $path)) { - while (<FILE>) { - chomp; + while (<FILE>) { + chomp; s/\#.+$//; - next if not (/VERSION/); - s/^VERSION=//; - return $_; - } + next if not (/VERSION/); + s/^VERSION=//; + return $_; + } } } diff --git a/debian/changelog b/debian/changelog index 35708c7..4ac2b90 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +sitesummary (0.0.25) UNRELEASED; urgency=low + + [ Petter Reinholdtsen ] + * New perl function get_hostname() available from the SiteSummary + perl module. + * Add script sitesummary-nodes to list all reporting nodes. Use -m + to list them in the format expected in /etc/munin/munin.conf. + + -- Petter Reinholdtsen <pere@debian.org> Fri, 18 May 2007 09:24:23 +0200 + sitesummary (0.0.24) unstable; urgency=low [ Bart Cornelis (cobaco) ] diff --git a/sitesummary-nodes b/sitesummary-nodes new file mode 100755 index 0000000..1c3b0df --- /dev/null +++ b/sitesummary-nodes @@ -0,0 +1,50 @@ +#!/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; + +my %opts; +getopts("m", \%opts); + +my %hostnames; + +for_all_hosts(\&handle_host); + +if ($opts{'m'}) { + print_munin_list(); +} else { + print_list(); +} + +sub handle_host { + my $hostid = shift; + my $hostname = get_hostname($hostid); + $hostnames{$hostname} = 1; +} + +sub print_list { + for my $hostname (sort keys %hostnames) { + print "$hostname\n"; + } +} + +sub print_munin_list { + for my $hostname (sort keys %hostnames) { + + # Using hostname as address, to avoid hardcoding IP addresses in + # the file. Might be an idea to fetch the IP address from + # system/ifconfig-a + print <<EOF; +[$hostname] + address $hostname + use_node_name yes + +EOF + } +} |