my $arg = shift;
defined $arg and ref $arg eq 'HASH' or ndie qq{validate_range must be called with a hashref\n};
- return ('','','','') if $MRTG and !$arg->{forcemrtg};
+ return ('','') if $MRTG and !$arg->{forcemrtg};
my $type = $arg->{type} or ndie qq{validate_range must be provided a 'type'\n};
my $critical = exists $opt{critical} ? $opt{critical} :
exists $opt{warning} ? '' : $arg->{default_critical} || '';
- # We need the extension : KB,GB, etc... or % for cleaner nagios output
- my $wuom;
- my $cuom;
-
if ('string' eq $type) {
## Don't use this unless you have to
}
ndie msg('range-seconds', 'warning');
}
$warning = $1;
- $wuom = 's';
}
if (length $critical) {
if ($critical !~ $timesecre) {
ndie msg('range-seconds', 'critical')
}
$critical = $1;
- $cuom = 's';
if (length $warning and $warning > $critical) {
ndie msg('range-warnbigtime', $warning, $critical);
}
if (length $warning and length $critical and $warning > $critical) {
ndie msg('range-warnbigtime', $warning, $critical);
}
- $wuom = 's';
- $cuom = 's';
}
elsif ('version' eq $type) {
my $msg = msg('range-version');
ndie msg('range-badsize', 'critical');
}
$critical = size_in_bytes($1,$2);
- $cuom=uc "$2b";
}
if (length $warning) {
if ($warning !~ $sizere) {
ndie msg('range-badsize', 'warning');
}
-die "Got $1 and $2\n";
-
-$wuom = "$1";
$warning = size_in_bytes($1,$2);
- $wuom=uc "$2b";
if (length $critical and $warning > $critical) {
ndie msg('range-warnbigsize', $warning, $critical);
}
if ($critical !~ /^\d+\%$/) {
ndie msg('range-badpercent', 'critical');
}
- $cuom = '%';
}
if (length $warning) {
if ($warning !~ /^\d+\%$/) {
ndie msg('range-badpercent', 'warning');
}
- $wuom = '%';
}
}
elsif ('size or percent' eq $type) {
if (length $critical) {
if ($critical =~ $sizere) {
$critical = size_in_bytes($1,$2);
- $cuom=uc "$2b";
}
elsif ($critical !~ /^\d+\%$/) {
ndie msg('range-badpercsize', 'critical');
}
- else {
- $cuom = '%';
- }
}
if (length $warning) {
if ($warning =~ $sizere) {
$warning = size_in_bytes($1,$2);
- $wuom=uc "$2b";
}
elsif ($warning !~ /^\d+\%$/) {
ndie msg('range-badpercsize', 'warning');
}
- else {
- $wuom = '%';
- }
}
elsif (! length $critical) {
ndie msg('range-noopt-size');
}
}
- return ($warning,$critical, $wuom, $cuom);
+ return ($warning,$critical);
} ## end of validate_range
## Warning and criticals are percentages
## Can also ignore databases with exclude, and limit with include
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'percent',
default_warning => '90%',
$LIMIT = $opt{perflimit};
}
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'size or percent',
default_warning => '1 GB',
## Limit to a specific user (db owner) with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'size'});
+ my ($warning, $critical) = validate_range({type => 'size'});
$USERWHERECLAUSE =~ s/AND/WHERE/;
}
my $msg = '';
- my ($nwarn, $ncrit)= ('', '');
- $nwarn = bytes_in_size($warning,$wuom) if ($warning);
- $ncrit = bytes_in_size($critical,$wuom) if ($critical);
-
for (sort {$s{$b}[0] <=> $s{$a}[0] or $a cmp $b } keys %s) {
$msg .= "$_: $s{$_}[0] ($s{$_}[1]) ";
- $wuom=$cuom if (!$wuom);
- $db->{perf} .= " '$_'="
- .bytes_in_size($s{$_}[0],$wuom)."$wuom"
- .";$nwarn".";$ncrit";
+ $db->{perf} .= " $_=$s{$_}[0]";
}
if (length $critical and $max >= $critical) {
add_critical $msg;
## NOTE: Needs to run on the same system (for now)
## XXX Allow custom ssh commands for remote df and the like
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'size or percent',
default_warning => '90%',
## Critical and warning are a percentage of max_fsm_pages
## Example: --critical=95
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'percent',
default_warning => '85%',
## Critical and warning are a percentage of max_fsm_relations
## Example: --critical=95
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'percent',
default_warning => '85%',
## Critical and warning are the number of files
## Example: --critical=40
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'integer', leastone => 1});
+ my ($warning, $critical) = validate_range({type => 'integer', leastone => 1});
## Figure out where the pg_xlog directory is
$SQL = q{SELECT count(*) FROM pg_ls_dir('pg_xlog') WHERE pg_ls_dir ~ E'^[0-9A-F]{24}$'}; ## no critic (RequireInterpolationOfMetachars)
## Limit to a specific user (relation owner) with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'size'});
+ my ($warning, $critical) = validate_range({type => 'size'});
$SQL = q{SELECT pg_relation_size(c.oid), pg_size_pretty(pg_relation_size(c.oid)), relkind, relname, nspname };
$SQL .= sprintf 'FROM pg_class c, pg_namespace n WHERE (relkind = %s) AND n.oid = c.relnamespace',
## Example:
## --exclude=~pg_ --include=pg_class,pg_attribute
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'time',
default_warning => '1 day',
$opt{critical} = $opt{mrtg};
}
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'restringex', forcemrtg => 1});
+ my ($warning, $critical) = validate_range({type => 'restringex', forcemrtg => 1});
my $string = length $critical ? $critical : $warning;
my $regex = ($string =~ s/^~//) ? '~' : '=';
## Lock names are case-insensitive, and do not need the "lock" at the end.
## Example: --warning=100 --critical="total=200;exclusive=20;waiting=5"
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'multival',
default_warning => 100,
## --warning="100s" --critical="120s" --queryname="speedtest1"
## --warning="5min" --critical="15min" --queryname="speedtest()"
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'time'});
+ my ($warning, $critical) = validate_range({type => 'time'});
my $queryname = $opt{queryname} || '';
## Limit to a specific user with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'time',
default_warning => '2 minutes',
$stats{$db->{dbname}} = $max;
next;
}
- $db->{perf} .= msg('maxtime', $max);
+ $db->{perf} .= "maxtime=$max;";
+ $db->{perf} .= "$warning" if length $warning;
+ $db->{perf} .= ";";
+ $db->{perf} .= "$critical" if length $critical;
my $msg = msg('qtime-msg', $max);
if (length $critical and $max >= $critical) {
## Limit to a specific user with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
- type => 'time',
+ type => 'time',
});
$SQL = q{SELECT datname, max(COALESCE(ROUND(EXTRACT(epoch FROM now()-xact_start)),0)) }.
## Limit to a specific user with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
- type => 'time',
+ type => 'time',
});
## Example:
## check_postgres_settings_checksum --critical="4e7ba68eb88915d3d1a36b2009da4acd"
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'checksum', onlyone => 1});
+ my ($warning, $critical) = validate_range({type => 'checksum', onlyone => 1});
eval {
require Digest::MD5;
## Supports: Nagios, MRTG
## Warning and critical are given in number of seconds difference
- my ($warning,$critical, $wuom, $cuom) = validate_range
+ my ($warning,$critical) = validate_range
({
type => 'seconds',
default_warning => 2,
## See: http://www.postgresql.org/docs/current/static/routine-vacuuming.html#VACUUM-FOR-WRAPAROUND
## It makes no sense to run this more than once on the same cluster
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'positive integer',
default_warning => 1_300_000_000,
}
}
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'version', forcemrtg => 1});
+ my ($warning, $critical) = validate_range({type => 'version', forcemrtg => 1});
my ($warnfull, $critfull) = (($warning =~ /^\d+\.\d+$/ ? 0 : 1),($critical =~ /^\d+\.\d+$/ ? 0 : 1));
my $valtype = $opt{valtype} || 'integer';
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => $valtype, leastone => 1});
+ my ($warning, $critical) = validate_range({type => $valtype, leastone => 1});
my $query = $opt{query} or ndie msg('custom-nostring');
## Supports: Nagios, MRTG
## Warning and critical are time to replicate to all slaves
- my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'time', leastone => 1, forcemrtg => 1});
+ my ($warning, $critical) = validate_range({type => 'time', leastone => 1, forcemrtg => 1});
if ($warning and $critical and $warning > $critical) {
ndie msg('range-warnbig');
## Warning and critical are percentages
## Can exclude and include sequences
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'percent',
default_warning => '85%',
## Warning and critical are seconds
## Requires $ENV{PGDATA} or --datadir
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'time',
leastone => 1,
## Supports: Nagios, MRTG
## Warning and critical are integers, defaults to 1
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'positive integer',
default_warning => 1,
## Most installations probably want no prepared_transactions
## Supports: Nagios, MRTG
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'seconds',
default_warning => '1',
## Supports: Cacti
## Assumes psql and target are the same version for the 8.3 check
- my ($warning, $critical, $wuom, $cuom) = validate_range
+ my ($warning, $critical) = validate_range
({
type => 'cacti',
});
information from the web: GET, wget, fetch, curl, lynx, links. To force the use of just
one (and thus remove the overhead of trying all the others until one of those works),
enter one of the names as the argument to get_method. For example, a BSD box might enter
-the folling line in their C<.check_postgresrc> file:
+the following line in their C<.check_postgresrc> file:
get_method=fetch
=head1 ENVIRONMENT VARIABLES
-The encironment variable I<$ENV{HOME}> is used to look for a F<.check_postgresrc> file.
+The environment variable I<$ENV{HOME}> is used to look for a F<.check_postgresrc> file.
=head1 TIPS AND TRICKS