# Register the routine with the plugin registry
$PLUGINS{'dns'} = \&check_dns;

# 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.4 2001/09/17 01:35:25 sljohnson Exp $

sub check_dns {
   my( $host ) = @_;
   my( $color, $summary, $message ) = ( "green", "", "" );

   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"; } 
   elsif ( $DNSCMD =~ /host/ ) { $cmd = "$DNSCMD $host $host >/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" );
        }

   safe_exec($cmd,15);

   if ( ($? >> 8) == 0 ) {
      $color = "green";
      $summary = "dns ok";
   } else {
      $color = "red";
      $summary = "can't resolve $host";
      $message = "can't resolve $host\n";
   }
   
   &debug( "dns - $host - $color, $summary" );
   return( $color, $summary, $message );
}

1;

