Per requests from many people.
t/02_version.t
t/02_wal_files.t
t/03_translations.t
+t/04_timeout.t
t/99_cleanup.t
t/99_perlcritic.t
t/99_pod.t
--- #YAML:1.0
name : check_postgres.pl
-version : 2.8.0
+version : 2.8.1
abstract : Postgres monitoring script
author:
- Greg Sabino Mullane <greg@endpoint.com>
provides:
check_postgres:
file : check_postgres.pl
- version : 2.8.0
+ version : 2.8.1
keywords:
- Postgres
use warnings;
use 5.006001;
-my $VERSION = '2.8.0';
+my $VERSION = '2.8.1';
if ($VERSION =~ /_/) {
print "WARNING! This is a test version ($VERSION) and should not be used in production!\n";
$Data::Dumper::Indent = 2;
$Data::Dumper::Useqq = 1;
-our $VERSION = '2.8.0';
+our $VERSION = '2.8.1';
use vars qw/ %opt $PSQL $res $COM $SQL $db /;
our $ERROR = '';
$opt{test} = 0;
-$opt{timeout} = 10;
+$opt{timeout} = 30;
die $USAGE unless
GetOptions(
--PSQL=FILE location of the psql executable; avoid using if possible
-v, --verbose verbosity level; can be used more than once to increase the level
-h, --help display this help information
- -t X, --timeout=X how long in seconds before we timeout. Defaults to 10 seconds.
+ -t X, --timeout=X how long in seconds before we timeout. Defaults to 30 seconds.
--symlinks create named symlinks to the main program for each action
Actions:
}
}
- push @args, '-c', $string;
-
- $VERBOSE >= 3 and warn Dumper \@args;
-
local $SIG{ALRM} = sub { die 'Timed out' };
my $timeout = $arg->{timeout} || $opt{timeout};
+ my $dbtimeout = $timeout * 1000;
alarm 0;
+ $string = "BEGIN;SET statement_timeout=$dbtimeout;COMMIT;$string";
+
+ push @args, '-c', $string;
+
+ $VERBOSE >= 3 and warn Dumper \@args;
+
my $start = $opt{showtime} ? [gettimeofday()] : 0;
open my $oldstderr, '>&', \*STDERR or ndie msg('runcommand-nodupe');
open STDERR, '>', $errorfile or ndie msg('runcommand-noerr');
if ($err =~ /Timed out/) {
ndie msg('runcommand-timeout', $timeout);
}
- else {
+ else {ndie $res;
ndie msg('runcommand-err');
}
}
ndie "$db->{error}";
}
+ elsif ($db->{error} =~ /statement timeout/) {
+ ndie msg('runcommand-timeout', $timeout);
+ }
+
if (!$db->{ok} and !$arg->{failok} and !$arg->{noverify}) {
## Check if problem is due to backend being too old for this check
B<check_postgres.pl> - a Postgres monitoring script for Nagios, MRTG, Cacti, and others
-This documents describes check_postgres.pl version 2.8.0
+This documents describes check_postgres.pl version 2.8.1
=head1 SYNOPSIS
=over 4
+=item B<Version 2.8.1> (May, 2009)
+
+ Added timeout via statement_timeout in addition to perl alarm (Greg)
+
=item B<Version 2.8.0> (May 4, 2009)
Added internationalization support (Greg)
<hr />
<h1><a name="name">NAME</a></h1>
<p><strong>check_postgres.pl</strong> - a Postgres monitoring script for Nagios, MRTG, Cacti, and others</p>
-<p>This documents describes check_postgres.pl version 2.8.0</p>
+<p>This documents describes check_postgres.pl version 2.8.1</p>
<p>
</p>
<hr />
<h1><a name="history">HISTORY</a></h1>
<p>Items not specifically attributed are by Greg Sabino Mullane.</p>
<dl>
-<dt><strong><a name="item_0"><strong>Version 2.8.0</strong> (May ??, 2009)</a></strong></dt>
+<dt><strong><a name="item_1"><strong>Version 2.8.1</strong> (May, 2009)</a></strong></dt>
+
+<dd>
+<pre>
+ Added timeout via statement_timeout in addition to perl alarm (Greg)</pre>
+</dd>
+<dt><strong><a name="item_0"><strong>Version 2.8.0</strong> (May 4, 2009)</a></strong></dt>
<dd>
<pre>
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,
Set stats to zero if we bail early due to USERWHERECLAUSE (Andras Fabian)
Add additional items to dbstats output (Andras Fabian)
Remove --schema option from the fsm_ checks. (Greg Mullane and Robert Treat)
- Various fixes. (Jeff Boes)
+ Handle case when ENV{PGUSER} is set. (Andy Lester)
+ Many various fixes. (Jeff Boes)
Fix --dbservice: check version and use ENV{PGSERVICE} for old versions (Cédric Villemain)</pre>
</dd>
<dt><strong><a name="item_3"><strong>Version 2.7.3</strong> (February 10, 2009)</a></strong></dt>
<pre>
Fix to prevent multiple groupings if db arguments given.</pre>
</dd>
-<dt><strong><a name="item_1"><strong>Version 2.7.1</strong> (February 6, 2009)</a></strong></dt>
+<dt><strong><strong>Version 2.7.1</strong> (February 6, 2009)</strong></dt>
<dd>
<pre>
--- /dev/null
+#!perl
+
+## Test the timeout functionality
+
+use 5.006;
+use strict;
+use warnings;
+use Data::Dumper;
+use Test::More tests => 2;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $SQL $t $res/;
+
+my $cp = CP_Testing->new( {default_action => 'custom_query'} );
+
+$dbh = $cp->test_database_handle();
+
+$t=q{Setting the --timeout flag works as expected};
+$res = $cp->run('--query="SELECT pg_sleep(2)" -w 7 --timeout=1');
+like ($res, qr{Command timed out}, $t);
+
+$t=q{Setting the --timeout flag works as expected};
+$res = $cp->run('--query="SELECT pg_sleep(1)" -w 7 --timeout=2');
+like ($res, qr{Invalid format}, $t);
+
+exit;