# Register the routine with the plugin registry
$PLUGINS{'dns'} = \&check_dns;
-# Check to see if they have the Net::DNS module installed, and if they do we
-# can then do DNS queries, and see if DNS servers are alive.
-
-eval "require Net::DNS;";
-if( ! $@ ) { $dns = 1; } else { $dns = 0; }
-
-# This check will (if the Net::DNS module is available) connect to a DNS server
+# This check will connect to a DNS server
# and ask that server to resolve it's own name. If it can do that, then we
# assume it is ok - If it can't then something is wrong.
+# $Id: check_dns,v 1.2 2000/09/13 18:20:36 sljohnson Exp $
+
sub check_dns {
my( $host ) = @_;
my( $color, $summary, $message ) = ( "green", "", "" );
-
- if( ! $dns ) {
- $summary = "can't do DNS lookups, Net::DNS not installed";
- &debug( "dns - $host - $color, $summary" );
- return ( "yellow", $summary,
- "In order to do DNS queries you must install the Net::DNS " .
- "Perl module.\nYou can find the module at your nearest CPAN " .
- "archive or http://www.perl.com/CPAN/\n" );
- }
-
- my $resolver = new Net::DNS::Resolver;
- $resolver->nameservers( $host );
- $resolver->retrans(2);
- $resolver->retry(1);
- $resolver->recurse(0);
- my $q = $resolver->search( $host, "A" );
-
- if( defined $q && defined $q->answer && defined (($q->answer)[0]) ) {
+
+ my $cmd;
+ if ( $DNSCMD =~ /nslookup/ ) { $cmd = "$DNSCMD -type=A $host $host >/dev/null 2>&1" }
+ elsif ( $DNSCMD =~ /dig/ ) { $cmd = "$DNSCMD \@$host $host a >/dev/null 2>&1"; }
+ else { return ( "yellow", "\$DNSCMD variable is not set to a proper value",
+ "Valid values for the \$DNSCMD variable are 'nslookup'" .
+ " or 'dig', with the full path name to the command. This" .
+ " variable must be set properly in order to do DNS " .
+ "queries.\n" );
+ }
+
+
+ system($cmd);
+
+ if ( ($? >> 8) == 0 ) {
$color = "green";
$summary = "dns ok";
} else {
return( $color, $summary, $message );
}
-
-
1;