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
9 # Revision 1.3 2002/05/07 05:35:49 sghosh
12 # Revision 1.2 2002/05/02 16:43:29 sghosh
13 # fix for embedded perl
15 # Revision 1.1.1.1 2002/02/28 06:43:00 egalstad
16 # Initial import of existing plugin code
18 # Revision 1.1 2000/08/03 20:41:12 karldebisschop
19 # rename to avoid conflict when installing
21 # Revision 1.1 2000/08/03 19:27:08 karldebisschop
22 # use Net::DNS to check name server
24 # Revision 1.1 2000/07/20 19:09:13 cwg
25 # All the pieces needed to use my version of check_dns.
34 my $PROGNAME = "check_netdns";
36 Getopt
::Long
::Configure
(`bundling`);
37 GetOptions
("V" => $opt_V, "version" => $opt_V,
38 "h" => $opt_h, "help" => $opt_h,
39 "t=i" => $opt_t, "timeout=i" => $opt_t,
40 "s=s" => $opt_s, "server=s" => $opt_s,
41 "H=s" => $opt_H, "hostname=s" => $opt_H);
43 # -h means display verbose help screen
44 if($opt_h){ print_help
(); exit 0; }
46 # -V means display version number
47 if ($opt_V) { print_version
(); exit 0; }
50 $opt_H = shift unless ($opt_H);
51 unless ($opt_H) { print_usage
(); exit -1; }
53 $opt_H =~ m/^([0-9]+.[0-9]+.[0-9]+.[0-9]+|[a-zA-Z][-a-zA-Z0]+(.[a-zA-Z][-a-zA-Z0]+)*)$/)
57 print "$opt_H is not a valid host name";
61 # -s means server name
62 $opt_s = shift unless ($opt_s);
64 if ($opt_s =~ m/^([0-9]+.[0-9]+.[0-9]+.[0-9]+|[a-zA-Z][-a-zA-Z0]+(.[a-zA-Z][-a-zA-Z0]+)*)$/)
68 print "$opt_s is not a valid host name";
74 my $timeout = 10 unless ($opt_t);
76 my $res = new Net
::DNS
::Resolver
;
79 $res->nameservers($server);
82 $res->tcp_timeout($timeout);
83 $SIG{ALRM
} = &catch_alarm
;
86 $query = $res->query($host);
88 my @answer = $query->answer;
91 $_->type . ` ` . $_->rdatastr;
100 print "query failed: ", $res->errorstring, "";
105 print "query timed out";
109 sub print_version
() {
112 print "$arg0 version 0.1";
117 print "Check if a nameserver can resolve a given hostname.";
121 print "-H, --hostname=HOST";
122 print " The name or address you want to query";
123 print "-s, --server=HOST";
124 print " Optional DNS server you want to use for the lookup";
125 print "-t, --timeout=INTEGER";
126 print " Seconds before connection times out (default: 10)";
128 print " Print detailed help";
129 print "-V, --version";
130 print " Print version numbers and license information";
136 print "$arg0 check_dns -H host [-s server] [-t timeout]";
137 print "$arg0 [-h | --help]";
138 print "$arg0 [-V | --version]";