Permalink
Browse files

Merge commit 'petdance/master'

Conflicts:
	TODO
	check_postgres.pl
  • Loading branch information...
2 parents 0d0b329 + f427b70 commit 79c0d646ccc5da3335cee8f809d521f82673e1b0 @turnstep turnstep committed Apr 7, 2010
Showing with 183 additions and 12 deletions.
  1. +11 −2 TODO
  2. +172 −10 check_postgres.pl
View
13 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
+
View
@@ -286,7 +286,7 @@ package check_postgres;
'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 @@ package check_postgres;
'version|V',
'verbose|v+',
'help|h',
+ 'man',
'output=s',
'simple',
'showperf=i',
@@ -735,6 +736,12 @@ package check_postgres;
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,18 +913,19 @@ package check_postgres;
--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
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 @@ sub check_backends {
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 @@ sub check_backends {
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 @@ sub check_database_size {
}
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 @@ sub check_prepared_txns {
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,13 +6753,24 @@ sub check_txn_idle {
}
else {
add_ok $msg;
+<<<<<<< HEAD:check_postgres.pl
}
}
## If no results, let's be paranoid and check their settings
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 @@ sub check_txn_time {
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 @@ sub check_txn_time {
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 @@ =head1 OTHER OPTIONS
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 @@ =head1 OTHER OPTIONS
=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 @@ =head1 HISTORY
=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 @@ =head1 LICENSE AND COPYRIGHT
OF SUCH DAMAGE.
=cut
+
+# vi: hardtabs=8 shiftwidth=8 noexpandtab nosmarttab

0 comments on commit 79c0d64

Please sign in to comment.