File: agesinceseen-summary

package info (click to toggle)
sitesummary 0.1.17+deb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 468 kB
  • ctags: 103
  • sloc: perl: 1,742; sh: 787; makefile: 84
file content (54 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (7)
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";
        }
    }
}