[check_postgres] [commit] Support warning/crit for new_version_cp based on version. Show message as well.
check_postgres at bucardo.org
check_postgres at bucardo.org
Mon May 4 20:40:35 UTC 2009
Committed by Greg Sabino Mullane <greg at endpoint.com>
Support warning/crit for new_version_cp based on version. Show message as well.
---
check_postgres.pl | 31 +++++++++++++++++++++++--------
t/02_new_version_cp.t | 21 ++++++++++++++++-----
t/CP_Testing.pm | 5 ++++-
3 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/check_postgres.pl b/check_postgres.pl
index 9d83b4a..e87e515 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -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,
diff --git a/t/02_new_version_cp.t b/t/02_new_version_cp.t
index c987e2a..1f8f536 100644
--- a/t/02_new_version_cp.t
+++ b/t/02_new_version_cp.t
@@ -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();
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index 99bd472..b77783e 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -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);
--
1.6.0.5
More information about the Check_postgres
mailing list