or die "Could not get host list";
print "Got list:\n$hostlist\n" if $debug>2;
-my $table = "<table>\n";
+
+# Statistics
my %summary;
my %sechosts;
my %secpkgs;
+my %ownhosts;
+my %ownpkgs;
+my %normhosts;
+my %normpkgs;
+my %okhosts;
+my %skiphosts;
+my %allhosts;
+my $sectot = 0;
+my $owntot = 0;
+my $normtot = 0;
+
+my $table = "<table>\n";
+
for $hline ( split("\n",$hostlist) ) {
- next unless ( $hline =~ /\/([a-z0-9]+)\.cfg$/ );
+ next unless ( $hline =~ /\/([a-z0-9-]+)\.cfg$/ );
my $H = $1;
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 ) {
$table .= "<tr><td colspan='3'> </td></tr>\n";
$table .= "<tr><td colspan='3'><b><u>$H</u></b> (skipped)\n";
+ $skiphosts{$H}=1;
next;
}
print "Got apts for $H: \n$apt\n" if $debug>2;
$pkgs++;
my $key = $pkg;
if ( $src =~ /Security/ ) {
- $det .= "<b>$pkg</b>";
+ $det .= "<b>$pkg (s) </b>";
$key = "<b>$pkg</b>";
$sechosts{$H}=1;
$secpkgs{$pkg}=1;
$secs++;
+ $sectot++;
} elsif ( $src =~ /Indexdata/ ) {
- $det .= "<b><i>$pkg</i></b>";
+ $det .= "<i><b>$pkg</b> (id) </i>";
$key = "<i>$pkg</i>";
+ $ownhosts{$H}=1;
+ $ownpkgs{$pkg}=1;
$own++;
+ $owntot++;
} else {
$det .= "$pkg";
+ $normhosts{$H}=1;
+ $normpkgs{$pkg}=1;
+ $normtot++;
}
if ( !$summary{$key} ) {
$summary{$key} = "";
$det .= "</tr>\n";
}
$table .= "<tr><td colspan='3'> </td></tr>\n";
- $table .= "<tr><td colspan='3'><b><u>$H</u></b> \n";
+ $table .= "<tr><td colspan='3'><a name='$H'><b><u>$H</u></b></a> \n";
if ( $pkgs ) {
$table .= "<b>$pkgs</b> packages to upgrade. ";
$table .= "<b>$secs security</b>. " if $secs;
$table .= " $own from indexdata " if $own;
} else {
$table .= "ok";
+ $okhosts{$H} = 1;
}
my $updlink = $wikilink . ucfirst($H) . "Updates" . $year;
$table .= " <a href='$updlink' >Upd</a>";
}
$table .= "</table>\n";
-# Produce page
+# Page header
my $outfile = "/tmp/aptcheck.html";
open F, ">$outfile"
or die "Could not open $outfile for writing: $!";
print F "<body>\n";
print F "<H1>Apt package status</H1>\n";
-if ( %sechosts ) {
- print F "<h2>Security updates for " .
- scalar(keys(%sechosts)) ." hosts: </h2>\n";
- print F "<b>" . join(" ", sort(keys(%sechosts)))."</b><br/> ".
- join(" ", sort(keys(%secpkgs))). "<p/>\n";
+
+# Summary table - NEW: one row for per host group
+print F "<p/>\n";
+print F "<table border='1' >\n";
+print F "<tr><td> </td>" ;
+print F "<td><b>Hosts</b></td>\n";
+print F "<td><b>Packages</b></td></tr>\n";
+
+if ( $sectot ) {
+ print F "<tr><td><b>Security</b><br/>" . scalar(keys(%sechosts)) .
+ " / " . scalar(keys(%secpkgs)) . " / $sectot </td>\n" ;
+ print F "<td>";
+ for $HH ( sort(keys(%sechosts)) ) {
+ print F "<a href='#$HH'><b>$HH</b></a> ";
+ }
+ print F "<td>" . join(" ",sort(keys(%secpkgs))) . " </td>";
+ print F "</tr>\n";
+}
+if ( $owntot ) {
+ print F "<tr><td><b>Indexdata</b><br/>" . scalar(keys(%ownhosts)) .
+ " / " . scalar(keys(%ownpkgs)) . " / $owntot </td>\n" ;
+ print F "<td>";
+ for $HH ( sort(keys(%ownhosts)) ) {
+ print F "<a href='#$HH'><b>$HH</b></a> ";
+ }
+ print F "<td>" . join(" ",sort(keys(%ownpkgs))) . " </td>";
+ print F "</tr>\n";
+}
+if ( $normtot ) {
+ print F "<tr><td>Indexdata<br/>" . scalar(keys(%normhosts)) .
+ " / " . scalar(keys(%normpkgs)) . " / $normtot </td>\n" ;
+ print F "<td>";
+ for $HH ( sort(keys(%normhosts)) ) {
+ print F "<a href='#$HH'><b>$HH</b></a> ";
+ }
+ print F "<td>" . join(" ",sort(keys(%normpkgs))) . " </td>";
+ print F "</tr>\n";
+}
+if ( %skiphosts ) {
+ print F "<tr><td>Skipped: " . scalar(keys(%skiphosts)) . "</td>\n";
+ print F "<td colspan='2'>";
+ for $HH ( sort(keys(%skiphosts)) ) {
+ print F "<a href='#$HH'><b>$HH</b></a> ";
+ }
+ print F "</td></tr>\n";
}
+if ( %okhosts ) {
+ print F "<tr><td>Ok: " . scalar(keys(%okhosts)) . "</td>\n";
+ print F "<td colspan='2'>";
+ for $HH ( sort(keys(%okhosts)) ) {
+ print F "<a href='#$HH'><b>$HH</b></a> ";
+ }
+ print F "</td></tr>\n";
+}
+print F "</table>\n";
+
+# The host table
print F $table;
print F "<p/>Produced " . `date`.
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 {