X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=aptcheck%2Faptcheck.pl;h=ad72adba15804d9c2ed17e16e78a1f68b0e23bb7;hb=fe107795d8c5c5dd4df63dee5c7aa9ba81d13a45;hp=c5d17be7d0863094432dab624c1517b1f9a9d9dd;hpb=f7535a3e90a312d10eb50178cfb28f04598460df;p=git-tools-moved-to-github.git diff --git a/aptcheck/aptcheck.pl b/aptcheck/aptcheck.pl index c5d17be..ad72adb 100755 --- a/aptcheck/aptcheck.pl +++ b/aptcheck/aptcheck.pl @@ -31,6 +31,7 @@ my %normhosts; my %normpkgs; my %okhosts; my %skiphosts; +my %allhosts; my $sectot = 0; my $owntot = 0; my $normtot = 0; @@ -43,6 +44,7 @@ for $hline ( split("\n",$hostlist) ) { next if ($H =~ /^commands/ ); next if ($H =~ /^servicegroups/ ); print "Checking $H\n" if $debug; + $allhosts{$H}=1; my $apt = `ssh $H apt-get upgrade -s -o 'Debug::NoLocking=true' `; # Note, do not append -qq, we want some output even when nothing to do if ( !$apt ) { @@ -65,21 +67,19 @@ for $hline ( split("\n",$hostlist) ) { $pkgs++; my $key = $pkg; if ( $src =~ /Security/ ) { - $det .= "$pkg"; - $key = "$pkg"; + $det .= "$pkg (s) "; $sechosts{$H}=1; $secpkgs{$pkg}=1; $secs++; $sectot++; } elsif ( $src =~ /Indexdata/ ) { - $det .= "$pkg"; - $key = "$pkg"; + $det .= "$pkg (id) "; $ownhosts{$H}=1; $ownpkgs{$pkg}=1; $own++; $owntot++; } else { - $det .= "$pkg"; + $det .= "$pkg "; $normhosts{$H}=1; $normpkgs{$pkg}=1; $normtot++; @@ -87,9 +87,9 @@ for $hline ( split("\n",$hostlist) ) { if ( !$summary{$key} ) { $summary{$key} = ""; } + $summary{$key} .= "$H "; $new = strdiff($cur,$new); $cur = strdiff($new,$cur); - $summary{$key} .= "$H "; $det .= " "; $det .= "$cur "; $det .= "$new "; @@ -103,8 +103,13 @@ for $hline ( split("\n",$hostlist) ) { $table .= " $own from indexdata " if $own; } else { $table .= "ok"; + $okhosts{$H} = 1; } my $updlink = $wikilink . ucfirst($H) . "Updates" . $year; + # Fix some pages that do not follow the convention. + # Mostly because the host names would not make proper WikiWords + $updlink =~ s/Bugzilla3Updates/BugzillaUpdates/; + $updlink =~ s/Opencontent-solrUpdates/OpenContentSolrUpdates/; $table .= " Upd"; $table .= "\n"; $table .= $det if $pkgs; @@ -113,7 +118,7 @@ for $hline ( split("\n",$hostlist) ) { } $table .= "\n"; -# Produce page +# Page header my $outfile = "/tmp/aptcheck.html"; open F, ">$outfile" or die "Could not open $outfile for writing: $!"; @@ -123,45 +128,97 @@ print F "\n"; print F "

Apt package status

\n"; -# Summary table +# Summary table: one row for per host group +print F "

\n"; print F "\n"; print F "" ; -print F "\n" ; -print F "\n" ; -print F "" . "\n"; -print F "\n"; - - -print F "\n"; +print F "\n"; + +if ( $sectot ) { + print F "\n" ; + print F ""; + print F ""; + print F "\n"; } -print F " \n"; -#print F ""; -#print F ""; -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"; +} +if ( %skiphosts ) { + print F "\n"; + print F "\n"; +} +if ( %okhosts ) { + 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)) . " / $sectot
Indexdata
" . scalar(keys(%ownhosts)) . - " / " . scalar(keys(%ownpkgs)) . " / $owntot
Normal
" . scalar(keys(%normhosts)) . - " / " . scalar(keys(%normpkgs)) . " / $normtot
Hosts"; -for $HH ( sort(keys(%sechosts)) ) { - print F "$HH "; +print F "HostsPackages
Security
" . scalar(keys(%sechosts)) . + " / " . scalar(keys(%secpkgs)) . " / $sectot
"; + for $HH ( sort(keys(%sechosts)) ) { + print F "$HH "; + } + print F ""; + for $PP ( sort(keys(%secpkgs)) ) { + print F "$PP "; + } + print F "
" . join(" ",sort(keys(%sechosts))) . " " . join(" ",sort(keys(%ownhosts))) . " "; -for $HH ( sort(keys(%ownhosts)) ) { - print F "$HH "; +if ( $owntot ) { + print F "
Indexdata
" . scalar(keys(%ownhosts)) . + " / " . scalar(keys(%ownpkgs)) . " / $owntot
"; + for $HH ( sort(keys(%ownhosts)) ) { + print F "$HH "; + } + print F ""; + for $PP ( sort(keys(%ownpkgs)) ) { + print F "$PP "; + } + print F "
" . join(" ",sort(keys(%normhosts))) . " 
"; -for $HH ( sort(keys(%normhosts)) ) { - print F "$HH "; +if ( $normtot ) { + print F "
Normal
" . scalar(keys(%normhosts)) . + " / " . scalar(keys(%normpkgs)) . " / $normtot
"; + for $HH ( sort(keys(%normhosts)) ) { + print F "$HH "; + } + print F ""; + for $PP ( sort(keys(%normpkgs)) ) { + print F "$PP "; + } + print F "
Skipped " . scalar(keys(%skiphosts)) . ""; + for $HH ( sort(keys(%skiphosts)) ) { + print F "$HH "; + } + print F "
Ok " . scalar(keys(%okhosts)) . ""; + for $HH ( sort(keys(%okhosts)) ) { + print F "$HH "; + } + print F "
Packages" . join(" ",sort(keys(%secpkgs))) . " " . join(" ",sort(keys(%ownpkgs))) . " " . join(" ",sort(keys(%normpkgs))) . " 
\n"; + +# The host table print F $table; +# Package table +print F "

Packages\n"; +print F "\n"; +for $P ( sort(keys(%summary)) ) { + my $PN = $P; + $PN = "$P (s)" if ($secpkgs{$P}); + $PN = "$P (id)" if ($ownpkgs{$P}); + print F "\n"; + print F "\n"; + +} +print F "
$PN"; + for $HH ( split(' ',$summary{$P} )) { + print F "$HH "; + } + print F "
\n"; + print F "

Produced " . `date`. " on " . `hostname` . " by " . `whoami` . "
\n"; @@ -172,19 +229,24 @@ close(F) system "scp -q $outfile nagios:/var/www/heikki/index.html"; +exit(0); + # Helper to take two strings and highligt that part of the second # that is different from the first. sub strdiff { my $x = shift; my $y = shift; print "strdiff: '$x' '$y' \n" if $debug>1; + if ( $x eq $y ) { + return "$x ??"; + } my $a = 0; while ( $a < length($y) && substr($x,$a,1) eq substr($y,$a,1) ) { $a++; } if ( $a == length($y) ) { - return "$y ???"; + return "$y ??"; } my $b = 1; while ( $b < length($y)-$a &&