aboutsummaryrefslogtreecommitdiffstats
path: root/site-summary
diff options
context:
space:
mode:
authorPetter Reinholdtsen <pere@hungry.com>2007-11-23 21:28:05 +0000
committerPetter Reinholdtsen <pere@hungry.com>2007-11-23 21:28:05 +0000
commit49e74efb846f5bac4bc29ee5fe4c3db7a918ced2 (patch)
tree6fed785524cd5c9139f91e0136b7be07db7744cc /site-summary
parentbee4f08184f47f860e32df6bc1f4c0328753e8c8 (diff)
downloadsitesummary-49e74efb846f5bac4bc29ee5fe4c3db7a918ced2.tar.gz
sitesummary-49e74efb846f5bac4bc29ee5fe4c3db7a918ced2.tar.bz2
sitesummary-49e74efb846f5bac4bc29ee5fe4c3db7a918ced2.tar.xz
Add -l support to site-summary too.
Diffstat (limited to 'site-summary')
-rwxr-xr-xsite-summary59
1 files changed, 52 insertions, 7 deletions
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;
+ }
+ }
+ }
}
}