[check_postgres] [commit] Don't allow values over 2 billion for wraparound check.

check_postgres at bucardo.org check_postgres at bucardo.org
Thu Apr 30 13:26:56 UTC 2009


Committed by Greg Sabino Mullane <greg at endpoint.com>

Don't allow values over 2 billion for wraparound check.
Older version compatibility.

---
 check_postgres.pl     |   11 +++++++++++
 t/02_txn_wraparound.t |   31 +++++++++++++++++++------------
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index b778462..8bd874c 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -262,6 +262,8 @@ our %msg = (
 	'txntime-fail'       => q{Query failed},
 	'txntime-msg'        => q{longest txn: $1s},
 	'txntime-none'       => q{No transactions},
+	'txnwrap-wbig'       => q{The 'warning' value must be less than 2 billion},
+	'txnwrap-cbig'       => q{The 'critical' value must be less than 2 billion},
 	'unknown-error'      => q{Unknown error},
 	'usage'              => qq{\nUsage: \$1 <options>\n Try "\$1 --help" for a complete list of options\n\n},
 	'vac-msg'            => q{DB: $1 TABLE: $2},
@@ -451,6 +453,8 @@ our %msg = (
 	'txntime-fail'       => q{Échec de la requête},
 	'txntime-msg'        => q{Transaction la plus longue : $1s},
 	'txntime-none'       => q{Aucune transaction},
+'txnwrap-wbig'       => q{The 'warning' value must be less than 2 billion},
+'txnwrap-cbig'       => q{The 'critical' value must be less than 2 billion},
 	'unknown-error'      => q{erreur inconnue},
 	'usage'              => qq{\nUsage: \$1 <options>\n Essayez « \$1 --help » pour liste complète des options\n\n},
 	'vac-msg'            => q{Base de données : $1 Table : $2},
@@ -3905,6 +3909,13 @@ sub check_txn_wraparound {
 		  default_critical => 1_400_000_000,
 		  });
 
+	if ($warning and $warning >= 2_000_000_000) {
+		ndie msg('txnwrap-wbig');
+	}
+	if ($critical and $critical >= 2_000_000_000) {
+		ndie msg('txnwrap-cbig');
+	}
+
 	$SQL = q{SELECT datname, age(datfrozenxid) FROM pg_database WHERE datallowconn ORDER BY 1, 2};
 	my $info = run_command($SQL, { regex => qr[\w+\s+\|\s+\d+] } );
 
diff --git a/t/02_txn_wraparound.t b/t/02_txn_wraparound.t
index 8e06100..c44af2a 100644
--- a/t/02_txn_wraparound.t
+++ b/t/02_txn_wraparound.t
@@ -6,7 +6,7 @@ use 5.006;
 use strict;
 use warnings;
 use Data::Dumper;
-use Test::More tests => 14;
+use Test::More tests => 16;
 use lib 't','.';
 use CP_Testing;
 
@@ -30,35 +30,42 @@ like ($result, qr{^$label}, $t);
 
 $t = qq{$S identifies each database};
 like ($result, qr{ardala=\d+ beedeebeedee=\d+ postgres=\d+ template1=\d+}, $t);
-my $txn_measure;
 $result =~ /ardala=(\d+)/;
-$txn_measure = $1;
+my $txn_measure = $1;
 
 $t = qq{$S identifies host};
 like ($result, qr{host:$host}, $t);
 
+## 8.1 starts a little over 1 billion
 $t = qq{$S accepts valid -w input};
-like ($cp->run(q{-w 1000000}), qr/$label OK/, $t);
+like ($cp->run(q{-w 1500000000}), qr{$label OK}, $t);
 
 $t = qq{$S flags invalid -w input};
-for (-1, 0, 'a') {
-    like ($cp->run(qq{-w $_}), qr/ERROR: Invalid argument.*must be a positive integer/, $t . " ($_)");
+for my $arg (-1, 0, 'a') {
+    like ($cp->run(qq{-w $arg}), qr{ERROR: Invalid argument.*must be a positive integer}, "$t ($arg)");
 }
 
+$t = qq{$S rejects warning values 2 billion or higher};
+like ($cp->run(qq{-w 2000000000}), qr{ERROR:.+less than 2 billion}, $t);
+
+$t = qq{$S rejects critical values 2 billion or higher};
+like ($cp->run(qq{-c 2200000000}), qr{ERROR:.+less than 2 billion}, $t);
+
 $t = qq{$S accepts valid -c input};
-like ($cp->run(q{-c 1000000}), qr/$label OK/, $t);
+like ($cp->run(q{-c 1400000000}), qr{$label OK}, $t);
 
 $t = qq{$S flags invalid -c input};
-for (-1, 0, 'a') {
-    like ($cp->run(qq{-c $_}), qr/ERROR: Invalid argument.*must be a positive integer/, $t . " ($_)");
+for my $arg (-1, 0, 'a') {
+    like ($cp->run(qq{-c $arg}), qr{ERROR: Invalid argument.*must be a positive integer}, "$t ($arg)");
 }
 
 $t = qq{$S sees impending wrap-around};
-like ($cp->run('-c ' . int ($txn_measure / 2)), qr/$label CRITICAL/, $t);
+like ($cp->run('-c ' . int ($txn_measure / 2)), qr{$label CRITICAL}, $t);
 
 $t = qq{$S sees no impending wrap-around};
-like ($cp->run('-v -c ' . ($txn_measure * 2)), qr/$label OK/, $t);
+like ($cp->run('-c 1999000000'), qr{$label OK}, $t);
 
 $t .= ' (mrtg)';
-like ($cp->run('-c 100000 --output=mrtg'), qr{\d+\n0\n\nDB: ardala}, $t);
+like ($cp->run('-c 1400000000 --output=mrtg'), qr{\d+\n0\n\nDB: \w+}, $t);
 
+exit;
-- 
1.6.0.5



More information about the Check_postgres mailing list