diff options
Diffstat (limited to 'agesinceseen-summary')
-rw-r--r-- | agesinceseen-summary | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/agesinceseen-summary b/agesinceseen-summary new file mode 100644 index 0000000..4bfed75 --- /dev/null +++ b/agesinceseen-summary @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use SiteSummary; +use Getopt::Std; + +my %agegroup = + ( + 3 => '>3 days', + 7 => '>one week', + 14 => '>14 days', + 30 => '>30 days', + 90 => '>90 days', +); + +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 $topdir = get_filepath_current($hostid, "/"); + my $age = (time() - (stat($topdir))[9]) / (60 * 60 * 24); + + my $thisgroup; + for my $group (sort { $a <=> $b; } keys %agegroup) { + if ($age > $group) { + $thisgroup = $group; + } + } + if (defined $thisgroup) { + if (exists $agedist{$thisgroup}) { + push @{$agedist{$thisgroup}}, $hostid ; + } else { + $agedist{$thisgroup} = [$hostid]; + } + } +} + +sub print_summary { + printf(" %-20s %5s\n", "hostclass", "count"); + for my $group (sort { $a <=> $b; } keys %agedist) { + printf(" %-20s %5d\n", $agegroup{$group}, scalar @{$agedist{$group}}); + if (exists $opts{l}) { + for my $hostid (@{$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"; + } + } +} |