1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#!/usr/bin/perl
use strict;
use warnings;
use SiteSummary;
use Getopt::Std;
my %hostclasses;
my %hostmap;
my %opts;
sub usage {
my $retval = shift;
print <<EOF;
Usage: $0 [-l]
-l list hosts with the host class version
EOF
exit $retval;
}
getopt("l", \%opts) || usage(1);
for_all_hosts(\&handle_host);
print_summary();
sub handle_host {
my $hostid = shift;
#print "$hostid\n";
for my $hostclass (get_hostclass($hostid)) {
$hostclass = "" unless defined $hostclass;
$hostclasses{$hostclass}++;
$hostmap{$hostclass} = [] unless exists $hostmap{$hostclass};
push @{$hostmap{$hostclass}}, $hostid ;
}
}
sub print_summary {
printf(" %-20s %5s\n", "hostclass", "count");
for my $hostclass (sort keys %hostclasses) {
printf(" %-20s %5d\n", $hostclass, $hostclasses{$hostclass});
if (exists $opts{l}) {
for my $hostid (sort @{$hostmap{$hostclass}}) {
my $hostname = get_hostname($hostid);
printf " %s %s %s\n", $hostname, $hostclass, $hostid;
}
}
}
}
|