#!/bin/sh
#
# dmp: Sun Enterprise Server check - BB external script test
#
# version 1.1 - now accounts for Volume Logix
# version 1.2 - properly uses $THIS_HOST instead of `uname -n` 
#                 - thanks Craig Cook
# version 1.3 - properly uses the format command - the options were wrong order
# version 1.4 - updated the grep -v syntax to accomodate users who use "-" 
#                 in the disk or group name
# version 1.5 - updated for use with SRDF - moved DEVLIST to bbsys.local
# version 1.6 - updated for use with SRDF - moved DEVLIST to bbsys.local and 
#                 fixed VX_DISK_LIST
# version 1.7 - updated for power path, or non Veritas DMP nodes - phase 1
#
# BIG BROTHER / XXXXXXXXXXXXXXXX status
#
# Written by Paul A. Luzzi
#  on March 22, 2000
#

#####
#####  ********************************************************
#####    MUST UPDATE THE VOLUME LOGIX DEVICE IF USING VCM !!!
#####  ********************************************************
#####

########################################
# NOTE
# This has been tested with BB 1.2b
# 
# Tested on :
#   Sun Ultra 60, E220R/420R, E250/450, E3000/3500, E4500
########################################

########################################
# INSTALLATION
#  step 1  - update the EXT section of the runbb.sh script to include this
#  ...
########################################

##################################
# CONFIGURE IT HERE
##################################

##################################
# Start of script
##################################

if test ! "$BBHOME"
then
	echo "template: BBHOME is not set"
	exit 1
fi

if test ! -d "$BBHOME"
then
	echo "template: BBHOME is invalid"
	exit 1
fi

if test ! "$BBTMP"                      # GET DEFINITIONS IF NEEDED
then
	echo "template: The BB environment is not set"
	exit 1
fi

#####
#####  Start of custom section added by Paul A. Luzzi
#####

