#!/bin/bash
#
# $Id$
#
# checks if omreport output says that all DISKS_IN_RAID hardware RAID disks seem OK.
#

# prepare

. /usr/lib/montools/mt-prepare

RESNAME="HW-RAID (OMSA)"


# work

PATH="/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

export FOUNDHDS=$(omreport storage pdisk controller=0 |egrep "^Status" |grep -n Status |wc -l)
# the grep -n is not redundand, it "prefixes" the disc number to each status line

if [ "$FOUNDHDS" != "$DISKS_IN_RAID" ] ; then
  #logDebug "Disk missing (found $FOUNDHDS of $DISKS_IN_RAID)."
  add2criticals "Disk missing (found $FOUNDHDS of $DISKS_IN_RAID)."
else
  add2infos "Found all $DISKS_IN_RAID disks."
fi

RAIDFAILS=$(omreport storage pdisk controller=0 |egrep "^Status" |grep -n Status |egrep -v "Ok|Non-Critical")
#RAIDFAILS=$(omreport storage pdisk controller=0 |egrep "^Status" |grep -n Status |egrep -v "Ok")
if [ ! -z "$RAIDFAILS" ] ; then
  #logDebug "HW-RAID has problems: $ERRORLIST"
  add2criticals \
    "HW-RAID reports disk failures:" \
    "$RAIDFAILS"
else
  # avoid OK message if we failed to find all discs before
  if [ "$FOUNDHDS" = "$DISKS_IN_RAID" ] ; then
    add2infos "HW-RAID seems OK."
  fi
fi


# notifications

. /usr/lib/montools/mt-notify-exit

