3 # Copyright (c) 2010 Peter Palfrader <peter@palfrader.org>
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 my $CHECK = $Bin.'/dsa-check-zone-rrsig-expiration';
41 unless (defined $unit) {
43 ($newticks, $unit) = $ticks =~ m/^(\d*)([smhdw]?)$/;
44 if (!defined $newticks) {
45 print STDERR "Warning: invalid timestring to convert '$ticks'\n";
51 if ($unit eq 's' || $unit eq '') { }
52 elsif ($unit eq 'm') { $ticks *= 60; }
53 elsif ($unit eq 'h') { $ticks *= 60*60; }
54 elsif ($unit eq 'd') { $ticks *= 60*60*24; }
55 elsif ($unit eq 'w') { $ticks *= 60*60*24*7; }
56 else { print STDERR "Warning: invalid unit '$unit'\n" }
60 my $USAGE = "Usage: $PROGRAM_NAME [--help] | [--warn=<nn>] [--critical=<nn>] <indir>\n";
61 my $params = { 'warn' => '14d', 'critical' => '7d' };
62 Getopt::Long::config('bundling');
64 '--help' => \$params->{'help'},
65 '--warn=s' => \$params->{'warn'},
66 '--critical=s' => \$params->{'critical'},
68 if ($params->{'help'}) {
72 die ($USAGE) unless (scalar @ARGV == 1);
77 chdir $INDIR or die "chdir $INDIR failed? $!\n";
78 opendir INDIR, $INDIR or die ("Cannot opendir $INDIR\n");
79 for my $file (readdir INDIR) {
80 next if ( -l "$file" );
81 next unless ( -f "$file" );
82 next if $file =~ /^(dsset|keyset)-/;
99 for my $zone (sort {$a cmp $b} @zones) {
101 open(F, '<', $zone) or die ("Cannot open $zone: $!\n");
103 if (/^; wzf:\s*dnssec\s*=\s*1\s*$/) { $do_dnssec = 1; }
107 unless ($do_dnssec) {
108 push @{$count->{'unsigned'}}, $zone;
113 open(P, '-|', ($CHECK, '-w', $params->{'warn'}, '-c', $params->{'critical'}, $zone)) or die ("Cannot run $CHECK for $zone\n");
116 $p[0] = $zone.': '. $p[0] if (scalar @p > 0);
119 my $res = $CHILD_ERROR >> 8;
120 if ($res == 0) { push @{$count->{'ok'}}, $zone; }
121 elsif ($res == 1) { push @{$count->{'warn'}}, $zone; }
122 elsif ($res == 2) { push @{$count->{'critical'}}, $zone; }
123 else { push @{$count->{'unknown'}}, $zone; };
127 my %state_mapping = (
133 for my $state (sort {$state_mapping{$b} <=> $state_mapping{$a}} keys %state_mapping) {
134 if (scalar @{$count->{$state}}) {
135 printf "%s: %d", uc($state), scalar @{$count->{$state}};
136 if ($state_mapping{$state} > 0) {
137 print ": ", join(', ', @{$count->{$state}});
140 $exit = $state_mapping{$state} unless defined $exit;
143 printf "unsigned: %d", scalar @{$count->{'unsigned'}};
145 print $_ for (@details);