If a command fails it's regex check, call new function version_verify to see if this
authorGreg Sabino Mullane <[email protected]>
Mon, 29 Sep 2008 00:18:57 +0000 (20:18 -0400)
committerGreg Sabino Mullane <[email protected]>
Mon, 29 Sep 2008 00:18:57 +0000 (20:18 -0400)
is ue to failing pre-reqs, and die with an appropriate message if so. From conversations
about bad error messages with Euler Taveira de Oliveira.

check_postgres.pl

index 587dd0e65e21c80212dfad074b46d25f5e6a9abf..8c0531ff70dd97f818bc2d093c7aaf2338c96000 100755 (executable)
@@ -981,6 +981,9 @@ sub run_command {
                        ## If we were provided with a regex, check and bail if it fails
                        elsif ($arg->{regex}) {
                                if ($db->{slurp} !~ $arg->{regex}) {
+                                       ## Check if problem is due to backend being to old for this check
+                                       verify_version($db->{slurp});
+
                                        add_unknown qq{T-BAD-QUERY $db->{slurp}};
                                        ## Remove it from the returned hash
                                        pop @{$info->{db}};
@@ -1029,6 +1032,52 @@ sub run_command {
 } ## end of run_command
 
 
+sub verify_version {
+
+       ## Check if the backend can handle the current action
+       my $limit = $testaction{lc $action} || '';
+
+       return if ! $limit;
+
+       ## We almost always need the version, so just grab it for any limitation
+       $SQL = q{SELECT setting FROM pg_settings WHERE name = 'server_version'};
+       my $info = run_command($SQL);
+       if (!defined $info->{db}[0] or $info->{db}[0]{slurp} !~ /((\d+)\.(\d+))/) {
+               die "Could not determine version while running $SQL\n";
+       }
+       my ($sver,$smaj,$smin) = ($1,$2,$3);
+
+       if ($limit =~ /VERSION: ((\d+)\.(\d+))/) {
+               my ($rver,$rmaj,$rmin) = ($1,$2,$3);
+               if ($smaj < $rmaj or ($smaj==$rmaj and $smin < $rmin)) {
+                       die qq{Cannot run "$action": server version must be >= $rver, but is $sver\n};
+               }
+       }
+
+       while ($limit =~ /\bON: (\w+)(?:\(([<>=])(\d+\.\d+)\))?/g) {
+               my ($setting,$op,$ver) = ($1,$2||'',$3||0);
+               if ($ver) {
+                       next if $op eq '<' and $sver >= $ver;
+                       next if $op eq '>' and $sver <= $ver;
+                       next if $op eq '=' and $sver != $ver;
+               }
+
+               $SQL = qq{SELECT setting FROM pg_settings WHERE name = '$setting'};
+               my $info = run_command($SQL);
+               if (!defined $info->{db}[0]) {
+                       die "Could not fetch setting '$setting'\n";
+               }
+               my $val = $info->{db}[0]{slurp};
+               if ($val ne 'on') {
+                       die qq{Cannot run "$action": $setting is not set to on\n};
+               }
+       }
+
+       return;
+
+} ## end of verify_version
+
+
 sub size_in_bytes { ## no critic (RequireArgUnpacking)
 
        ## Given a number and a unit, return the number of bytes.
@@ -4542,6 +4591,7 @@ Items not specifically attributed are by Greg Sabino Mullane.
 
  Add MRTG output to fsm_pages and fsm_relations.
  Force error messages to one-line for proper Nagios output.
+ Check for invalid prereqs on failed command. From conversations with Euler Taveira de Oliveira.
 
 =item B<Version 2.2.0> (September 25, 2008)