Support warning/crit for new_version_cp based on version. Show message as well.
authorGreg Sabino Mullane <[email protected]>
Mon, 4 May 2009 20:39:58 +0000 (16:39 -0400)
committerGreg Sabino Mullane <[email protected]>
Mon, 4 May 2009 20:39:58 +0000 (16:39 -0400)
check_postgres.pl
t/02_new_version_cp.t
t/CP_Testing.pm

index 9d83b4a85ade864caf0467567a278321917bb4a2..e87e515b3ae9e795683daf9a69dc61fdead23ec5 100755 (executable)
@@ -815,7 +815,7 @@ sub add_response {
                $db->{host} .= " => $opt{host2}->[0]";
        }
        if ($nohost) {
-               push @{$type->{''}} => [$msg,''];
+               push @{$type->{''}} => [$msg, length $nohost > 1 ? $nohost : ''];
                return;
        }
        my $header = sprintf q{%s%s%s},
@@ -4509,16 +4509,16 @@ sub check_new_version_cp {
        my $site = 'bucardo.org';
        my $path = 'check_postgres/latest_version.txt';
        my $url = "http://$site/$path";
-       my $newver = '';
-       my $versionre = qr{\d+\.\d+\.\d+};
+       my ($newver,$maj,$rev,$message) = ('','','','');
+       my $versionre = qr{((\d+\.\d+)\.(\d+))\s+(.+)};
 
        for my $meth (@get_methods) {
                eval {
                        my $COM = "$meth $url";
                        $VERBOSE >= 1 and warn "TRYING: $COM\n";
                        my $info = qx{$COM 2>/dev/null};
-                       if ($info =~ /($versionre)/) {
-                               $newver = $1;
+                       if ($info =~ $versionre) {
+                               ($newver,$maj,$rev,$message) = ($1,$2,$3,$4);
                        }
                        $VERBOSE >=1 and warn "SET version to $newver\n";
                };
@@ -4527,13 +4527,28 @@ sub check_new_version_cp {
 
        if (! length $newver) {
                add_unknown msg('new-cp-fail');
+               return;
+       }
+
+       if ($newver eq $VERSION) {
+               add_ok msg('new-cp-ok', $newver);
+               return;
+       }
+
+       if ($VERSION !~ /(\d+\.\d+)\.(\d+)/) {
+               add_unknown msg('new-cp-fail');
+               return;
        }
-       elsif ($newver ne $VERSION) {
+
+       $nohost = $message;
+       my ($cmaj,$crev) = ($1,$2);
+       if ($cmaj eq $maj) {
                add_warning msg('new-cp-warn', $newver, $VERSION);
        }
        else {
-               add_ok msg('new-cp-ok', $newver);
+               add_critical msg('new-cp-warn', $newver, $VERSION);
        }
+       return;
 
 } ## end of check_new_version_cp
 
@@ -6080,7 +6095,7 @@ Items not specifically attributed are by Greg Sabino Mullane.
 
   Added internationalization support (Greg)
   Added the 'disabled_triggers' check (Greg)
-  Added the prepared_txns' check (Greg)
+  Added the 'prepared_txns' check (Greg)
   Added the 'new_version_cp' and 'new_version_pg' checks (Greg)
   French translations (Guillaume Lelarge)
   Make the backends search return ok if no matches due to inclusion rules,
index c987e2a40b7aab91eb7611ff306d14131a943ae3..1f8f536d2d9f9a722e250eedd611e36a4b0c0938 100644 (file)
@@ -6,11 +6,11 @@ use 5.006;
 use strict;
 use warnings;
 use Data::Dumper;
-use Test::More tests => 3;
+use Test::More tests => 5;
 use lib 't','.';
 use CP_Testing;
 
-use vars qw/$dbh $t/;
+use vars qw/$dbh $t $info/;
 
 my $cp = CP_Testing->new( {default_action => 'new_version_cp'} );
 
@@ -22,11 +22,22 @@ my $label = 'POSTGRES_NEW_VERSION_CP';
 $t=qq{$S fails when called with an invalid option};
 like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t);
 
+$t=qq{$S returns critical for mismatched major version};
+$cp->fake_self_version('1.2.3');
+$info = $cp->run('');
+like ($info, qr{$label CRITICAL:  Version \d+\.\d+\.\d+ of check_postgres.pl exists}, $t);
+$info =~ /((\d+\.\d+\.)(\d+))/ or die "Invalid version!?\n";
+my ($current_version,$cmaj,$crev) = ($1,$2,$3);
+
+$t=qq{$S returns a message about the latest version};
+like ($info, qr{\| \w\w}, $t);
+
 $t=qq{$S returns okay for matching version};
-like ($cp->run(''), qr{$label OK:  Version \d+\.\d+\.\d+ is the latest for check_postgres.pl}, $t);
+$cp->fake_self_version($current_version);
+like ($cp->run(''), qr{$label OK:  Version $current_version is the latest for check_postgres.pl}, $t);
 
-$t=qq{$S returns warning for mismatched version};
-$cp->fake_self_version('1.2.3');
+$t=qq{$S returns warning for mismatched revision};
+$cp->fake_self_version($cmaj . ($crev==0 ? 99 : $crev-1));
 like ($cp->run(''), qr{$label WARNING:  Version \d+\.\d+\.\d+ of check_postgres.pl exists}, $t);
 
 $cp->restore_self_version();
index 99bd47267cc5e628b4de2882bb14ded86c4ab7f3..b77783e96da6dc2869a98548de8bb09e4e31a443 100644 (file)
@@ -637,6 +637,9 @@ sub fake_self_version {
        open my $fh, '+<', $file or die qq{Could not open "$file": $!\n};
        my $slurp;
        { local $/; $slurp = <$fh> }
+       ## Remove any old versions
+       $slurp =~ s/^\$VERSION = '\d+\.\d+\.\d+'.+TESTING ONLY\n//gm;
+       ## Put in out new version
        $slurp =~ s/(our \$VERSION = '\d+\.\d+\.\d+';)/$1\n\$VERSION = '$version'; ## TESTING ONLY/;
        seek $fh, 0, 0;
        print $fh $slurp;
@@ -654,7 +657,7 @@ sub restore_self_version {
        open my $fh, '+<', $file or die qq{Could not open "$file": $!\n};
        my $slurp;
        { local $/; $slurp = <$fh> }
-       $slurp =~ s/^\$VERSION = '\d+\.\d+\.\d+'.+?\n//gm;
+       $slurp =~ s/^\$VERSION = .+TESTING ONLY.*\n//gm;
        seek $fh, 0, 0;
        print $fh $slurp;
        truncate $fh, tell($fh);