[check_postgres] [commit] If a command fails it's regex check, call new function version_verify to see if this

check_postgres at bucardo.org check_postgres at bucardo.org
Mon Sep 29 01:29:12 UTC 2008


Committed by Greg Sabino Mullane <greg at endpoint.com>

If a command fails it's regex check, call new function version_verify to see if this
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 |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index 587dd0e..8c0531f 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -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)
 
-- 
1.5.5.4



More information about the Check_postgres mailing list