version 1.6, 2007/01/10 18:41:04 |
version 1.7, 2007/01/12 21:56:01 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $RedRiver: check_rrd,v 1.5 2007/01/10 01:17:44 andrew Exp $ |
# $RedRiver: check_rrd,v 1.6 2007/01/10 18:41:04 andrew Exp $ |
######################################################################## |
######################################################################## |
# check_rrd *** A nagios check for changing averages in rrds |
# check_rrd *** A nagios check for changing averages in rrds |
# |
# |
|
|
|
|
my %TIMES = ( |
my %TIMES = ( |
FIVE_MINUTES => 5 * 60, |
FIVE_MINUTES => 5 * 60, |
ONE_HOUR => 1 * 60 * 60, |
HOUR => 1 * 60 * 60, |
ONE_DAY => 1 * 24 * 60 * 60, |
DAY => 1 * 24 * 60 * 60, |
|
WEEK => 7 * 24 * 60 * 60 |
); |
); |
|
|
my %Checks = ( |
my %Checks = ( |
|
|
my @rras; |
my @rras; |
my @warning; |
my @warning; |
my @critical; |
my @critical; |
|
my $time; |
|
my @time = ( |
|
'WEEK', |
|
'DAY', |
|
'HOUR', |
|
); |
my $opt_V; |
my $opt_V; |
|
|
|
|
#Option checking |
#Option checking |
my $status = GetOptions( |
my $status = GetOptions( |
"version|V" => \$opt_V, |
"version|V" => \$opt_V, |
"filename|f=s" => \$filename, |
"filename|f=s" => \$filename, |
"rra|r=s" => \@rras, |
"rra|r=s" => \@rras, |
|
"time|t=s" => \$time, |
"warning|w=s" => \@warning, |
"warning|w=s" => \@warning, |
"critical|c=s" => \@critical, |
"critical|c=s" => \@critical, |
); |
); |
|
|
@critical = split(/,/,join(',',@critical)); |
@critical = split(/,/,join(',',@critical)); |
@warning = split(/,/,join(',',@warning)); |
@warning = split(/,/,join(',',@warning)); |
|
|
|
if ($time) { |
|
@time = split /:/, $time; |
|
for (0..2) { |
|
unless ($time[$_]) { |
|
die "Time usage needs 3 entries, like 'WEEK:DAY:HOUR'"; |
|
} |
|
unless (exists $TIMES{ $time[$_] }) { |
|
die "Times need to be one of WEEK, DAY, HOUR or FIVE_MINUTES"; |
|
} |
|
print $TIMES{ $time[$_] }, "\n"; |
|
} |
|
} |
|
|
|
#print Dumper $time, \@time; |
|
|
update_checks(\%Checks, 'crit', \@critical); |
update_checks(\%Checks, 'crit', \@critical); |
update_checks(\%Checks, 'warn', \@warning); |
update_checks(\%Checks, 'warn', \@warning); |
|
|
|
|
} |
} |
|
|
my $end = int($last / $resolution) * $resolution; |
my $end = int($last / $resolution) * $resolution; |
my $start = int( ($end - $TIMES{'ONE_DAY'}) / $resolution) * $resolution; |
my $start = int( ($end - $TIMES{ $time[0] }) / $resolution) * $resolution; |
|
|
my ($first, $step, $names, $data) = RRDs::fetch( |
my ($first, $step, $names, $data) = RRDs::fetch( |
$filename, |
$filename, |
|
|
next if @rras and not grep { /^$key$/ } @rras; |
next if @rras and not grep { /^$key$/ } @rras; |
|
|
my %w; |
my %w; |
$w{'Minute'} = $totals{$key}{'FIVE_MINUTES'}{'average'}; |
$w{ $time[0] } = $totals{$key}{ $time[0] }{'average'}; |
$w{'Hour'} = $totals{$key}{'ONE_HOUR'}{'average'}; |
$w{ $time[1] } = $totals{$key}{ $time[1] }{'average'}; |
$w{'Day'} = $totals{$key}{'ONE_DAY'}{'average'}; |
$w{ $time[2] } = $totals{$key}{ $time[2] }{'average'}; |
|
|
|
|
TYPE: foreach my $type ('change', 'abs') { |
TYPE: foreach my $type ('change', 'abs') { |
|
|
|
|
if ($type eq 'change') { |
if ($type eq 'change') { |
my %deltas = ( |
my %deltas = ( |
Hour => [ $w{'Day'}, $w{'Hour'} ], |
$time[1] => [ $w{ $time[0] }, $w{ $time[1] } ], |
Minute => [ $w{'Hour'}, $w{'Minute'} ], |
$time[2] => [ $w{ $time[1] }, $w{ $time[2] } ], |
); |
); |
|
|
foreach my $d (keys %deltas) { |
foreach my $d (keys %deltas) { |
|
|
} |
} |
|
|
} else { |
} else { |
foreach my $time ('Day', 'Hour', 'Minute') { |
foreach my $time (@time) { |
if ((not $check_status{$key}{$time}) && |
if ((not $check_status{$key}{$time}) && |
( $res eq 'OK' || |
( $res eq 'OK' || |
( not range_ok($w{$time}, $min, $max) ) |
( not range_ok($w{$time}, $min, $max) ) |
|
|
foreach my $s (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) { |
foreach my $s (sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS) { |
foreach my $DS (sort keys %check_status) { |
foreach my $DS (sort keys %check_status) { |
foreach my $key (sort keys %{ $check_status{$DS} }) { |
foreach my $key (sort keys %{ $check_status{$DS} }) { |
next unless $check_status{$DS}{$key}{'status'} eq $s;; |
next unless $check_status{$DS}{$key}{'status'} eq $s; |
$have_results++; |
$have_results++; |
$state = $s; |
$state = $s; |
push @{ $states{$s} }, |
push @{ $states{$s} }, |