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=b3923761df2779305961f11dc4e953dc31624f00;hp=b97cb09fdb653e6af840749eb68b42b843f3df10;hpb=2e0c04d4e9ecd89ae6470e76feb9db5601e9c21a;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 b97cb09..674dd1c 100755 --- a/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration-many +++ b/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration-many @@ -102,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; @@ -120,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); @@ -152,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}; @@ -169,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;