Do the right thing when 'sequence' called with multiple databases.
authorGreg Sabino Mullane <[email protected]>
Tue, 14 Oct 2008 19:38:47 +0000 (15:38 -0400)
committerGreg Sabino Mullane <[email protected]>
Tue, 14 Oct 2008 19:38:47 +0000 (15:38 -0400)
Handle 'target' argument to run_command cleaner.
Bump to version 2.3.7

check_postgres.pl
check_postgres.pl.asc
check_postgres.pl.html
index.html

index 11ff3b6eb93e633307629615f568655a6cea210e..4cc1cd1f69fdaf5b6ce2bd7b473835f4f6939430 100755 (executable)
@@ -28,7 +28,7 @@ $Data::Dumper::Varname = 'POSTGRES';
 $Data::Dumper::Indent = 2;
 $Data::Dumper::Useqq = 1;
 
-our $VERSION = '2.3.6';
+our $VERSION = '2.3.7';
 
 use vars qw/ %opt $PSQL $res $COM $SQL $db /;
 
@@ -824,7 +824,12 @@ sub run_command {
 
                ## If we were passed in a target, use that and move on
                if (exists $arg->{target}) {
-                       push @target, $arg->{target};
+                       ## Make a copy, in case we are passed in a ref
+                       my $newtarget;
+                       for my $key (keys %$conn) {
+                               $newtarget->{$key} = exists $arg->{target}{$key} ? $arg->{target}{$key} : $conn->{$key};
+                       }
+                       push @target, $newtarget;
                        last GROUP;
                }
 
@@ -3506,13 +3511,14 @@ sub check_sequence {
                my (@crit,@warn,@ok);
                my $maxp = 0;
                my %seqinfo;
+               my $multidb = @{$info->{db}} > 1 ? "$db->{dbname}." : '';
          SLURP: while ($db->{slurp} =~ /\s*(.+?)\s+\| (.+?)\s+\| (.+?)\s*$/gsm) {
                        my ($schema, $seq, $seqname) = ($1,$2,$3);
                        next if skip_item($seq);
                        $SQL = q{SELECT last_value, slots, used, ROUND(used/slots*100) AS percent, slots - used AS numleft FROM }.
                                q{ (SELECT last_value, CEIL((max_value-min_value+1)/increment_by::NUMERIC) AS slots,}.
                                qq{ CEIL((last_value-min_value+1)/increment_by::NUMERIC) AS used FROM $seqname) foo};
-                       my $seqinfo = run_command($SQL);
+                       my $seqinfo = run_command($SQL, { target => $db });
                        if (!defined $seqinfo->{db}[0] or $seqinfo->{db}[0]{slurp} !~ /(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)/) {
                                ndie "Could not determine information about sequence $seqname";
                        }
@@ -3524,7 +3530,7 @@ sub check_sequence {
                        }
                        next if $MRTG;
 
-                       $db->{perf} .= " $seqname=$percent|$slots|$used|$left";
+                       $db->{perf} .= " $multidb$seqname=$percent|$slots|$used|$left";
                        if (length $critical and $percent >= $c) {
                                push @crit => $msg;
                        }
@@ -3562,7 +3568,7 @@ sub check_sequence {
 =head1 NAME
 
 B<check_postgres.pl> - a Postgres monitoring script for Nagios, MRTG, and others
-This documents describes check_postgres.pl version 2.3.6
+This documents describes check_postgres.pl version 2.3.7
 
 =head1 SYNOPSIS
 
@@ -4703,6 +4709,10 @@ Items not specifically attributed are by Greg Sabino Mullane.
 
 =over 4
 
+=item B<Version 2.3.7>
+
+ Allow multiple databases in 'sequence' action. Reported by Christoph Zwerschke.
+
 =item B<Version 2.3.6>
 
  Add missing $schema to check_fsm_pages. (Robert Treat)
index 6bb816f30dbc57f988ce316dd67297842c52ff93..5fb50d9ebca96db1116e39c431b38d8fc0dfda41 100644 (file)
@@ -1,6 +1,6 @@
 -----BEGIN PGP SIGNATURE-----
 
-iEUEABEDAAYFAkjz8gUACgkQvJuQZxSWSsiVkQCYnZDHcq4IIrsgEx+pOPj7Vg96
-ugCbB61rFwYdg9At4cECcttnPHDA0R8=
-=VnYF
+iEYEABEDAAYFAkj09TsACgkQvJuQZxSWSsjFFACg+bqTQFUag8Xix5Fbrpw1Jq06
+DVEAoJ6GdP0VvIKKbOj5VeWZVMkmhoBn
+=B/UA
 -----END PGP SIGNATURE-----
index 3a818e913eebd4cf7f81f2ad19369afddd43c9d9..013c2533a2bc458e8a76351109c51453c95797f9 100644 (file)
@@ -90,7 +90,7 @@
 <hr />
 <h1><a name="name">NAME</a></h1>
 <p><strong>check_postgres.pl</strong> - a Postgres monitoring script for Nagios, MRTG, and others
-This documents describes check_postgres.pl version 2.3.6</p>
+This documents describes check_postgres.pl version 2.3.7</p>
 <p>
 </p>
 <hr />
@@ -1119,6 +1119,12 @@ feature requests, and commit notices, send email to <a href="mailto:check_postgr
 <h1><a name="history">HISTORY</a></h1>
 <p>Items not specifically attributed are by Greg Sabino Mullane.</p>
 <dl>
+<dt><strong><a name="item_version_2_2e3_2e7"><strong>Version 2.3.7</strong></a></strong></dt>
+
+<dd>
+<pre>
+ Allow multiple databases in 'sequence' action. Reported by Christoph Zwerschke.</pre>
+</dd>
 <dt><strong><a name="item_version_2_2e3_2e6"><strong>Version 2.3.6</strong></a></strong></dt>
 
 <dd>
index a5e6fa99df3895aeec3725de958c0081b4ecba3a..376ead040941d710377932ec1f9ffd53603b7efc 100644 (file)
@@ -21,14 +21,14 @@ h1 {
 
 <h1>check_postgres.pl</h1>
 
-<p><b>check_postgres.pl</b> is a script for checking the state of one or more Postgres databases and reporting back in a Nagios-friendly manner. It was developed by Greg Sabino Mullane of <a href="http://www.endpoint.com/">End Point Corporation</a> and is BSD-licensed. The latest version is <b>2.3.6</b>, and was released on October 13, 2008.</p>
+<p><b>check_postgres.pl</b> is a script for checking the state of one or more Postgres databases and reporting back in a Nagios-friendly manner. It was developed by Greg Sabino Mullane of <a href="http://www.endpoint.com/">End Point Corporation</a> and is BSD-licensed. The latest version is <b>2.3.7</b>, and was released on October 14, 2008.</p>
 
 <ul>
- <li><a href="/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.3.6</a></li>
+ <li><a href="/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.3.7</a></li>
 </ul>
 <ul>
- <li><a href="/check_postgres/check_postgres.pl">Download check_postgres.pl 2.3.6</a></li>
- <li><a href="/check_postgres/check_postgres.pl.asc">PGP signature for check_postgres.pl 2.3.6</a></li>
+ <li><a href="/check_postgres/check_postgres.pl">Download check_postgres.pl 2.3.7</a></li>
+ <li><a href="/check_postgres/check_postgres.pl.asc">PGP signature for check_postgres.pl 2.3.7</a></li>
 </ul>
 
 <p>The latest development version can be downloaded via git:</p>