dsa-check-zone-rrsig-expiration-many: Print which threads we are waiting on with...
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-zone-rrsig-expiration-many
index 0561286..4139b0d 100755 (executable)
@@ -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 = <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=<nn>] [--warn=<nn>] [--critical=<nn>] [--geozonedir=<geodir>] <indir>\n";
-my $params = { 'timeout' => 30, 'warn' => '14d', 'critical' => '7d' };
+my $USAGE = "Usage: $PROGRAM_NAME [--help] | [--debug] [--timeout=<nn>] [--warn=<nn>] [--critical=<nn>] [--geozonedir=<geodir>] <indir>\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 (<F>) {
-               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 "", (<F>));
-               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);
+       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;
@@ -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);