Cover V12, I08

Article
Listing 1

aug2003.tar

Listing 1 The Volume Manager monitoring script

#!/bin/ksh 

## 
## This script checks that the disks in Disksite/Volume Manager 
## are all okay and that all devices that are supposed to be 
## mirrored are mirrored. 
## 
## Author: Andrew Kyle 
## 

# 
# Firstly see if metastat is installed 
# and where it can be found. 
# 2.6, 7 Installs in /usr/opt/SUNWmd/sbin/metastat 
# 8 up, Installs in /usr/sbin/metastat 
# 
METASTAT="" 
if [ -x /usr/opt/SUNWmd/sbin/metastat ] 
then 
   METASTAT=/usr/opt/SUNWmd/sbin/metastat 
   METADB=/usr/opt/SUNWmd/sbin/metadb 
else 
   if [ -x /usr/sbin/metastat ] 
   then 
      METASTAT=/usr/sbin/metastat 
      METADB=/usr/sbin/metadb 
   fi 
fi 


# 
# If metastat can be found then see if there are 
# metadbs configured. 
# 
if [ "$METASTAT" != "" ] 
then 
   METASTAT_DATA=`$METASTAT 2>&1` 
   #echo I think this server has meta disks to check.... 
   #check to see if it has been configured with any metadbs 
   if [ "`echo "$METASTAT_DATA" | grep 'there are no existing databases'`" = "" ] 
   then 
      # 
      # Check the state of all metadevices 
      # 
      STATES=`echo "$METASTAT_DATA"| \ 
              awk '{if($1~/^d/){metadevice=$1}} 
                   {if($1~/State/&&$NF!~/Okay/) 
                      {print metadevice" "$NF}}'` 
      if [ "$STATES" != "" ] 
      then 
          echo 
          echo "The following metadevices are not \"Okay\"" 
          echo "$STATES" 
          echo "Run \"$METASTAT\" to check." 
          echo 
      fi 
    
      # 
      # Now check all disks are mirrored 
      # 
      echo "$METASTAT_DATA"|awk -F: 'BEGIN{count=0}{ 
         if ($0~/Mirror/){ 
            {FLAG="TRUE"}metadisk=$1} 
         if (FLAG=="TRUE" && $0~/Submirror/) 
            {count=count+1} 
         if ($0~/Pass/){ 
            {if (count<2){ 
               print "Metadisk "metadisk" is not mirrored!"}} 
            {FLAG="FALSE"}{count=0}} 
      }' 

      # 
      # Check all Hot spares are "Available" 
      # 
      HSP_STATES=`echo "$METASTAT_DATA"| \ 
                  awk '{if(NF==5&&$NF=="blocks") 
                          {print $1"\t"$2" "$3}} 
                       {if(NF==4&&$NF=="blocks"&&$2!="Available") 
                          {print $1"\t"$2}}'| \ 
                  sort -u` 
      if [ "$HSP_STATES" != "" ] 
      then 
         echo 
         echo "The following hot spares are in a state other then \"Available\":"
         echo "$HSP_STATES" 
         echo "Run \"$METASTAT\" to check." 
         echo 
      fi 
   fi 

   # 
   #Check the metadbs are ok 
   # 
   METADB_FLAGS=`$METADB|tail +2|awk '{if($1!="a"){print $0}}'` 
   if [ "$METADB_FLAGS" != "" ] 
   then 
      echo 
      echo "There is a problem with the metadbs:" 
      echo "$METADB_FLAGS" 
      echo 
      echo "Run \"$METADB\" to check." 
      echo 
   fi 
fi