From: Stephen L Johnson Date: Wed, 13 Sep 2000 18:20:36 +0000 (+0000) Subject: stopped using Net::DNS moduel and started using dig/nslookup for checking. X-Git-Tag: spong-2_7_0-beta1~54 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6f4c7ad12ef7b53093a9543d6241d7a58281e45;p=spong.git stopped using Net::DNS moduel and started using dig/nslookup for checking. --- diff --git a/src/lib/Spong/Network/plugins/check_dns b/src/lib/Spong/Network/plugins/check_dns index de85554..0522de7 100755 --- a/src/lib/Spong/Network/plugins/check_dns +++ b/src/lib/Spong/Network/plugins/check_dns @@ -1,37 +1,30 @@ # 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 { @@ -44,7 +37,5 @@ sub check_dns { return( $color, $summary, $message ); } - - 1;