3 # Perl version of check_dns plugin which calls DNS directly instead of
4 # relying on nslookup (which has bugs)
6 # Copyright 2000, virCIO, LLP
8 # Revision 1.3 2002/05/07 05:35:49 sghosh
11 # Revision 1.2 2002/05/02 16:43:29 sghosh
12 # fix for embedded perl
14 # Revision 1.1.1.1 2002/02/28 06:43:00 egalstad
15 # Initial import of existing plugin code
17 # Revision 1.1 2000/08/03 20:41:12 karldebisschop
18 # rename to avoid conflict when installing
20 # Revision 1.1 2000/08/03 19:27:08 karldebisschop
21 # use Net::DNS to check name server
23 # Revision 1.1 2000/07/20 19:09:13 cwg
24 # All the pieces needed to use my version of check_dns.
31 use lib
"$FindBin::Bin";
34 my $PROGNAME = "check_netdns";
39 $ENV{'PATH'}='@TRUSTED_PATH@';
43 Getopt
::Long
::Configure
(`bundling`);
44 GetOptions
("V" => $opt_V, "version" => $opt_V,
45 "h" => $opt_h, "help" => $opt_h,
46 "t=i" => $opt_t, "timeout=i" => $opt_t,
47 "s=s" => $opt_s, "server=s" => $opt_s,
48 "H=s" => $opt_H, "hostname=s" => $opt_H);
50 # -h means display verbose help screen
51 if($opt_h){ print_help
(); exit 3; }
53 # -V means display version number
54 if ($opt_V) { print_version
(); exit 3; }
57 $opt_H = shift unless ($opt_H);
58 unless ($opt_H) { print_usage
(); exit -1; }
60 $opt_H =~ m/^([0-9]+.[0-9]+.[0-9]+.[0-9]+|[a-zA-Z][-a-zA-Z0]+(.[a-zA-Z][-a-zA-Z0]+)*)$/)
64 print "$opt_H is not a valid host name";
68 # -s means server name
69 $opt_s = shift unless ($opt_s);
71 if ($opt_s =~ m/^([0-9]+.[0-9]+.[0-9]+.[0-9]+|[a-zA-Z][-a-zA-Z0]+(.[a-zA-Z][-a-zA-Z0]+)*)$/)
75 print "$opt_s is not a valid host name";
81 my $timeout = 10 unless ($opt_t);
83 my $res = new Net
::DNS
::Resolver
;
86 $res->nameservers($server);
89 $res->tcp_timeout($timeout);
90 $SIG{ALRM
} = &catch_alarm
;
93 $query = $res->query($host);
95 my @answer = $query->answer;
98 $_->type . ` ` . $_->rdatastr;
102 print "empty answer";
107 print "query failed: ", $res->errorstring, "";
112 print "query timed out";
116 sub print_version
() {
119 print "$arg0 version 0.1";
124 print "Check if a nameserver can resolve a given hostname.";
128 print "-H, --hostname=HOST";
129 print " The name or address you want to query";
130 print "-s, --server=HOST";
131 print " Optional DNS server you want to use for the lookup";
132 print "-t, --timeout=INTEGER";
133 print " Seconds before connection times out (default: 10)";
135 print " Print detailed help";
136 print "-V, --version";
137 print " Print version numbers and license information";
143 print "$arg0 check_dns -H host [-s server] [-t timeout]";
144 print "$arg0 [-h | --help]";
145 print "$arg0 [-V | --version]";