Fix query_time action when using --dbservice option
authorGuillaume Lelarge <[email protected]>
Wed, 5 Oct 2011 10:09:12 +0000 (12:09 +0200)
committerGuillaume Lelarge <[email protected]>
Wed, 5 Oct 2011 10:09:12 +0000 (12:09 +0200)
When using --dbservice option, $db->{dbname} is not set. So the $whodunit
variable initialization should first check if the $db->{dbname} is set.

Actually, we only initialize it for the MRTG output as it is not important in
the Nagios output.

check_postgres.pl

index b741583ffd05a08872b2e4288844a69da5878a95..a68f2603370ac00b0f8afe24c3624393af561668 100755 (executable)
@@ -168,6 +168,7 @@ our %msg = (
     'new-ver-ok'         => q{Version $1 is the latest for $2},
     'new-ver-warn'       => q{Please upgrade to version $1 of $2. You are running $3},
     'new-ver-tt'         => q{Your version of $1 ($2) appears to be ahead of the current release! ($3)},
+    'no-db'              => q{No databases},
     'no-match-db'        => q{No matching databases found due to exclusion/inclusion options},
     'no-match-fs'        => q{No matching file systems found due to exclusion/inclusion options},
     'no-match-rel'       => q{No matching relations found due to exclusion/inclusion options},
@@ -412,6 +413,7 @@ our %msg = (
     'new-ver-ok'          => q{La version $1 est la dernière pour $2},
     'new-ver-warn'        => q{Merci de mettre à jour vers la version $1 de $2. Vous utilisez actuellement la $3},
     'new-ver-tt'         => q{Votre version de $1 ($2) semble ult??rieure ?? la version courante ! ($3)},
+'no-db'              => q{No databases},
     'no-match-db'        => q{Aucune base de données trouvée à cause des options d'exclusion/inclusion},
     'no-match-fs'        => q{Aucun système de fichier trouvé à cause des options d'exclusion/inclusion},
     'no-match-rel'       => q{Aucune relation trouvée à cause des options d'exclusion/inclusion},
@@ -7264,7 +7266,14 @@ sub check_txn_idle {
     my $count = 0;
 
     ## Info about the top offender
-    my $whodunit = "DB: $db->{dbname}";
+    my $whodunit = "";
+    if ($MRTG) {
+        if (defined $db->{dbname}) {
+            $whodunit = "DB: $db->{dbname}";
+        } else {
+            $whodunit = sprintf q{DB: %s}, msg('no-db');
+        }
+    }
 
     ## Process each returned row
     for my $r (@{ $db->{slurp} }) {