# Register this routine with the plugin registery

$CHECKFUNCS{'processes'} = \&check_processes;


# This routine checks processes running on the host and makes sure that
# the important ones are running

# $Id: check_processes,v 1.5 2001/09/16 18:08:39 sljohnson Exp $

use Spong::SafeExec qw(safe_exec);

sub check_processes { 
   my $color    = "green";
   my( $message, $summary, $check, @ret, $down, @down, $time, $critical );
   my (@plist);
   
   @plist = safe_exec($PS,30);

   foreach $check ( @JOBSWARN, @PROCSWARN ) {
      $cnt = 1;
      if ($check =~ /^([^:]+):(.*)$/o) {
        $cnt = $2;
        $check = $1;
      }
      @ret = grep (/$check/, @plist);
      if( scalar @ret < $cnt ) { $color = "yellow"; push( @down, "$check:$cnt" ); }
      else { $message .= join ('',@ret); }
   }
   foreach $check ( @JOBSCRIT, @PROCSCRIT ) {
      $cnt = 1;
      if ($check =~ /^([^:]+):(.*)$/o) {
        $cnt = $2;
        $check = $1;
      }
      @ret = grep (/$check/, @plist);
      if( scalar @ret < $cnt ) { $color = "red"; push( @down, "$check:$cnt" ); }
      else { $message .= join ('',@ret); }
   }

   $summary = "processes ok"        if $color eq "green";
   $summary = "(@down) not running" if $color ne "green";

   &debug( "jobs - $color, $summary" );
   &status( $SPONGSERVER, $HOST, "jobs", $color, $summary, $message );
}

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