X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=dsa-nagios-checks%2Fchecks%2Fdsa-check-zone-rrsig-expiration-many;h=674dd1c2b000ead32e1f17a4effd2939b06f7182;hb=f97779a92eb29c8dbbb48ad6becb3251da272c71;hp=ec97557daf1477e91c0db2de9dd37b17fcc353ff;hpb=513ded70330e665924e04d7e4c08a725947d3fd2;p=mirror%2Fdsa-nagios.git diff --git a/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration-many b/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration-many index ec97557..674dd1c 100755 --- a/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration-many +++ b/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration-many @@ -71,6 +71,7 @@ sub check_one { my @cmd = ($check, '-w', $params->{'warn'}, '-c', $params->{'critical'}); push(@cmd, '-r', $extra->{'initial_refs'}) if exists $extra->{'initial_refs'}; + push(@cmd, '-d') if $params->{'debug'}; push(@cmd, $zone); open(P, '-|', @cmd) or die ("Cannot run $CHECK for $zone\n"); my @p =

; @@ -82,13 +83,14 @@ sub check_one { return ($res, \@p); } -my $USAGE = "Usage: $PROGRAM_NAME [--help] | [--timeout=] [--warn=] [--critical=] [--geozonedir=] \n"; +my $USAGE = "Usage: $PROGRAM_NAME [--help] | [--debug] [--timeout=] [--warn=] [--critical=] [--geozonedir=] \n"; my $params = { 'timeout' => 45, 'warn' => '14d', 'critical' => '7d' }; Getopt::Long::config('bundling'); GetOptions ( '--help' => \$params->{'help'}, '--timeout=i' => \$params->{'timeout'}, '--warn=s' => \$params->{'warn'}, + '--debug' => \$params->{'debug'}, '--critical=s' => \$params->{'critical'}, '--geozonedir=s' => \$params->{'geozonedir'}, ) or die ($USAGE); @@ -100,13 +102,9 @@ die ($USAGE) unless (scalar @ARGV == 1); my $INDIR = shift; -my $count = - { 'ok' => [], - 'warn' => [], - 'critical' => [], - 'unknown' => [], - 'unsigned' => [], - }; +my $states = [qw{critical warn unknown ok unsigned}]; +my $count = { map { $_ => [] } @$states }; +my $details = { map { $_ => [] } @$states }; my %dnsseczones; @@ -118,20 +116,23 @@ for my $file (sort {$a cmp $b} (readdir INDIR)) { next unless ( -f "$file" ); my $do_dnssec = 1; + my $delegated = 1; my $initial_refs = undef; open(F, '<', $file) or die ("Cannot open $file: $!\n"); for () { if (/^; wzf:\s*dnssec\s*=\s*0\s*$/) { $do_dnssec = 0; } + if (/^; delegated\s*=\s*no\s*$/) { $delegated = 0; } if (/^; check-initial-refs\s*=\s*(.*?)\s*$/) { $initial_refs = $1; } }; close F; - if ($do_dnssec) { + if ($do_dnssec && $delegated) { die "Duplicate zone $file?\n" if exists $dnsseczones{$file}; $dnsseczones{$file} = {}; $dnsseczones{$file}->{'initial_refs'} = $initial_refs if defined $initial_refs; } else { - push @{$count->{'unsigned'}}, $file; + push @{$count ->{'unsigned'}}, $file; + push @{$details->{'unsigned'}}, "$file: marked unsigned or undelegated.\n"; }; } closedir(INDIR); @@ -150,8 +151,6 @@ if (defined $params->{'geozonedir'}) { closedir(INDIR); } -my @details; - my %threads; for my $zone (sort {$a cmp $b} keys %dnsseczones) { die "Duplicate zone $zone?\n" if defined $threads{$zone}; @@ -167,44 +166,52 @@ while (time - $begin <= $params->{timeout}) { my ($res, $det) = $threads{$zone}->join(); - push @details, @$det; + my $type = ($res == 0) ? 'ok' : + ($res == 1) ? 'warn' : + ($res == 2) ? 'critical' : + 'unknown'; - if ($res == 0) { push @{$count->{'ok'}}, $zone; } - elsif ($res == 1) { push @{$count->{'warn'}}, $zone; } - elsif ($res == 2) { push @{$count->{'critical'}}, $zone; } - else { push @{$count->{'unknown'}}, $zone; }; + push @{$details->{$type}}, @$det; + push @{$count ->{$type}}, $zone; delete $threads{$zone}; } - sleep(1) unless scalar keys %threads == 0; + last if scalar keys %threads == 0; + print STDERR (scalar keys %threads), " threads left: ", join(" ", keys %threads), "\n" if $params->{'debug'}; + sleep 1; } for my $zone (sort {$a cmp $b} keys %threads) { - push @{$count->{'warn'}}, $zone; - push @details, "$zone: timeout during check\n"; + push @{$count ->{'warn'}}, $zone; + push @{$details->{'warn'}}, "$zone: timeout during check\n"; $threads{$zone}->kill('KILL')->detach(); } -for my $k (keys %$count) { - @{$count->{$k}} = sort {$a cmp $b} @{$count->{$k}}; -} - my $exit = 0; my %state_mapping = ( 'unknown' => 255, 'critical' => 2, 'warn' => 1, + 'unsigned' => 0, 'ok' => 0 ); -for my $state (sort {$state_mapping{$b} <=> $state_mapping{$a}} keys %state_mapping) { +for my $state (@$states) { + @{$count->{$state}} = sort {$a cmp $b} @{$count->{$state}}; + @{$details->{$state}} = sort {$a cmp $b} @{$details->{$state}}; + if (scalar @{$count->{$state}}) { printf "%s: %d", uc($state), scalar @{$count->{$state}}; if ($state_mapping{$state} > 0) { print ": ", join(', ', @{$count->{$state}}); }; print "; "; - $exit = $state_mapping{$state} unless defined $exit; + $exit = $state_mapping{$state} if ($state_mapping{$state} > $exit); }; }; printf "unsigned: %d", scalar @{$count->{'unsigned'}}; print "\n"; -print $_ for (@details); +for my $state (@$states) { + for (@{$details->{$state}}) { + s/\|/;/g; + print $_; + } +} exit $exit;