Don't allow values over 2 billion for wraparound check.
authorGreg Sabino Mullane <[email protected]>
Thu, 30 Apr 2009 12:35:13 +0000 (08:35 -0400)
committerGreg Sabino Mullane <[email protected]>
Thu, 30 Apr 2009 12:35:13 +0000 (08:35 -0400)
Older version compatibility.

check_postgres.pl
t/02_txn_wraparound.t

index b778462d8b982378ccb17fc53fa049fd482a66d9..8bd874cb37d84a6f4a682e45a194bc439a95973c 100755 (executable)
@@ -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+] } );
 
index 8e0610088f3e910f2fe7bbf71c61a97917cb47cc..c44af2a123a3b6dc8f025bc42a51c3257fc6b1d7 100644 (file)
@@ -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;