[check_postgres] [commit] Allow transform of simple output numbers.

check_postgres at bucardo.org check_postgres at bucardo.org
Wed Oct 22 02:47:13 UTC 2008


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

Allow transform of simple output numbers.

---
 check_postgres.pl |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index ab554b0..992f9a8 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -156,6 +156,15 @@ if (!$OUTPUT) {
 	}
 }
 
+
+## Extract transforms from the output
+$opt{transform} = '';
+if ($OUTPUT =~ /\b(kb|mb|gb|tb|eb)\b/) {
+	$opt{transform} = uc $1;
+}
+if ($OUTPUT =~ /(nagios|mrtg|simple)/io) {
+	$OUTPUT = lc $1;
+}
 ## Check for a valid output setting
 if ($OUTPUT ne 'nagios' and $OUTPUT ne 'mrtg' and $OUTPUT ne 'simple') {
 	die qq{Invalid output: must be 'nagios' or 'mrtg' or 'simple'\n};
@@ -376,6 +385,21 @@ sub do_mrtg {
 	my $two = $arg->{two} || 0;
 	if ($SIMPLE) {
 		$one = $two if (length $two and $two > $one);
+		if ($opt{transform} eq 'KB' and $one =~ /^\d+$/) {
+			$one = int $one/(1024);
+		}
+		if ($opt{transform} eq 'MB' and $one =~ /^\d+$/) {
+			$one = int $one/(1024*1024);
+		}
+		elsif ($opt{transform} eq 'GB' and $one =~ /^\d+$/) {
+			$one = int $one/(1024*1024*1024);
+		}
+		elsif ($opt{transform} eq 'TB' and $one =~ /^\d+$/) {
+			$one = int $one/(1024*1024*1024*1024);
+		}
+		elsif ($opt{transform} eq 'EB' and $one =~ /^\d+$/) {
+			$one = int $one/(1024*1024*1024*1024*1024);
+		}
 		print "$one\n";
 	}
 	else {
@@ -3657,7 +3681,10 @@ See the documentation on each action for details on the exact MRTG output for ea
 
 The simple output is simply a truncated version of the MRTG one, and simply returns the first number 
 and nothing else. This is very useful when you just want to check the state of something, regardless 
-of any threshold.
+of any threshold. You can transform the numeric output by appending KB, MB, GB, TB, or EB to the output 
+argument, for example:
+
+  --output=simple,MB
 
 =head1 DATABASE CONNECTION OPTIONS
 
@@ -4711,6 +4738,11 @@ Items not specifically attributed are by Greg Sabino Mullane.
 
 =over 4
 
+=item B<Version 2.3.8>
+
+ Allow the default port to be changed easily.
+ Allow transform of simple output by MB, GB, etc.
+
 =item B<Version 2.3.7>
 
  Allow multiple databases in 'sequence' action. Reported by Christoph Zwerschke.
-- 
1.5.5.4



More information about the Check_postgres mailing list