}
}
- local $SIG{ALRM} = sub { die 'Timed out' };
+ local $SIG{ALRM} = sub { die "Timed out\n" };
alarm 0;
push @args, '-c', $string;
alarm 0;
open STDERR, '>&', $oldstderr or ndie msg('runcommand-noerr');
close $oldstderr or ndie msg('file-noclose', 'STDERR copy', $!);
+ if ($err and $action eq 'connection') {
+ $info->{fatal} = $err;
+ return $info;
+ }
if ($err) {
if ($err =~ /Timed out/) {
ndie msg('runcommand-timeout', $timeout);
}
## If we are just trying to connect, failed attempts are critical
- if ($action eq 'connection' and $db->{error} =~ /FATAL|could not connect/) {
- $info->{fatal} = 1;
+ if ($action eq 'connection' and $db->{error}) {
+ $info->{fatal} = $db->{error};
return $info;
}
}
my $info = run_command('SELECT version() AS v');
+ if ($info->{fatal}) {
+ add_critical $info->{fatal};
+ return;
+ }
for $db (@{$info->{db}}) {
my $err = $db->{error} || '';
- if ($err =~ /FATAL|could not connect/) {
+ if ($err) {
$MRTG and do_mrtg({one => 0});
add_critical $db->{error};
return;
total_relation_size, using the respective pg_indexes_size() and
pg_total_relation_size() functions. All size checks will now also check
materialized views where applicable.
+
+ Connection errors are now always critical, not unknown.
(Christoph Berg)
New action replication_slots checking if logical or physical replication
use strict;
use warnings;
use Data::Dumper;
-use Test::More tests => 12;
+use Test::More tests => 14;
use lib 't','.';
use CP_Testing;
$cp->fake_version('ABC');
$t=qq{$S fails if there's a fake version function};
-like ($cp->run(), qr{^$label UNKNOWN:}, $t);
+like ($cp->run(), qr{^$label UNKNOWN:.*Invalid query}, $t);
+
+$cp->fake_version_timeout();
+$t=qq{$S fails on timeout};
+like ($cp->run('--timeout 1'), qr{^$label CRITICAL:.*Timed out}, $t);
$cp->reset_path();
+$t=qq{$S fails on nonexisting socket};
+like ($cp->run('--port=1023'), qr{^$label CRITICAL: could not connect to server}, $t);
+
exit;
} ## end of fake version
+sub fake_version_timeout {
+
+ my $self = shift;
+ my $dbh = $self->{dbh} || die;
+ my $dbuser = $self->{testuser} || die;
+
+ if (! $self->schema_exists($dbh, $fakeschema)) {
+ $dbh->do("CREATE SCHEMA $fakeschema");
+ }
+
+ $dbh->do(qq{
+CREATE OR REPLACE FUNCTION $fakeschema.version()
+RETURNS TEXT
+LANGUAGE SQL
+AS \$\$
+SELECT pg_sleep(10)::text;
+\$\$
+});
+ $dbh->do("ALTER USER $dbuser SET search_path = $fakeschema, public, pg_catalog");
+ $dbh->commit();
+ return;
+
+} ## end of fake version timeout
+
+
sub fake_self_version {
## Look out...