The line that has the assignment to $PLUGINS{'registry-name'} is the key to the registry mechanism. It's what track the registry name to the your check function.
The registry name does not always have to match up to the service name as in this case of '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 &status() function when reporting you info back to the server.
# 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 );
}
# I;m included perl code, I need this line.
1;
Please note the final line. It is always required for a module file.