Next: spong-server | Previous: spong-network | [Table of Contents] | [Index] |
This template assumes that you are creating a network check called 'dns'. The name of the file created should be 'check_dns'. The file name should always be 'check_' plus the registry name (e.g. for the foo check, the registry name is 'foo' and the file name is 'check_foo'.
The line that has the assignment to $PLUGINS{'registry-name'} is the key to the registry mechanism. It's what ties the registry name to the the checking function.
The registry name does not always have to match up to the service name as in
the case of our module 'dns'. If you where creating a new and improved function
to ping and traceroute, you could create a module called 'ping_trace'. You
would use the registry name 'ping_trace', but you would use the service name
'ping' in the &main::status()
function when reporting your information
back to the server.
check_dns:
# 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"; &main::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"; } &main::debug( "dns - $host - $color, $summary" ); return( $color, $summary, $message ); } # I'm included perl code, I need this line. 1;Please note the final line. It is always required for a module file.
sjohnson@monsters.org
>