forked from dotse/dnssec-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nagios_dnssec.pl
171 lines (134 loc) · 4.63 KB
/
nagios_dnssec.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/perl
#
# Copyright (c) 2010 .SE (The Internet Infrastructure Foundation).
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
######################################################################
require 5.8.0;
use warnings;
use strict;
use Crypt::OpenSSL::Random qw(random_bytes);
use Digest::SHA1 qw(sha1);
use Digest::BubbleBabble qw(bubblebabble);
use Pod::Usage;
use Getopt::Long;
use dnssec_monitor;
######################################################################
sub main {
my $debug = 0;
my $help = 0;
my $zone;
my $ksk_expire_critical = 7;
my $ksk_expire_warning = 14;
my $zsk_expire_critical = 1;
my $zsk_expire_warning = 3;
my $dstport = 53;
my $enable_wildcard = 0;
my $enable_nsec3 = 0;
GetOptions(
'help|?' => \$help,
'zone=s' => \$zone,
'kskcritical=i' => \$ksk_expire_critical,
'kskwarning=i' => \$ksk_expire_warning,
'zskcritical=i' => \$zsk_expire_critical,
'zskwarning=i' => \$zsk_expire_warning,
'debug+' => \$debug,
'dstport=i' => \$dstport,
'wildcard' => \$enable_wildcard,
'nsec3' => \$enable_nsec3,
) or die;
pod2usage(2) if ($help);
die "no zone" unless ($zone);
die "no nameserver" unless ($#ARGV == 0);
my %args = (
quiet => 1,
debug => $debug,
ksk_expire_critical => $ksk_expire_critical,
ksk_expire_warning => $ksk_expire_warning,
zsk_expire_critical => $zsk_expire_critical,
zsk_expire_warning => $zsk_expire_warning,
dstport => $dstport,
);
my $ns = shift @ARGV;
my $c = new dnssec_monitor($zone, $ns, %args);
# create nonexisting domain name
my @tmp = split(/-/, bubblebabble(Digest => sha1(random_bytes(64))));
my $nonexisting = sprintf("%s.%s", join("", @tmp[1 .. 6]), $zone);
#### NAGIOS CHECKS ####
unless ($c->check_apex_rrsig()) {
nagios($c->{error});
}
unless ($c->check_exist($zone, "SOA")) {
nagios($c->{error});
}
unless ($c->check_exist($zone, "NS")) {
nagios($c->{error});
}
unless ($c->check_nxdomain($nonexisting, "NS", $enable_wildcard, $enable_nsec3)) {
nagios($c->{error});
}
nagios("OK: Looking good");
}
sub nagios {
$_ = shift;
if (/^WARNING: (.*)/) {
print "DNSSEC WARNING: $1\n";
exit(1);
}
if (/^CRITICAL: (.*)/) {
print "DNSSEC CRITICAL: $1\n";
exit(2);
}
if (/^UNKNOWN: (.*)/) {
print "DNSSEC UNKNOWN: $1\n";
exit(3);
}
if (/^OK: (.*)/) {
print "DNSSEC OK: $1\n";
exit(0);
}
if (/^(.*)/) {
print "DNSSEC CRITICAL: $1\n";
exit(2);
}
exit(-1);
}
main;
=head1 NAME
nagios_dnssec.pl - Nagios DNSSEC Plugin
=head1 SYNOPSIS
nagios_dssec.pl --zone zonename nameserver
--zone zone The zone to test (required argument)
--kskcritical=i KSK critical (days)
--kskwarning=i KSK warning (days)
--zskcritical=i ZSK critical (days)
--zskwarning=i ZSK warning (days)
--debug Debug mode
--dstport=i Destination port on name server (53 is default)
=head1 AUTHOR
.SE
=head1 LICENCE AND COPYRIGHT
Copyright (c) .SE, The Internet Infrastructure Foundation (2010) <[email protected]>
BSD License.
=cut