diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2007-11-23 21:28:05 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2007-11-23 21:28:05 +0000 |
commit | 49e74efb846f5bac4bc29ee5fe4c3db7a918ced2 (patch) | |
tree | 6fed785524cd5c9139f91e0136b7be07db7744cc | |
parent | bee4f08184f47f860e32df6bc1f4c0328753e8c8 (diff) | |
download | sitesummary-49e74efb846f5bac4bc29ee5fe4c3db7a918ced2.tar.gz sitesummary-49e74efb846f5bac4bc29ee5fe4c3db7a918ced2.tar.bz2 sitesummary-49e74efb846f5bac4bc29ee5fe4c3db7a918ced2.tar.xz |
Add -l support to site-summary too.
-rw-r--r-- | debian/changelog | 5 | ||||
-rwxr-xr-x | site-summary | 59 |
2 files changed, 55 insertions, 9 deletions
diff --git a/debian/changelog b/debian/changelog index db32d91..2b75db8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,8 @@ summary (0.0.31) UNRELEASED; urgency=low - * Add -l option to kernelversion-summary, to get it to list the - individual hosts with the given kernel version. + * Add -l option to kernelversion-summary and site-summary, to get it + to list the individual hosts with the given kernel version and + site/sitegroup setting. * New script agesinceseen-summary, listing the hosts that have failed to submit a report in the last few days. It support -l to list the individual hosts. diff --git a/site-summary b/site-summary index 8461ef0..e914719 100755 --- a/site-summary +++ b/site-summary @@ -4,9 +4,23 @@ use strict; use warnings; use SiteSummary; +use Getopt::Std; my %sites; my %sitegroups; +my %hostmap; +my %opts; + +sub usage { + my $retval = shift; + print <<EOF; +Usage: $0 [-l] + -l list hosts with the given site/sitegroup +EOF + exit $retval; +} + +getopt("l", \%opts) || usage(1); for_all_hosts(\&handle_host); @@ -16,18 +30,49 @@ sub handle_host { my $hostid = shift; #print "$hostid\n"; for my $site (get_site($hostid)) { - $site = "" unless defined $site; - $sites{$site}++; - $sitegroups{$site}{get_sitegroup($hostid)}++ if get_sitegroup($hostid); + $site = "" unless defined $site; + $sites{$site}++; + my $sitegroup = get_sitegroup($hostid); + if ($sitegroup) { + $sitegroups{$site}{$sitegroup}++; + + if (exists $hostmap{$site}{$sitegroup}) { + push @{$hostmap{$site}{$sitegroup}}, $hostid ; + } else { + $hostmap{$site}{$sitegroup} = [$hostid]; + } + } else { + if (exists $hostmap{$site}) { + push @{$hostmap{$site}}, $hostid ; + } else { + $hostmap{$site} = [$hostid]; + } + } } } sub print_summary { printf(" %-20s %5s\n", "site", "count"); for my $site (sort keys %sites) { - printf(" %-20s %5d\n", $site, $sites{$site}); - for my $sitegroup (sort keys %{$sitegroups{$site}}) { - printf(" %-18s %5d\n", $sitegroup, $sitegroups{$site}{$sitegroup}); - } + printf(" %-20s %5d\n", $site, $sites{$site}); + if (exists $opts{l}) { + for my $hostid (sort @{$hostmap{$site}}) { + my $hostname = get_hostname($hostid); + my $site = get_site($hostid) || ""; + my $sitegroup = get_sitegroup($hostid) || ""; + printf " %s %s/%s %s\n", $hostname, $site, $sitegroup, $hostid; + } + } + for my $sitegroup (sort keys %{$sitegroups{$site}}) { + printf(" %-18s %5d\n", $sitegroup, $sitegroups{$site}{$sitegroup}); + if (exists $opts{l}) { + for my $hostid (sort @{$hostmap{$site}{$sitegroup}}) { + my $hostname = get_hostname($hostid); + my $site = get_site($hostid) || ""; + my $sitegroup = get_sitegroup($hostid) || ""; + printf " %s %s/%s %s\n", $hostname, $site, $sitegroup, $hostid; + } + } + } } } |