#!/usr/bin/perl
# check_disksuite - 
#
# Moved the regular expressions into the script 
# eliminating the need for grep in the metastat
# command line
#
# - Mike Adams 10/15/04
#
#
#
# Very simple script to parse the output
# of the disksuite command "metastat"
#
# Okay       = State: Okay
# Warning    = State: Resync
# CRITICAL   = State: Anything else
#
# - Mike Adams 08/27/04
#

@states = `/usr/sbin/metastat`;
foreach $state (@states) {
  if($state =~ /State/) {
    if($state =~ /(Okay|Dbase)/) {
      next;
    }
    elsif($state =~/Resync/){
      $exit = 1;
    }
    else {
      $exit = 2;
      $crit = $state;
    }
  }
}
if($exit == 0) {
    print "OK: All metadevices are Okay\n";
    exit 0;
  } 
  elsif($exit == 1) {
    print "WARNING: Metadevice is resyncing\n";
  exit 1;
  } 
  elsif($exit == 2) {
    chomp($crit);
    print "CRITICAL: $crit\n";
    exit 2;
}

