[Table of Contents][Index]



spong-network-mod-template - A sample spong-network check module


This document describes a sample plug-in module for the spong-network program. Any modules that you create can be custom network checks, or they can be replacements for the core Spong modules.

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.


  # 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\n" )

      my $resolver = new Net::DNS::Resolver;
      $resolver->nameservers( $host );
      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.

Please note the final line. It is always required for a module file.


the developer-guide entry elsewhere in this document, the spong-network entry elsewhere in this document, the spong.conf manpage


Stephen L Johnson <>


Based on code/ideas from Sean MacGuire (BB), and Helen Harrison (Pong). Ed Hill original converted Big Brother ( into Perl which diverged from Big Brother to become Spong. Ed Hill continued Spong development until version 2.1. Stephen L Johnson took over development in October, 1999 with his changes which became Spong 2.5.

[Top] Generated by Pod::HTML 0.43 on Wed Jun 13 11:17:43 2001