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.
33 my $PROGNAME = "check_netdns";
35 Getopt
::Long
::Configure
(`bundling`);
36 GetOptions
("V" => $opt_V, "version" => $opt_V,
37 "h" => $opt_h, "help" => $opt_h,
38 "t=i" => $opt_t, "timeout=i" => $opt_t,
39 "s=s" => $opt_s, "server=s" => $opt_s,
40 "H=s" => $opt_H, "hostname=s" => $opt_H);
42 # -h means display verbose help screen
43 if($opt_h){ print_help
(); exit 0; }
45 # -V means display version number
46 if ($opt_V) { print_version
(); exit 0; }
49 $opt_H = shift unless ($opt_H);
50 unless ($opt_H) { print_usage
(); exit -1; }
52 $opt_H =~ m/^([0-9]+.[0-9]+.[0-9]+.[0-9]+|[a-zA-Z][-a-zA-Z0]+(.[a-zA-Z][-a-zA-Z0]+)*)$/)
56 print "$opt_H is not a valid host name";
60 # -s means server name
61 $opt_s = shift unless ($opt_s);
63 if ($opt_s =~ m/^([0-9]+.[0-9]+.[0-9]+.[0-9]+|[a-zA-Z][-a-zA-Z0]+(.[a-zA-Z][-a-zA-Z0]+)*)$/)
67 print "$opt_s is not a valid host name";
73 my $timeout = 10 unless ($opt_t);
75 my $res = new Net
::DNS
::Resolver
;
78 $res->nameservers($server);
81 $res->tcp_timeout($timeout);
82 $SIG{ALRM
} = &catch_alarm
;
85 $query = $res->query($host);
87 my @answer = $query->answer;
90 $_->type . ` ` . $_->rdatastr;
99 print "query failed: ", $res->errorstring, "";
104 print "query timed out";
108 sub print_version
() {
111 print "$arg0 version 0.1";
116 print "Check if a nameserver can resolve a given hostname.";
120 print "-H, --hostname=HOST";
121 print " The name or address you want to query";
122 print "-s, --server=HOST";
123 print " Optional DNS server you want to use for the lookup";
124 print "-t, --timeout=INTEGER";
125 print " Seconds before connection times out (default: 10)";
127 print " Print detailed help";
128 print "-V, --version";
129 print " Print version numbers and license information";
135 print "$arg0 check_dns -H host [-s server] [-t timeout]";
136 print "$arg0 [-h | --help]";
137 print "$arg0 [-V | --version]";