From 2ece13eccf0bd4f5ce0aaf15c2bfdffed37b9d41 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Sun, 16 Dec 2018 21:54:43 +0100 Subject: [PATCH 1/2] allow time units to be used for monitoring warn/crit values --- sanoid | 48 ++++++++++++++++++++++++++++++++++++++++---- sanoid.defaults.conf | 12 +++++------ 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/sanoid b/sanoid index ddd457f..3aa57a3 100755 --- a/sanoid +++ b/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 diff --git a/sanoid.defaults.conf b/sanoid.defaults.conf index 96be95c..8785e7c 100644 --- a/sanoid.defaults.conf +++ b/sanoid.defaults.conf @@ -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 From cfab4eafdf2e8512f787db9e854835872493533f Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Sun, 16 Dec 2018 22:02:14 +0100 Subject: [PATCH 2/2] added/fixed documentation --- sanoid.defaults.conf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sanoid.defaults.conf b/sanoid.defaults.conf index 8785e7c..6649c2e 100644 --- a/sanoid.defaults.conf +++ b/sanoid.defaults.conf @@ -83,7 +83,8 @@ yearly_min = 0 # monitoring plugin - define warn / crit levels for each snapshot type by age, in units of one period down # example hourly_warn = 90 means issue WARNING if most recent hourly snapshot is not less than 90 minutes old, # daily_crit = 36 means issue CRITICAL if most recent daily snapshot is not less than 36 hours old, -# monthly_warn = 36 means issue WARNING if most recent monthly snapshot is not less than 36 days old... etc. +# monthly_warn = 5 means issue WARNING if most recent monthly snapshot is not less than 5 weeks old... etc. +# the following time suffixes can also be used: Y = years, M = months, W = weeks, D = days, h = hours, m = minutes, s = seconds # # monitor_dont_warn = yes will cause the monitoring service to report warnings as text, but with status OK. # monitor_dont_crit = yes will cause the monitoring service to report criticals as text, but with status OK.