# Register the routine with the plugin registry
$PLUGINS{'mysql'} = \&check_mysql;

# This will check the status of MySQL on a system. It uses
# the mysqladmin command to query the server.
#
# Place this file in $SPONGHOME/lib/Spong/Network/plugins and add
#
# $MYSQLADMIN = "/usr/bin/mysqladmin -h";
# $DBUSER     = "user";
# $DBPASS     = "password";
#
# to spong.conf.
#
# Miles Lott <milos@insync.net>

sub check_mysql {
   my( $host ) = @_;
   my( $color, $summary, $message ) = ( "green", "Server OK", "" );

   open (MYSQL,"$MYSQLADMIN $host status -u$DBUSER -p$DBPASS 2>&1 |") || warn "Could not exec $MYSQLADMIN for status info.";
   while (<MYSQL>) {
      $message .= $_;
      if (/Can\'t connect/) {
         $color = "red"; $summary = "Server is unreachable.";
      }
      if (/Access denied/) {
             $color = "yellow"; $summary = "Server is up, but access is denied.";
      }
   }
  
   &debug( "mysql - $host - $color, $summary" );
   return( $color, $summary, $message );
}

1;