X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=dsa-nagios-checks%2Fchecks%2Fdsa-check-zone-rrsig-expiration;h=06c4eccc2321bf4369bb90ac91ba1e9baf4cf253;hb=a9a2e2fb94e486d35a951c85b144d6cdcc054e1c;hp=a915c4bb67c66975e77cd6fd8ea308e32c4ac7de;hpb=16affb8426129c78732f64dc87efb7b609223073;p=mirror%2Fdsa-nagios.git diff --git a/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration b/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration index a915c4b..06c4ecc 100755 --- a/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration +++ b/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration @@ -38,6 +38,11 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +# Copyright (c) 2010 Peter Palfrader +# - various fixes and cleanups +# - do more than one zone + + # usage # # define command { @@ -71,18 +76,33 @@ use Time::HiRes qw ( gettimeofday tv_interval); use Time::Local; use List::Util qw ( shuffle ); +sub convert_time { + my $in = shift; + my ($ticks, $unit) = ($in =~ /^(\d+)([smhdw]?)$/); + + if ($unit eq 's' || $unit eq '') { } + elsif ($unit eq 'm') { $ticks *= 60; } + elsif ($unit eq 'h') { $ticks *= 60*60; } + elsif ($unit eq 'd') { $ticks *= 60*60*24; } + elsif ($unit eq 'w') { $ticks *= 60*60*24*7; } + else { die "Invalid unit '$unit' in '$in'\n" } + return $ticks; +} + my %opts = (t=>30); -getopts('Z:dt:', \%opts); -usage() unless $opts{Z}; +getopts('hdt:c:w:', \%opts); +usage() unless scalar @ARGV == 1; usage() if $opts{h}; -my $zone = $opts{Z}; -$zone =~ s/^zone\.//; +my $zone = $ARGV[0]; my $data; my $start; my $stop; -my $CRIT_DAYS = 3; -my $WARN_DAYS = 7; +my $CRIT = 3 * 3600*24; +my $WARN = 7 * 3600*24; + +$CRIT = convert_time($opts{c}) if defined $opts{c}; +$WARN = convert_time($opts{w}) if defined $opts{w}; my @refs = qw ( a.root-servers.net @@ -191,15 +211,15 @@ sub do_analyze { } } critical("$min_ns has expired RRSIGs") if ($min_exp < $NOW); - if ($min_exp - $NOW < ($CRIT_DAYS*86400)) { + if ($min_exp - $NOW < ($CRIT)) { my $ND = sprintf "%3.1f days", ($min_exp-$NOW)/86400; critical("$min_type RRSIG expires in $ND at $min_ns") } - if ($min_exp - $NOW < ($WARN_DAYS*86400)) { + if ($min_exp - $NOW < ($WARN)) { my $ND = sprintf "%3.1f days", ($min_exp-$NOW)/86400; warning("$min_type RRSIG expires in $ND at $min_ns") } - success("No RRSIGs expiring in the next $WARN_DAYS days"); + success(sprintf("No RRSIGs expiring in the next %3.1f days", $WARN/86400)); } sub sigrr_exp_epoch { @@ -249,7 +269,7 @@ sub output { } sub usage { - print STDERR "usage: $0 -Z zone\n"; + print STDERR "usage: $0 [-d] [-w=] [-c=] [-t=] \n"; exit 3; }