Allow transform of simple output numbers.
authorGreg Sabino Mullane <[email protected]>
Wed, 22 Oct 2008 02:47:01 +0000 (22:47 -0400)
committerGreg Sabino Mullane <[email protected]>
Wed, 22 Oct 2008 02:47:01 +0000 (22:47 -0400)
check_postgres.pl

index ab554b07d6d9c1e23932af144d77f3442ab62c4c..992f9a8d1528d205b6afdc650b795fb97c646a88 100755 (executable)
@@ -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.