#!/bin/sh
#
# @(!--#) @(#) raidarrayreport.sh, version 001, 28-march-2001
#
# display a report ona specific RAID array (HP AutoRAID)
#

#
# Constants
#

REPORTLENGTHTHRESHOLD=50

#
# Main
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/hparray/bin
export PATH

progname=`basename $0`

. /etc/rc.config.d/unixsa

if [ "$UNIXSA" = "" ]
then
  echo "$progname: UNIXSA not set in /etc/rc.config.d/unixsa" 1>&2
  exit 2
fi

if [ $# -eq 0 ]
then
  echo "$progname: usage: progname array_serial_number" 1>&2
  exit 2
fi

SERIALNUMBER=$1

HPARRAYDIR=$UNIXSA/var/hparray

if [ ! -d $HPARRAYDIR ]
then
  echo "$progname: cannot find directory \"$HPARRAYDIR\"" 1>&2
  exit 2
fi

DAY=`date '+%a' | tr 'A-Z' 'a-z'`

ARRAYREPORT=$HPARRAYDIR/hparrayreport.$DAY

logprint -a $SERIALNUMBER                                 | \
  grep -v "^Usage record for Subsystem $SERIALNUMBER at " | \
  grep -v "^Log File: /var/opt/hparray/log/L"             | \
  grep -v "^$"                                            >$ARRAYREPORT

REPORTLENGTH=`cat $ARRAYREPORT | wc -l | awk '{ print $1 }'`

(
  grep -i error $ARRAYREPORT >/dev/null

  if [ $? -ne 1 ]
  then
    echo "ATTENTION!!!   ATTENTION!!!   ATTENTION!!!"
    echo
    echo "This report appears to indicate some sort of error."
    echo "Please examine very throughly."
    echo
    echo "ATTENTION!!!   ATTENTION!!!   ATTENTION!!!"
    echo
  fi

  if [ $REPORTLENGTH -gt $REPORTLENGTHTHRESHOLD ]
  then
    echo "INFORMATION:"
    echo
    echo "The length of this report now exceeds $REPORTLENGTHTHRESHOLD lines."
    echo "You should consider clearing down the ARRAY logs."
    echo
  fi

  cat $ARRAYREPORT

  echo
  echo "Regards,"
  echo
  echo "The $progname script."
) | mailx -s "HP AutoRAID report from \"`uname -n`\" for unit $SERIALNUMBER" root

exit 0


