summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Sabino Mullane2010-04-07 17:22:09 +0000
committerGreg Sabino Mullane2010-04-07 17:22:09 +0000
commit79c0d646ccc5da3335cee8f809d521f82673e1b0 (patch)
tree8a0a597c3d2d4881c769dac88253a05c184a2402
parent0d0b3294ba8987bf1dadb75a263fb089ddb5973f (diff)
parentf427b70ff460951efa359831f3dcd5810ef9170e (diff)
Merge commit 'petdance/master'
Conflicts: TODO check_postgres.pl
-rw-r--r--TODO13
-rwxr-xr-xcheck_postgres.pl182
2 files changed, 183 insertions, 12 deletions
diff --git a/TODO b/TODO
index 27dafa7e3..3ee21a73d 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,9 @@
Quick list of outstanding items / bugs / feature requests for CP:
+* Add a --output=plain, for simple human-readable output.
+
+* Add a --output=csv, for importing into various targets.
+
* Language testing: force to EN?
* Allow a flag to determine if skipped into goes into perf or not
@@ -29,8 +33,6 @@ Quick list of outstanding items / bugs / feature requests for CP:
* Check at least one table has been vacuumed/analyzed since X time
-* Put on CPAN
-
* Check every table has been vacuum|analyze at least once. (no NULL)
* Check at least one table has been vacuumed|analyzed since X hours/days/...
@@ -43,3 +45,10 @@ Quick list of outstanding items / bugs / feature requests for CP:
* For the Nagios 'perf' output on last_analyze and last_vacuum (and other things with a time),
consider making a single global timing call.
+
+# Perl-specific
+
+* Put on CPAN
+
+* Create a Perl::Critic test suite
+
diff --git a/check_postgres.pl b/check_postgres.pl
index db8abcb80..ecf2c56be 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -286,7 +286,7 @@ our %msg = (
'txnwrap-cbig' => q{The 'critical' value must be less than 2 billion},
'txnwrap-wbig' => q{The 'warning' value must be less than 2 billion},
'unknown-error' => q{Unknown error},
- 'usage' => qq{\nUsage: \$1 <options>\n Try "\$1 --help" for a complete list of options\n\n},
+ 'usage' => qq{\nUsage: \$1 <options>\n Try "\$1 --help" for a complete list of options\n Try "\$1 --man" for the full manual\n},
'username' => q{username},
'vac-msg' => q{DB: $1 TABLE: $2},
'vac-nomatch-a' => q{No matching tables have ever been analyzed},
@@ -683,6 +683,7 @@ die $USAGE unless
'version|V',
'verbose|v+',
'help|h',
+ 'man',
'output=s',
'simple',
'showperf=i',
@@ -735,6 +736,12 @@ die $USAGE unless
and keys %opt
and ! @ARGV;
+if ( $opt{man} ) {
+ require Pod::Usage;
+ Pod::Usage::pod2usage({-verbose => 2});
+ exit;
+}
+
## Put multi-val options from check_postgresrc in place, only if no command-line args!
for my $mv (keys %tempopt) {
$opt{$mv} ||= delete $tempopt{$mv};
@@ -906,6 +913,7 @@ Other options:
--PSQL=FILE location of the psql executable; avoid using if possible
-v, --verbose verbosity level; can be used more than once to increase the level
-h, --help display this help information
+ --man display the full manual
-t X, --timeout=X how long in seconds before we timeout. Defaults to 30 seconds.
--symlinks create named symlinks to the main program for each action
@@ -913,11 +921,11 @@ Actions:
Which test is determined by the --action option, or by the name of the program
$action_usage
-For a complete list of options and full documentation, please view the POD for this file.
-Two ways to do this is to run:
-pod2text $ME | less
-pod2man $ME | man -l -
-Or simply visit: http://bucardo.org/check_postgres/
+For a complete list of options and full documentation, view the manual.
+
+ $ME --man
+
+Or visit: http://bucardo.org/check_postgres/
};
@@ -1047,10 +1055,15 @@ sub add_response {
push @{$type->{''}} => [$msg, length $nohost > 1 ? $nohost : ''];
return;
}
+<<<<<<< HEAD:check_postgres.pl
+=======
+ my $dbservice = $db->{dbservice};
+ my $dbname = $db->{dbname};
+>>>>>>> petdance/master:check_postgres.pl
my $header = sprintf q{%s%s%s},
- $action_info->{$action}[0] ? '' : (defined $db->{dbservice} and length $db->{dbservice}) ?
- qq{service=$db->{dbservice} } : qq{DB "$db->{dbname}" },
+ $action_info->{$action}[0] ? '' : (defined $dbservice and length $dbservice) ?
+ qq{service=$dbservice } : qq{DB "$dbname" },
$db->{host} eq '<none>' ? '' : qq{(host:$db->{host}) },
defined $db->{port} ? ($db->{port} eq $opt{defaultport} ? '' : qq{(port=$db->{port}) }) : '';
$header =~ s/\s+$//;
@@ -2635,6 +2648,8 @@ ORDER BY datname
my $ok = 1;
if ($e1) { ## minus
$ok = 0 if $limit-$total >= $e2;
+<<<<<<< HEAD:check_postgres.pl
+=======
}
elsif ($e3) { ## percent
my $nowpercent = $total/$limit*100;
@@ -2661,8 +2676,37 @@ ORDER BY datname
if (!$ok) {
add_warning $msg;
return;
+>>>>>>> petdance/master:check_postgres.pl
+ }
+ elsif ($e3) { ## percent
+ my $nowpercent = $total/$limit*100;
+ $ok = 0 if $nowpercent >= $e2;
+ }
+ else { ## raw number
+ $ok = 0 if $total >= $e2;
+ }
+ if (!$ok) {
+ add_critical $msg;
+ return;
}
+ if ($w1) {
+ $ok = 0 if $limit-$total >= $w2;
+ }
+ elsif ($w3) {
+ my $nowpercent = $total/$limit*100;
+ $ok = 0 if $nowpercent >= $w2;
+ }
+ else {
+ $ok = 0 if $total >= $w2;
+ }
+ if (!$ok) {
+ add_warning $msg;
+ return;
+ }
+
+ add_ok $msg;
+
add_ok $msg;
return;
@@ -3061,6 +3105,7 @@ sub check_custom_query {
my ($warning, $critical) = validate_range({type => $valtype, leastone => 1});
my $query = $opt{query} or ndie msg('custom-nostring');
+<<<<<<< HEAD:check_postgres.pl
my $reverse = $opt{reverse} || 0;
@@ -3128,6 +3173,75 @@ sub check_database_size {
## Limit to a specific user (db owner) with the includeuser option
## Exclude users with the excludeuser option
+=======
+
+ my $reverse = $opt{reverse} || 0;
+
+ my $info = run_command($query);
+
+ for $db (@{$info->{db}}) {
+
+ if (! @{$db->{slurp}}) {
+ add_unknown msg('custom-norows');
+ next;
+ }
+
+ my $goodrow = 0;
+
+ for my $r (@{$db->{slurp}}) {
+ my ($data,$msg) = ($r->{result}, $r->{data}||'');
+ $goodrow++;
+ $db->{perf} .= " $msg";
+ my $gotmatch = 0;
+ if (length $critical) {
+ if (($valtype eq 'string' and $data eq $critical)
+ or
+ ($reverse ? $data <= $critical : $data >= $critical)) { ## covers integer, time, size
+ add_critical "$data";
+ $gotmatch = 1;
+ }
+ }
+
+ if (length $warning and ! $gotmatch) {
+ if (($valtype eq 'string' and $data eq $warning)
+ or
+ ($reverse ? $data <= $warning : $data >= $warning)) {
+ add_warning "$data";
+ $gotmatch = 1;
+ }
+ }
+
+ if (! $gotmatch) {
+ add_ok "$data";
+ }
+
+ } ## end each row returned
+
+ if (!$goodrow) {
+ add_unknown msg('custom-invalid');
+ }
+ }
+
+ return;
+
+} ## end of check_custom_query
+
+
+sub check_database_size {
+
+ ## Check the size of one or more databases
+ ## Supports: Nagios, MRTG
+ ## mrtg reports the largest two databases
+ ## By default, checks all databases
+ ## Can check specific one(s) with include
+ ## Can ignore some with exclude
+ ## Warning and critical are bytes
+ ## Valid units: b, k, m, g, t, e
+ ## All above may be written as plural or with a trailing 'b'
+ ## Limit to a specific user (db owner) with the includeuser option
+ ## Exclude users with the excludeuser option
+
+>>>>>>> petdance/master:check_postgres.pl
my ($warning, $critical) = validate_range({type => 'size'});
$USERWHERECLAUSE =~ s/AND/WHERE/;
@@ -3145,9 +3259,15 @@ JOIN pg_user u ON (u.usesysid=d.datdba)$USERWHERECLAUSE
}
my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1, } );
+<<<<<<< HEAD:check_postgres.pl
+
+ my $found = 0;
+
+=======
my $found = 0;
+>>>>>>> petdance/master:check_postgres.pl
for $db (@{$info->{db}}) {
my $max = -1;
$found = 1;
@@ -4486,9 +4606,15 @@ SELECT database, ROUND(EXTRACT(epoch FROM now()-prepared)) AS age, prepared
FROM pg_prepared_xacts
ORDER BY prepared ASC
};
+<<<<<<< HEAD:check_postgres.pl
+
+ my $info = run_command($SQL, {regex => qr[\w+], emptyok => 1 } );
+
+=======
my $info = run_command($SQL, {regex => qr[\w+], emptyok => 1 } );
+>>>>>>> petdance/master:check_postgres.pl
my $msg = msg('preptxn-none');
my $found = 0;
for $db (@{$info->{db}}) {
@@ -6627,6 +6753,7 @@ sub check_txn_idle {
}
else {
add_ok $msg;
+<<<<<<< HEAD:check_postgres.pl
}
}
@@ -6634,6 +6761,16 @@ sub check_txn_idle {
if (!$found) {
if ($USERWHERECLAUSE) {
add_ok msg('no-match-user');
+=======
+>>>>>>> petdance/master:check_postgres.pl
+ }
+ verify_version();
+ }
+
+ ## If no results, let's be paranoid and check their settings
+ if (!$found) {
+ if ($USERWHERECLAUSE) {
+ add_ok msg('no-match-user');
}
verify_version();
}
@@ -6671,6 +6808,7 @@ SELECT
FROM pg_stat_activity
WHERE xact_start IS NOT NULL $USERWHERECLAUSE
};
+<<<<<<< HEAD:check_postgres.pl
my $info = run_command($SQL, { regex => qr{\d+ \|\s+\s+}, emptyok => 1 } );
@@ -6681,6 +6819,18 @@ WHERE xact_start IS NOT NULL $USERWHERECLAUSE
ndie msg('txntime-fail');
}
+=======
+
+ my $info = run_command($SQL, { regex => qr{\d+ \|\s+\s+}, emptyok => 1 } );
+
+ $db = $info->{db}[0];
+ my $slurp = $db->{slurp};
+
+ if (! exists $db->{ok}) {
+ ndie msg('txntime-fail');
+ }
+
+>>>>>>> petdance/master:check_postgres.pl
if ($slurp !~ /\w/ and $USERWHERECLAUSE) {
$stats{$db->{dbname}} = 0;
add_ok msg('no-match-user');
@@ -7121,6 +7271,10 @@ script. The default value is 10; the units are always in seconds.
Displays a help screen with a summary of all actions and options.
+=item B<--man>
+
+Displays the entire manual.
+
=item B<-V> or B<--version>
Shows the current version.
@@ -7171,8 +7325,9 @@ Creates symlinks to the main program for each action.
=item B<--output=VAL>
-Determines the format of the output, for use in various programs. The default is 'nagios'. No
-other systems are supported yet.
+Determines the format of the output, for use in various programs. The
+default is 'nagios'. Available options are 'nagios', 'mrtg', 'simple'
+and 'cacti'.
=item B<--mrtg=VAL>
@@ -8440,6 +8595,11 @@ Items not specifically attributed are by Greg Sabino Mullane.
=over 4
+
+=item B<?>
+
+ Add --man option to show the entire manual. (Andy Lester)
+
=item B<Version 2.15.0>
Redo the internal run_command() sub to use -x and hashes instead of regexes.
@@ -8973,3 +9133,5 @@ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
=cut
+
+# vi: hardtabs=8 shiftwidth=8 noexpandtab nosmarttab