blob: ddfd7ff0f71d43ce772728be440948000d63dffc (
plain)
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
51
52
53
54
|
#!/usr/bin/perl
use strict;
use warnings;
use SiteSummary;
use Getopt::Std;
my %agedist;
my %opts;
sub usage {
my $retval = shift;
print <<EOF;
Usage: $0 [-l]
-l list hosts with the given age
EOF
exit $retval;
}
getopt("l", \%opts) || usage(1);
for_all_hosts(\&handle_host);
print_summary();
sub handle_host {
my $hostid = shift;
my $thisgroup = get_age_group($hostid);
if (defined $thisgroup) {
if (exists $agedist{$thisgroup}) {
push @{$agedist{$thisgroup}}, $hostid ;
} else {
$agedist{$thisgroup} = [$hostid];
}
}
}
sub print_summary {
printf(" %-20s %5s\n", "age", "count");
my %agegroups = get_age_groups();
for my $group (sort { $a <=> $b; } keys %agedist) {
printf(" %-20s %5d\n", $agegroups{$group}, scalar @{$agedist{$group}});
if (exists $opts{l}) {
for my $hostid (sort @{$agedist{$group}}) {
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;
}
print "\n";
}
}
}
|