Details
[git-tools-moved-to-github.git] / aptcheck / aptcheck.pl
index ac4893f..ad72adb 100755 (executable)
@@ -31,15 +31,20 @@ 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 ) {
@@ -62,28 +67,29 @@ for $hline ( split("\n",$hostlist) ) {
         $pkgs++;
         my $key = $pkg;
         if ( $src =~ /Security/ ) {
-            $det .= "<b>$pkg</b>";
-            $key = "<b>$pkg</b>";
+            $det .= "<b>$pkg (s)</b> ";
             $sechosts{$H}=1;
             $secpkgs{$pkg}=1;
             $secs++;
+            $sectot++;
         } elsif ( $src =~ /Indexdata/ ) {
-            $det .= "<b><i>$pkg</i></b>";
-            $key = "<i>$pkg</i>";
+            $det .= "<i><b>$pkg</b> (id) </i>";
             $ownhosts{$H}=1;
             $ownpkgs{$pkg}=1;
             $own++;
+            $owntot++;
         } else {
-            $det .= "$pkg";
+            $det .= "$pkg ";
             $normhosts{$H}=1;
             $normpkgs{$pkg}=1;
+            $normtot++;
         }
         if ( !$summary{$key} ) {
             $summary{$key} = "";
         }
+        $summary{$key} .= "$H ";
         $new = strdiff($cur,$new);
         $cur = strdiff($new,$cur);
-        $summary{$key} .= "$H ";
         $det .= "</td> ";
         $det .= "<td>$cur</td> ";
         $det .= "<td>$new</td> ";
@@ -97,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 .= "&nbsp;<a href='$updlink' >Upd</a>";
     $table .= "</td></tr>\n";
     $table .= $det if $pkgs;
@@ -107,7 +118,7 @@ for $hline ( split("\n",$hostlist) ) {
 }
 $table .= "</table>\n";
 
-# Produce page
+# Page header
 my $outfile = "/tmp/aptcheck.html";
 open F, ">$outfile"
     or die "Could not open $outfile for writing: $!";
@@ -117,45 +128,97 @@ print F "<body>\n";
 print F "<H1>Apt package status</H1>\n";
 
 
-# Summary table
+# Summary table: one row for per host group
+print F "<p/>\n";
 print F "<table border='1' >\n";
 print F "<tr><td>&nbsp;</td>" ;
-print F "<td><b>Security:</b> " . scalar(keys(%sechosts)) . 
-        " / " .  scalar(keys(%secpkgs)) . " </td>\n" ;
-print F "<td>Indexdata: " . scalar(keys(%ownhosts)) . 
-        " / " .  scalar(keys(%ownpkgs)) . " </td>\n" ;
-print F "<td>Normal: " . scalar(keys(%normhosts)) . 
-        " / " .  scalar(keys(%normpkgs)) . " </td>" . "</tr>\n";
-print F "<tr><td>Hosts</td>\n";
-
-
-print F "<td>";
-for $HH ( sort(keys(%sechosts)) ) {
-    print F "<a href='#$HH'><b>$HH</b></a> ";
+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)) . 
+        "&nbsp;/&nbsp;" .  scalar(keys(%secpkgs)) . "&nbsp;/&nbsp;$sectot </td>\n" ;
+    print F "<td>";
+    for $HH ( sort(keys(%sechosts)) ) {
+        print F "<a href='#$HH'><b>$HH</b></a> ";
+    }
+    print F "</td>";
+    print F "<td>";
+    for $PP ( sort(keys(%secpkgs)) ) {
+        print F "<a href='#$PP'>$PP</a> ";
+    }
+    print F "</td>";
+    print F "</tr>\n";
 }
-print F "&nbsp;</td>\n";
-#print F "<td><b>" . join(" ",sort(keys(%sechosts))) . "</b>&nbsp;</td>";
-#print F "<td><b>" . join(" ",sort(keys(%ownhosts))) . "</b>&nbsp;</td>";
-print F "<td>";
-for $HH ( sort(keys(%ownhosts)) ) {
-    print F "<a href='#$HH'><b>$HH</b></a> ";
+if ( $owntot ) {
+    print F "<tr><td><b>Indexdata</b><br/>" . scalar(keys(%ownhosts)) . 
+        "&nbsp;/&nbsp;" .  scalar(keys(%ownpkgs)) . "&nbsp;/&nbsp;$owntot </td>\n" ;
+    print F "<td>";
+    for $HH ( sort(keys(%ownhosts)) ) {
+        print F "<a href='#$HH'><b>$HH</b></a> ";
+    }
+    print F "</td>";
+    print F "<td>";
+    for $PP ( sort(keys(%ownpkgs)) ) {
+        print F "<a href='#$PP'>$PP</a> ";
+    }
+    print F "</td>";
+    print F "</tr>\n";
 }
-print F "&nbsp;</td>\n";
-#print F "<td><b>" . join(" ",sort(keys(%normhosts))) . "</b>&nbsp;</td></tr>\n";
-print F "<td>";
-for $HH ( sort(keys(%normhosts)) ) {
-    print F "<a href='#$HH'><b>$HH</b></a> ";
+if ( $normtot ) {
+    print F "<tr><td>Normal<br/>" . scalar(keys(%normhosts)) . 
+        "&nbsp;/&nbsp;" .  scalar(keys(%normpkgs)) . "&nbsp;/&nbsp;$normtot </td>\n" ;
+    print F "<td>";
+    for $HH ( sort(keys(%normhosts)) ) {
+        print F "<a href='#$HH'><b>$HH</b></a> ";
+    }
+    print F "</td>";
+    print F "<td>";
+    for $PP ( sort(keys(%normpkgs)) ) {
+        print F "<a href='#$PP'>$PP</a> ";
+    }
+    print F "</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 "&nbsp;</td>\n";
-
-print F "<tr><td>Packages</td>\n";
-print F "<td>" . join(" ",sort(keys(%secpkgs))) . "&nbsp;</td>";
-print F "<td>" . join(" ",sort(keys(%ownpkgs))) . "&nbsp;</td>";
-print F "<td>" . join(" ",sort(keys(%normpkgs))) . "&nbsp;</td></tr>\n";
 print F "</table>\n";
 
+
+# The host table
 print F $table;
 
+# Package table
+print F "<p/><b><u>Packages</u></b>\n";
+print F "<table>\n";
+for $P ( sort(keys(%summary)) ) {
+    my $PN = $P;
+    $PN = "<b>$P (s)</b>" if ($secpkgs{$P});
+    $PN = "$P (id)" if ($ownpkgs{$P});
+    print F "<tr><td><a name='$P'/>$PN</td>\n";
+    print F "<td>";
+    for $HH ( split(' ',$summary{$P} )) {
+        print F "<a href=#$HH>$HH</a> ";
+    }
+    print F "</td>\n";
+
+}
+print F "</table>\n";
+
 print F "<p/>Produced " . `date`.
         " on " . `hostname` . " by " . `whoami` .
         "<br/>\n";
@@ -166,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 <b>??</b>";
+    }
     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 &&