Make sure connection checks return CRITICAL rather than UNKNOWN.
authorDominic Hargreaves <[email protected]>
Sat, 23 Mar 2013 16:09:34 +0000 (12:09 -0400)
committerGreg Sabino Mullane <[email protected]>
Sat, 23 Mar 2013 16:09:34 +0000 (12:09 -0400)
Patch by Dominic Hargreaves with minor tweaks by Greg Sabino Mullane.
Thanks to Christoph Berg for the forward (this came in via the Debian bugs system)

check_postgres.pl

index a3078f40df7cb2fa9a19f6d50ee0fcd9f217dac7..152b7e831858fdf4a89720d2ab92f00fac86a478 100755 (executable)
@@ -2353,13 +2353,13 @@ sub run_command {
                 $ERROR = $db->{error};
             }
 
-            if ($db->{error} =~ /FATAL/) {
-                ## If we are just trying to connect, this should be a normal error
-                if ($action eq 'connection') {
-                    $info->{fatal} = 1;
-                    return $info;
-                }
+            ## 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;
+                return $info;
+            }
 
+            if ($db->{error} =~ /FATAL/) {
                 if (exists $arg->{fatalregex} and $db->{error} =~ /$arg->{fatalregex}/) {
                     $info->{fatalregex} = $db->{error};
                     next;
@@ -2369,7 +2369,7 @@ sub run_command {
                 }
             }
 
-            elsif ($db->{error} =~ /statement timeout/) {
+            if ($db->{error} =~ /statement timeout/) {
                 ndie msg('runcommand-timeout', $timeout);
             }
 
@@ -4011,7 +4011,7 @@ sub check_connection {
     for $db (@{$info->{db}}) {
 
         my $err = $db->{error} || '';
-        if ($err =~ /FATAL/) {
+        if ($err =~ /FATAL|could not connect/) {
             $MRTG and do_mrtg({one => 0});
             add_critical $db->{error};
             return;