#! /usr/bin/ksh

#############################################################################
#       file-ident: md_check      V1.0                                      #
#       last modified: 2004/07/02                                           #
#                                                                           #
#       Copyright (c) 2004 OSL GmbH Germany                                 #
#       All rights reserved                                                 #
#                                                                           #
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,        #
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY          #
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO    #
# EVENT SHALL THE AUTHORS OR OSL BE LIABLE FOR ANY SPECIAL, INCIDENTAL      #
# INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER  #
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF    #
# THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT    #
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.         #
#                                                                           #
# This software including the copyright notice, the disclaimer and the      #
# following notice must not be modified. The mentioned ownership,           #
# protection and legal notices are an integral part of the software and     #
# must not be modified or removed. They are covered by applicable law       #
# (including but not limited to copyright, trademark and trade secret law)  #
# and must be strictly observed.                                            # 
#                                                                           #
# This software or its use shall not be: sold, rented, leased, traded or    #
# otherwise marketed without express written permission by OSL.             #
#                                                                           #
# Permission is hereby granted to use unmodified copies of this software    #
# for internal purposes as long as the conditions above are met.            #
# Except these copies for internal use the software must not be copied,     #
# modified, reproduced, redistributed, marketed or used otherwise.          #
#                                                                           #
# All rights not explicitly covered by this notice are reserved.            #
#                                                                           #
#############################################################################


LANG=C
LC_MONETARY=C
LC_TIME=C
LC_MESSAGES=C
LC_CTYPE=C
LC_COLLATE=C
LC_NUMERIC=C
alias awk="/usr/bin/nawk"

MDSET=""
if [ "$1" = "-s" ]
  then
  MDSET=$2
  if [ -z "$MDSET" ]
    then
    echo "ERROR: option -s requires a diskset to be specified" 1>&2
    exit 1
  fi
fi

if [ -z "$MDSET" ]
  then
  IS_ERR=`/usr/sbin/metastat |\
          awk '$1 == "State:" && $2 != "Okay" {print $1, $2;}'`
else
  IS_ERR=`/usr/sbin/metastat -s $MDSET |\
          awk '$1 == "State:" && $2 != "Okay" {print $1, $2;}'`
fi

if [ -n "$IS_ERR" ]
  then
  if [ -z "$MDSET" ]
    then
    LOGMSG=`echo "WARNING (md_check): There are problems with local md configuration!"` 
  else
    LOGMSG=`echo "WARNING (md_check): There are problems with md diskset $MDSET !"`
  fi
  logger -p daemon.notice "$LOGMSG"
fi

exit 0
