#!/bin/sh
#
# (Script Specific Information)
#
#	Script Name..........$OAROOT/metacheck
#
#	Current Revision.....v2
#
#	Author...............David.Dixon@uk
#
#	Purpose..............Check mirroring status
#
#	OS Requirements......Solaris 2.x
#
#	Date Written.........15/8/1996
#
#	Run Time Environment  Bourne
#
#	Authors Notes........None
#
# (Updates)
#
# 	   Date	   Reason		   	    		Author
#
#	  27/1/97  Now checks state of Meta Databases		David Dixon
#	  25/4/97  Now check for configuration changes		David Dixon
#	  02/6/97  Source one common params file
#		   Re-arrange mail header			Rob Kolb
#	  17/12/97 Re-write for PrimeAlert			Nate Gardner
#	  04/03/99 Re-write for SyMON			Nate Gardner
#	  05/23/01 location of metastat is different in Solaris 8 Carsten Lorbeer
#		   	
#
# (Run Time Information)
#
#	Parameters...........None
#
#	Parameters File......None
#
#	Exit Code Levels.....0	Succes, no problem found
#			     10 Error(s) MetaDevice(s)
#			     11 Error(s) StateDbase(s)
#			     12 Changed DiskSuite configuration
#			     14 DiskSuite not installed
#
#	Dependencies.........ODS installed
#
#	Full Details.........http://{URL path}
#
# (Additional Script Calls)
#	
#	Script Name..........None
#
#	Call Purpose.........N/A
#
# Changed 11 Aug 1997 Rob Kolb
#       Added exit codes for AS/LH
#
#
# Set initial exit-code to "0" zero. Depended on the script-flow, this value may 
# At the end this value is put into the exit-code.
code="0"

#
# Set most variables form one common file
# Set most variables from script - npg
#
HOME=/var/opt/SUNWsymon/log
APPL=meta
PkgInstallLog=/var/sadm/install/contents
METASTAT=/usr/opt/SUNWmd/sbin/metastat
METADB=/usr/opt/SUNWmd/sbin/metadb

export HOME APPL


LOGFILE="/tmp/metacheck_log$$"
METAPLOG="$HOME/metastat_p.save"
METAPNEW="$HOME/metastat_p.new"

> $METAPNEW

#
# verify if DiskSuite is installed
#
META_VRF="`/bin/pkginfo|/usr/bin/grep SUNWmd`"
if [ "$META_VRF" = "" ]
then
	/usr/bin/echo "Disksuite Usage ** DiskSuite not installed" 
	exit 14
fi
# Determine path to metastat command

if [ ! -x "$METASTAT" ] ; then
        METASTAT=`/usr/bin/grep "metastat f" $PkgInstallLog|awk '{print $1}'`
fi

if [ "$METASTAT" = "" ]
then
        /usr/bin/echo "Disksuite Usage ** DiskSuite not installed"
        exit 14
fi

# Check for anything other than okay status

META_CMD="`$METASTAT | /usr/bin/grep "State:" | /usr/bin/grep -v "Okay"`"

if [ "$META_CMD" != "" ]  
then
	code=`expr $code + 10`
	/usr/bin/echo "Disksuite ERROR - Disk Mirroring has an error. Please investigate further." 

fi

# Determine path to metadb command

if [ ! -x "$METADB" ] ; then
        METADB=`/usr/bin/grep "metadb f" $PkgInstallLog|awk '{print $1}'`
fi

if [ "$METADB" = "" ]
then
        /usr/bin/echo "Disksuite Usage ** DiskSuite not installed"
        exit 14
fi

# Check status of Meta State Databases


META_DB="`$METADB | /usr/bin/grep '[DFMRSW]'`"

if [ "$META_DB" != "" ]
then
	code=`expr $code + 11`
	/usr/bin/echo "DiskSuite ERROR - Problem with Meta State Databases. Please investigate further."
fi

# Check for configuration changes. These could be possible problems.


if [ ! -f "$METAPLOG" ]
then 
	$METASTAT -p > $METAPLOG
fi
$METASTAT -p >> $METAPNEW
diff $METAPLOG $METAPNEW > /dev/null
if [ $? -eq 0 ]
then
	/usr/bin/echo "All is ok" > /dev/null
else
	code=`expr $code + 12`
	/usr/bin/echo "DiskSuite WARNING - The ODS configuration has changed. Please investigate further."
fi

/usr/bin/rm -f $METAPNEW

if [ "$code" -eq 0 ]
then
	/usr/bin/echo "DiskSuite is ok"
fi

exit 0