#####
#####  Get Status proc - used to get all responses
#####
get_status() 
{

  #####
  #####  Setup any and all variables before beginning.
  #####

  #####
  #####  Setup some variables for use later
  #####
  COLOR="green"
  
  #####
  #####  Format report
  #####
  echo "<P><DIV ALIGN=\"CENTER\"><HR>" 
  echo "<B>============== Format Alternate Pathing Info ==============</B>"
  echo "<B>--- (format) ---</B>"
  echo "<HR></DIV>" 
  echo "<BLOCKQUOTE>" 
  #####
  #####  Set the DMP_DEV_LIST param to null in bbsys.local if not using VCM
  #####
  CATCH_COMMAND=` echo "



" | $FORMAT -l /tmp/$THIS_HOST.dmp.log $VX_DISK_LIST `
  CATCH_COMMAND2=` $GREP "drive type unknown" /tmp/$THIS_HOST.dmp.log `
  if [ ! -z "$CATCH_COMMAND2" ]
    then
      COLOR="red"
      echo "Format command reports problem with alternate paths !!!"
      echo "$CATCH_COMMAND2"
     else
      echo "Format command reports alternate paths to be ok."
    fi
  echo "</BLOCKQUOTE>" 

  #####
  #####  Format report
  #####
  MP_TYPE=`/usr/sbin/modinfo | $EGREP "vxdmp|emcpower" | $AWK '{print $6}' `
  case "$MP_TYPE" in
    vxdmp ) 
            echo "<P><DIV ALIGN=\"CENTER\"><HR>" 
            echo "<B>============== Veritas Alternate Pathing Info ==============</B>"
            echo "<B>--- (vxdisk list .... | grep active ) ---</B>"
            echo "<HR></DIV>" 
            echo "<BLOCKQUOTE>" 
           
            echo "<TABLE border=1>"
            echo "<TR><B><I>"
            echo "<TD>Disk Name</TD>"
            echo "<TD>Configured<BR>Path Count</TD>"
            echo "<TD>Active<BR>Path Count</TD>"
            echo "<TD>Active/Enabled Paths</TD>"
            echo "</B></I></TR>"
            
            ## DISK_LIST=` $VXDISK list | $AWK '{print $3}' | $UNIQ | $GREP -v "^-" | $GREP -v DISK `
            DISK_LIST=` $VXDISK list | $AWK '{print $3,$1}' | $UNIQ | $GREP -v "^-" | $GREP -v DISK | $AWK '{print $2}' `
            for VX_DISK in $DISK_LIST
            do
              #####
              #####  Lets capture the output and work on it, rather than having to
              #####    run the command more than once.
              #####
              NUMPATHS=` $VXDISK list $VX_DISK | $GREP numpath | $AWK '{print $2}' `
              ACTIVE_PATH_COUNT=` $VXDISK list $VX_DISK | $EGREP -c "active|state=enabled" `
              ACTIVE_PATHS=` $VXDISK list $VX_DISK | $EGREP "active|state=enabled" | $AWK '{print $1}' `
          
              echo "<TR>"
              echo "<TD> $VX_DISK </TD>"
              echo "<TD> $NUMPATHS </TD>"
              echo "<TD> $ACTIVE_PATH_COUNT </TD>"
              echo "<TD> $ACTIVE_PATHS </TD>"
              echo "</TR>"
          
              #####
              #####  Now see if the number of paths, matches the active number.
              #####
              if [ ! "$ACTIVE_PATH_COUNT" = "$NUMPATHS" ]
                then
                  COLOR="red"
                  echo "There is a failed path for $VX_DISK."
                fi
            done
            echo "</TABLE>"
            echo "</BLOCKQUOTE>" 

            echo "<BLOCKQUOTE>" 
            if [ ! "$COLOR" = "green" ]
              then
                echo "Veritas/Format commands report problems with alternate paths !!!"
               else
                echo "<P>Veritas reports alternate paths to be ok."
              fi
            echo "</BLOCKQUOTE>" 
            ;;

    emcpower ) 
            echo "<P><DIV ALIGN=\"CENTER\"><HR>" 
            echo "<B>============== EMC PowerPath Alternate Pathing Info ==============</B>"
            echo "<B>--- (dont know yet | grep someting ) ---</B>"
            echo "<HR></DIV>" 
            echo "<BLOCKQUOTE>" 
            echo "EMC PowerPath is used on $THIS_HOST and not Veritas DMP."
            echo "We dont know how to check on $THIS_HOST for multi pathing status at this time."
            echo "</BLOCKQUOTE>" 
            ;;

    * ) 
            echo "<P><DIV ALIGN=\"CENTER\"><HR>" 
            echo "<B>============== Alternate Pathing Info ==============</B>"
            echo "<HR></DIV>" 
            echo "<BLOCKQUOTE>" 
            echo "No software implemented for multipathing on $THIS_HOST."
            echo "I guess it would be more appropriate to say we dont know how to check on $THIS_HOST actually."
            echo "</BLOCKQUOTE>" 
            ;;
  esac

  #####
  #####  Make sure to export COLOR so that it gets back to "central"
  #####
  export COLOR

#####
#####  End of get_status proc
#####
}

#####
#####  Main body
#####
touch /tmp/$THIS_HOST.dmp
$GREP $THIS_HOST $BBHOSTS | $GREP "dmp" | 
while read line
  do
    if [ ! -z "$line" ]
      then
        echo "<BR><DIV ALIGN=\"CENTER\"><HR></DIV>" > /tmp/$THIS_HOST.dmp
        echo "Status of alternate paths on $THIS_HOST " >> /tmp/$THIS_HOST.dmp
        echo "Captured : `$DATE` " >> /tmp/$THIS_HOST.dmp
        get_status >> /tmp/$THIS_HOST.dmp
        $BB $BBDISP "status $THIS_HOST.dmp $COLOR `$DATE` `cat /tmp/$THIS_HOST.dmp` "
      else
        COLOR="clear"
        $BB $BBDISP "status $THIS_HOST.dmp $COLOR `$DATE` `cat /tmp/$THIS_HOST.dmp` "
      fi
    done

#####
#####  End of custom section added by Paul A. Luzzi
#####
  
##############################################
# end of script
##############################################
