version 1.2, 2006/11/07 20:23:03 |
version 1.3, 2006/11/10 22:58:37 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $RedRiver: check_rrd,v 1.1 2006/11/07 20:21:19 andrew Exp $ |
# $RedRiver: check_rrd,v 1.2 2006/11/07 20:23:03 andrew Exp $ |
######################################################################## |
######################################################################## |
# check_rrd *** A nagios check for changing averages in rrds |
# check_rrd *** A nagios check for changing averages in rrds |
# |
# |
# 2006.05.01 #*#*# andrew fresh <andrew@mad-techies.org> |
# 2006.05.01 #*#*# andrew fresh <andrew@mad-techies.org> |
######################################################################## |
######################################################################## |
|
# Want to make this do 3 checks |
|
# * check percentage difference on day, hour, 5 min |
|
# * check actual number high/low |
|
# * check last time |
|
######################################################################## |
use strict; |
use strict; |
use warnings; |
use warnings; |
use RRDs; |
use RRDs; |
|
|
|
use Data::Dumper; |
|
|
%ENV = (); |
%ENV = (); |
|
|
use POSIX; |
use POSIX; |
|
|
ONE_DAY => 1 * 24 * 60 * 60, |
ONE_DAY => 1 * 24 * 60 * 60, |
); |
); |
|
|
|
my %Checks = ( |
|
max => { |
|
#warn => undef, |
|
#crit => undef, |
|
warn => -60, |
|
crit => -50, |
|
}, |
|
min => { |
|
#warn => undef, |
|
#crit => undef, |
|
warn => -80, |
|
crit => -85, |
|
}, |
|
change => { |
|
warn => 5, |
|
crit => 10, |
|
}, |
|
time => { |
|
warn => 15 * 60, # 15 minutes |
|
crit => 60 * 60, # 1 hour |
|
}, |
|
); |
|
|
my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK |
my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK |
my %states; # This stores the count of states; |
my %states; # This stores the count of states; |
my $filename; |
my $filename; |
|
|
exit $ERRORS{'OK'}; |
exit $ERRORS{'OK'}; |
} |
} |
|
|
my $info = RRDs::info($filename); |
my $info = RRDs::info($filename) or die "Problem with info from '$filename': $!"; |
|
|
my $resolution = $info->{'step'}; |
my $resolution = $info->{'step'}; |
my $last = $info->{'last_update'}; |
my $last = $info->{'last_update'}; |
|
|
|
my $age = time - $last; |
|
if ($age > $Checks{'time'}{'crit'}) { |
|
push @{ $states{'CRITICAL'} }, |
|
"Last check was too long ago"; |
|
} elsif ($age > $Checks{'time'}{'warn'}) { |
|
push @{ $states{'WARNING'} }, |
|
"Last check was too long ago"; |
|
} else { |
|
push @{ $states{'OK'} }, |
|
"Last check was within time limits"; |
|
} |
|
|
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{'ONE_DAY'}) / $resolution) * $resolution; |
|
|
|
|
'-r', $resolution, |
'-r', $resolution, |
'-s', $start, |
'-s', $start, |
'-e', $end |
'-e', $end |
); |
) or die "Problem fetching from '$filename': $!"; |
|
|
my %totals; |
my %totals; |
foreach my $line (@$data) { |
foreach my $line (@$data) { |
|
|
} |
} |
} |
} |
|
|
# XXX Need to replace this with real checks |
|
foreach my $key (keys %totals) { |
foreach my $key (keys %totals) { |
|
next if @rras and not grep { /^$key$/ } @rras; |
|
|
|
my $mins = $totals{$key}{'FIVE_MINUTES'}{'average'}; |
|
my $hour = $totals{$key}{'ONE_HOUR'}{'average'}; |
|
my $day = $totals{$key}{'ONE_DAY'}{'average'}; |
|
|
|
|
|
my ($s, $m) = check_delta($day, $hour); |
|
push @{ $states{$s} }, "$key: Hour $m"; |
|
|
|
($s, $m) = check_delta($hour, $mins); |
|
push @{ $states{$s} }, "$key: Minute $m"; |
|
|
|
($s, $m) = check_max($day); |
|
push @{ $states{$s} }, "$key: Day $m"; |
|
|
|
($s, $m) = check_min($day); |
|
push @{ $states{$s} }, "$key: Day $m"; |
|
|
|
($s, $m) = check_max($hour); |
|
push @{ $states{$s} }, "$key: Hour $m"; |
|
|
|
($s, $m) = check_min($hour); |
|
push @{ $states{$s} }, "$key: Hour $m"; |
|
|
|
($s, $m) = check_max($mins); |
|
push @{ $states{$s} }, "$key: Minute $m"; |
|
|
|
($s, $m) = check_min($mins); |
|
push @{ $states{$s} }, "$key: Minute $m"; |
|
|
print $key, ": "; |
print $key, ": "; |
print join ", ", |
print join ", ", |
$totals{$key}{'FIVE_MINUTES'}{'average'}, |
$totals{$key}{'ONE_DAY'}{'average'}, |
$totals{$key}{'ONE_HOUR'}{'average'}, |
$totals{$key}{'ONE_HOUR'}{'average'}, |
$totals{$key}{'ONE_DAY'}{'average'}; |
$totals{$key}{'FIVE_MINUTES'}{'average'}; |
print "\n"; |
print "\n"; |
} |
} |
|
|
|
print Dumper \%states; |
|
|
exit $ERRORS{$state}; |
exit $ERRORS{$state}; |
|
|
|
|
|
|
sub print_help { |
sub print_help { |
print <<EOL; |
print <<EOL; |
$PROGNAME plugin for Nagios checks averages in rrds |
$PROGNAME plugin for Nagios checks averages in rrds |
|
|
|
|
EOL |
EOL |
print_revision($PROGNAME, '$Revision$'); |
print_revision($PROGNAME, '$Revision$'); |
|
} |
|
|
|
sub check_max |
|
{ |
|
my ($num) = @_; |
|
|
|
my $state = 'UNKNOWN'; |
|
my $message = 'unknown status'; |
|
|
|
if (defined $Checks{'max'}{'crit'} && $num > $Checks{'max'}{'crit'}) { |
|
$state = 'CRITICAL'; |
|
$message = "actual value is ($num) greater than allowed"; |
|
} elsif (defined $Checks{'max'}{'warn'} && $num > $Checks{'max'}{'warn'}) { |
|
$state = 'WARNING'; |
|
$message = "actual value ($num) is greater than allowed"; |
|
} elsif (defined $Checks{'max'}{'crit'} && defined $Checks{'max'}{'warn'}) { |
|
$state = 'OK'; |
|
$message = "actual value ($num) is OK"; |
|
} |
|
|
|
return $state, $message; |
|
} |
|
|
|
sub check_min |
|
{ |
|
my ($num) = @_; |
|
|
|
my $state = 'UNKNOWN'; |
|
my $message = 'unknown status'; |
|
|
|
if ($Checks{'min'}{'crit'} && $num < $Checks{'min'}{'crit'}) { |
|
$state = 'CRITICAL'; |
|
$message = "actual value ($num) is smaller than allowed"; |
|
} elsif (defined $Checks{'min'}{'warn'} && $num < $Checks{'min'}{'warn'}) { |
|
$state = 'WARNING'; |
|
$message = "actual value ($num) is greater than allowed"; |
|
} elsif (defined $Checks{'min'}{'crit'} && defined $Checks{'min'}{'warn'}) { |
|
$state = 'OK'; |
|
$message = "actual value ($num) is OK"; |
|
} |
|
|
|
return $state, $message; |
|
} |
|
|
|
sub check_delta |
|
{ |
|
my ($primary, $secondary) = @_; |
|
|
|
my $state = 'UNKNOWN'; |
|
my $message = ''; |
|
|
|
my $delta = 0; |
|
$delta = ($primary - $secondary) / $primary * 100 if $primary != 0; |
|
print "Delta: $delta\n"; |
|
|
|
if (defined $Checks{'change'}{'crit'} |
|
&& abs($delta) > $Checks{'change'}{'crit'}) { |
|
$state = 'CRITICAL'; |
|
$message = "change ($delta%) is greater than allowed"; |
|
} elsif (defined $Checks{'change'}{'warn'} |
|
&& abs($delta) > $Checks{'change'}{'warn'}) { |
|
$state = 'WARNING'; |
|
$message = "change ($delta%) is greater than allowed"; |
|
} elsif (defined $Checks{'change'}{'crit'} |
|
&& defined $Checks{'change'}{'warn'}) { |
|
$state = 'OK'; |
|
$message = "change ($delta%) is OK"; |
|
} |
|
|
|
return $state, $message; |
} |
} |
|
|