From: Stephen L Johnson Date: Mon, 31 May 1999 19:41:36 +0000 (+0000) Subject: Initial import X-Git-Tag: start~42 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35527f42e5b450b42121b580d5a4544a261b3d1a;p=spong.git Initial import --- diff --git a/src/lib/Spong/Network/plugins/check_dns b/src/lib/Spong/Network/plugins/check_dns new file mode 100755 index 0000000..de85554 --- /dev/null +++ b/src/lib/Spong/Network/plugins/check_dns @@ -0,0 +1,50 @@ +# 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 +# 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. + +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]) ) { + $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; + diff --git a/src/lib/Spong/Network/plugins/check_http b/src/lib/Spong/Network/plugins/check_http new file mode 100755 index 0000000..1e77210 --- /dev/null +++ b/src/lib/Spong/Network/plugins/check_http @@ -0,0 +1,45 @@ +# Register the routine with the plugins registry +$PLUGINS{'http'} = \&check_http; + +# Http is a little special in that we also check the return code. No +# connection and 5xx codes are red, but 4xx return codes are just yellow. +# Also we go through a list of documents that the have been provided and check +# each one of them to make sure the web server is behaving correctly + +sub check_http { + my( $host ) = @_; + my( @http_files ) = ( @{$HTTPDOCS{"ALL"}}, @{$HTTPDOCS{$host}} ); + my( $http_port ) = $HTTPPORT{$host} || $HTTPPORT{"ALL"} || 80; + my( $file, $tmessage ) = ( "", "" ); + my( $color, $summary ) = ( "green", "" ); + + foreach $file ( @http_files ) { + my $message = + &check_tcp( $host, $http_port, "HEAD $file HTTP/1.0\r\n\r\n" ); + + if( $message =~ /HTTP\S+\s+(\d\d\d)\s.*$/m ) { + my $code = $1; + + if( $code >= 500 ) { + $color = "red"; $summary = "error - $code - $file"; + } elsif( $code >= 400 ) { + if( $color ne "red" ) { + $color = "yellow"; $summary = "warning - $code - $file"; } + } else { + if( $color ne "red" && $color ne "yellow" ) { + $color = "green"; $summary = "ok - $code"; } + } + } elsif( $message !~ /HTTP/m ) { + $color = "red"; $summary = "no response from http server"; + } else { + if( $color ne "red" ) { + $color = "yellow"; $summary = "can't determine status code";} + } + $tmessage .= "->HEAD $file HTTP/1.0\n$message\n"; + } + + &debug( "http - $host - $color, $summary" ); + return( $color, $summary, $tmessage ); +} + +1; diff --git a/src/lib/Spong/Network/plugins/check_nfs b/src/lib/Spong/Network/plugins/check_nfs new file mode 100755 index 0000000..1ed191c --- /dev/null +++ b/src/lib/Spong/Network/plugins/check_nfs @@ -0,0 +1,34 @@ +# Register the routine with the plugin registry +$PLUGINS{'nfs'} = \&check_nfs; + +# This will do a very simple NFS check by using the rpcinfo command to probe +# the portmapper at the remote host. It checks to make sure the nfs, and +# mountd services are responding. + +sub check_nfs { + my( $host ) = @_; + my( $color, $summary, $message, $rpcok ) = ( "green", "", "", 1 ); + my( $msg1, $msg2 ); + + $msg1 = `$RPCINFO $host nfs 2>&1`; + if( $msg1 !~ /ready and waiting/ ) { $rpcok = 0; } + $msg2 = `$RPCINFO $host mountd 2>&1`; + if( $msg2 !~ /ready and waiting/ ) { $rpcok = 0; } + + $message = "$msg1\n$msg2"; + if( $rpcok ) { + $color = "green"; + $summary = "nfs ok"; + } else { + $color = "red"; + $summary = "nfs down"; + } + + &debug( "nfs - $host - $color, $summary" ); + return( $color, $summary, $message ); +} + + + +1; +