X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=dsa-nagios-checks%2Fchecks%2Fdsa-check-zone-rrsig-expiration-many;h=cfbacfd3b78f2b42c6ae1d37c01d072201734916;hb=3756e9519c4d13cdc6757d4329667481d12d6732;hp=05612861ebb15b928548a319315ed16b57175f70;hpb=95d831f4e33bb416632f85de4e3eaa41cfa232fb;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 0561286..cfbacfd 100755 --- a/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration-many +++ b/dsa-nagios-checks/checks/dsa-check-zone-rrsig-expiration-many @@ -66,9 +66,14 @@ sub check_one { my $zone = shift; my $check = shift; + my $extra = shift; my $params = shift; - open(P, '-|', ($check, '-w', $params->{'warn'}, '-c', $params->{'critical'}, $zone)) or die ("Cannot run $CHECK for $zone\n"); + 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 =

; close P; $p[0] = $zone.': '. $p[0] if (scalar @p > 0); @@ -78,13 +83,14 @@ sub check_one { return ($res, \@p); } -my $USAGE = "Usage: $PROGRAM_NAME [--help] | [--timeout=] [--warn=] [--critical=] [--geozonedir=] \n"; -my $params = { 'timeout' => 30, 'warn' => '14d', 'critical' => '7d' }; +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); @@ -105,24 +111,27 @@ my $count = }; -my @dnsseczones; +my %dnsseczones; # load list of classic zones that will do DNSSEC chdir $INDIR or die "chdir $INDIR failed? $!\n"; opendir INDIR, '.' or die ("Cannot opendir $INDIR\n"); for my $file (sort {$a cmp $b} (readdir INDIR)) { next if ( -l "$file" ); next unless ( -f "$file" ); - next if $file =~ /^(dsset|keyset)-/; - my $do_dnssec = 0; + my $do_dnssec = 1; + my $initial_refs = undef; open(F, '<', $file) or die ("Cannot open $file: $!\n"); for () { - if (/^; wzf:\s*dnssec\s*=\s*1\s*$/) { $do_dnssec = 1; last; } + if (/^; wzf:\s*dnssec\s*=\s*0\s*$/) { $do_dnssec = 0; } + if (/^; check-initial-refs\s*=\s*(.*?)\s*$/) { $initial_refs = $1; } }; close F; if ($do_dnssec) { - push @dnsseczones, $file; + 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; }; @@ -136,17 +145,9 @@ if (defined $params->{'geozonedir'}) { for my $file (sort {$a cmp $b} (readdir INDIR)) { next unless $file =~ /\.zone$/; - open (F, '<', $file) or die "Cannot open $file: $!\n"; - my ($zc, undef, undef) = Load(join "", ()); - close F; - my $zone = basename($file, '.zone'); - - if ($zc->{'dnssec'}) { - push @dnsseczones, $zone; - } else { - push @{$count->{'unsigned'}}, $zone; - }; + die "Duplicate zone $zone?\n" if exists $dnsseczones{$zone}; + $dnsseczones{$zone} = {}; } closedir(INDIR); } @@ -154,10 +155,10 @@ if (defined $params->{'geozonedir'}) { my @details; my %threads; -for my $zone (sort {$a cmp $b} @dnsseczones) { +for my $zone (sort {$a cmp $b} keys %dnsseczones) { die "Duplicate zone $zone?\n" if defined $threads{$zone}; my $thr = threads->create({'context' => 'list'}, - \&check_one, $zone, $CHECK, $params); + \&check_one, $zone, $CHECK, $dnsseczones{$zone}, $params); $threads{$zone} = $thr; } @@ -176,7 +177,9 @@ while (time - $begin <= $params->{timeout}) { else { push @{$count->{'unknown'}}, $zone; }; delete $threads{$zone}; } - sleep(1); + # print STDERR "foo #threads:", (scalar keys %threads), ":", join(",", keys %threads),"\n"; + last if scalar keys %threads == 0; + sleep 1; } for my $zone (sort {$a cmp $b} keys %threads) { push @{$count->{'warn'}}, $zone; @@ -208,4 +211,4 @@ for my $state (sort {$state_mapping{$b} <=> $state_mapping{$a}} keys %state_mapp printf "unsigned: %d", scalar @{$count->{'unsigned'}}; print "\n"; print $_ for (@details); -exit $exit; +exit ((defined $exit) ? $exit : 0);