From 70028dc70af1fb94bd430acce15a2c9de0def8fb Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Thu, 17 Mar 2011 12:51:49 +0100 Subject: [PATCH] Added a summary table in the beginning, with links --- aptcheck/aptcheck.pl | 60 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/aptcheck/aptcheck.pl b/aptcheck/aptcheck.pl index 23dab9d..ac4893f 100755 --- a/aptcheck/aptcheck.pl +++ b/aptcheck/aptcheck.pl @@ -20,10 +20,20 @@ my $hostlist = `ssh nagios grep -l Apt /etc/nagios3/indexdata-conf.d/*.cfg` or die "Could not get host list"; print "Got list:\n$hostlist\n" if $debug>2; -my $table = "\n"; + +# Statistics my %summary; my %sechosts; my %secpkgs; +my %ownhosts; +my %ownpkgs; +my %normhosts; +my %normpkgs; +my %okhosts; +my %skiphosts; + +my $table = "
\n"; + for $hline ( split("\n",$hostlist) ) { next unless ( $hline =~ /\/([a-z0-9]+)\.cfg$/ ); my $H = $1; @@ -35,6 +45,7 @@ for $hline ( split("\n",$hostlist) ) { if ( !$apt ) { $table .= "\n"; $table .= "\n"; } $table .= "\n"; - $table .= "
 
$H (skipped)\n"; + $skiphosts{$H}=1; next; } print "Got apts for $H: \n$apt\n" if $debug>2; @@ -59,9 +70,13 @@ for $hline ( split("\n",$hostlist) ) { } elsif ( $src =~ /Indexdata/ ) { $det .= "$pkg"; $key = "$pkg"; + $ownhosts{$H}=1; + $ownpkgs{$pkg}=1; $own++; } else { $det .= "$pkg"; + $normhosts{$H}=1; + $normpkgs{$pkg}=1; } if ( !$summary{$key} ) { $summary{$key} = ""; @@ -75,7 +90,7 @@ for $hline ( split("\n",$hostlist) ) { $det .= "
 
$H  \n"; + $table .= "
$H  \n"; if ( $pkgs ) { $table .= "$pkgs packages to upgrade. "; $table .= "$secs security. " if $secs; @@ -101,12 +116,43 @@ print F "Apt upgrade status\n"; print F "\n"; print F "

Apt package status

\n"; -if ( %sechosts ) { - print F "

Security updates for " . - scalar(keys(%sechosts)) ." hosts:

\n"; - print F "" . join(" ", sort(keys(%sechosts)))."
". - join(" ", sort(keys(%secpkgs))). "

\n"; + +# Summary table +print F "\n"; +print F "" ; +print F "\n" ; +print F "\n" ; +print F "" . "\n"; +print F "\n"; + + +print F "\n"; +#print F ""; +#print F ""; +print F "\n"; +#print F "\n"; +print F "\n"; + +print F "\n"; +print F ""; +print F ""; +print F "\n"; +print F "
 Security: " . scalar(keys(%sechosts)) . + " / " . scalar(keys(%secpkgs)) . " Indexdata: " . scalar(keys(%ownhosts)) . + " / " . scalar(keys(%ownpkgs)) . " Normal: " . scalar(keys(%normhosts)) . + " / " . scalar(keys(%normpkgs)) . "
Hosts"; +for $HH ( sort(keys(%sechosts)) ) { + print F "$HH "; +} +print F " " . join(" ",sort(keys(%sechosts))) . " " . join(" ",sort(keys(%ownhosts))) . " "; +for $HH ( sort(keys(%ownhosts)) ) { + print F "$HH "; } +print F " " . join(" ",sort(keys(%normhosts))) . " 
"; +for $HH ( sort(keys(%normhosts)) ) { + print F "$HH "; +} +print F " 
Packages" . join(" ",sort(keys(%secpkgs))) . " " . join(" ",sort(keys(%ownpkgs))) . " " . join(" ",sort(keys(%normpkgs))) . " 
\n"; print F $table; -- 1.7.10.4