#
# check_raid
# Version 0.1
# 28-Nov-02
#
# Written and maintained by Robert Harrison
#
# email: rharrison@hgfip.com
#
# This is a plugin to spong to monitor the /proc/mdstat
# file created using raidtools 
# 
# OUTPUTS
#
# Green : RAID appears to be fine
# Yellow: RAID is being built or recovered
# RED 	: RAID has disk down
#
# The message is a cat of /proc/mdstat
#

# Register this routine with the plugin registry
$CHECKFUNCS{'raid'} = \&check_raid;

sub check_raid { 

   my $color    = "green";
   my $raidfile = "/proc/mdstat";
   my ( $message, $summary );
   my $num_error;

   $summary = "looks to be working fine"; 

   open (FOO,"$raidfile");

   while (<FOO>){
      $message .= $_ ;
   }

   close (FOO);

   $num_error = grep /\(F\)/i, $message;
   if ($num_error > 0) {
	$color = "red";
   	$summary = "Disk Error REPLACE DRIVE NOW"; 
   }

   $num_error = grep /resync/i, $message;
   if ($num_error > 0) {
	$color = "yellow";
   	$summary = "Being built ..."; 
   }

   $num_error = grep /recovery/i, $message;
   if ($num_error > 0) {
	$color = "yellow";
   	$summary = "Being recovered ..."; 
   }

   &debug( "raid - $color, $summary" );

   &status( $SPONGSERVER, $HOST, "raid", $color, $summary, $message );
}

# I'm included perl code, I need this line.
1;