mirror of https://github.com/jimsalterjrs/sanoid
allow time units to be used for monitoring warn/crit values
This commit is contained in:
parent
dc4df15e2e
commit
2ece13eccf
48
sanoid
48
sanoid
|
|
@ -143,8 +143,8 @@ sub monitor_snapshots {
|
|||
|
||||
my $typewarn = $type . '_warn';
|
||||
my $typecrit = $type . '_crit';
|
||||
my $warn = $config{$section}{$typewarn} * $smallerperiod;
|
||||
my $crit = $config{$section}{$typecrit} * $smallerperiod;
|
||||
my $warn = convertTimePeriod($config{$section}{$typewarn}, $smallerperiod);
|
||||
my $crit = convertTimePeriod($config{$section}{$typecrit}, $smallerperiod);
|
||||
my $elapsed = -1;
|
||||
if (defined $snapsbytype{$path}{$type}{'newest'}) {
|
||||
$elapsed = $snapsbytype{$path}{$type}{'newest'};
|
||||
|
|
@ -153,7 +153,7 @@ sub monitor_snapshots {
|
|||
my $dispwarn = displaytime($warn);
|
||||
my $dispcrit = displaytime($crit);
|
||||
if ( $elapsed > $crit || $elapsed == -1) {
|
||||
if ($config{$section}{$typecrit} > 0) {
|
||||
if ($crit > 0) {
|
||||
if (! $config{$section}{'monitor_dont_crit'}) { $errorlevel = 2; }
|
||||
if ($elapsed == -1) {
|
||||
push @msgs, "CRIT: $path has no $type snapshots at all!";
|
||||
|
|
@ -162,7 +162,7 @@ sub monitor_snapshots {
|
|||
}
|
||||
}
|
||||
} elsif ($elapsed > $warn) {
|
||||
if ($config{$section}{$typewarn} > 0) {
|
||||
if ($warn > 0) {
|
||||
if (! $config{$section}{'monitor_dont_warn'} && ($errorlevel < 2) ) { $errorlevel = 1; }
|
||||
push @msgs, "WARN: $path\'s newest $type snapshot is $dispelapsed old (should be < $dispwarn)";
|
||||
}
|
||||
|
|
@ -1511,6 +1511,46 @@ sub runscript {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
#######################################################################################################################3
|
||||
#######################################################################################################################3
|
||||
#######################################################################################################################3
|
||||
|
||||
sub convertTimePeriod {
|
||||
my $value=shift;
|
||||
my $period=shift;
|
||||
|
||||
if ($value =~ /^\d+Y$/) {
|
||||
$period = 60*60*24*31*365;
|
||||
chop $value;
|
||||
} elsif ($value =~ /^\d+M$/) {
|
||||
$period = 60*60*24*31;
|
||||
chop $value;
|
||||
} elsif ($value =~ /^\d+W$/) {
|
||||
$period = 60*60*24*7;
|
||||
chop $value;
|
||||
} elsif ($value =~ /^\d+D$/) {
|
||||
$period = 60*60*24;
|
||||
chop $value;
|
||||
} elsif ($value =~ /^\d+h$/) {
|
||||
$period = 60*60;
|
||||
chop $value;
|
||||
} elsif ($value =~ /^\d+m$/) {
|
||||
$period = 60;
|
||||
chop $value;
|
||||
} elsif ($value =~ /^\d+s$/) {
|
||||
$period = 1;
|
||||
chop $value;
|
||||
} elsif ($value =~ /^\d+$/) {
|
||||
# no unit, provided fallback period is used
|
||||
} else {
|
||||
# invalid value, return smallest valid value as fallback
|
||||
# (will trigger a warning message for monitoring for sure)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $value * $period;
|
||||
}
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
|
|
|||
|
|
@ -94,14 +94,14 @@ monitor_dont_warn = no
|
|||
monitor_dont_crit = no
|
||||
frequently_warn = 0
|
||||
frequently_crit = 0
|
||||
hourly_warn = 90
|
||||
hourly_crit = 360
|
||||
daily_warn = 28
|
||||
daily_crit = 32
|
||||
hourly_warn = 90m
|
||||
hourly_crit = 360m
|
||||
daily_warn = 28h
|
||||
daily_crit = 32h
|
||||
weekly_warn = 0
|
||||
weekly_crit = 0
|
||||
monthly_warn = 32
|
||||
monthly_crit = 40
|
||||
monthly_warn = 32D
|
||||
monthly_crit = 40D
|
||||
yearly_warn = 0
|
||||
yearly_crit = 0
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue