#!/bin/sh 
#  
# BIG BROTHER - Monitor the RAID status
#
# Author: Daniel Gomez (dgomez@tigr.org,daniel@ixplosive.com), 
# 	  Richard Deal (rdeal@tigr.org)
#
# Notes:
# This extension is intended to provide a framwork for a comprehensive RAID 
# reporting tool. Currently the RAID technologies covered include:
#  - Dell Megaraid hardware SCSI raid controller through the MEGARC PERC/CERC
#    Configuration Utility by LSI
#  - Linux Software RAID (raidtools implimentation)
#  - Fusion-MPT LSI 1030 RAID-1 Controller 
#  - AACRAID PERC3/Di - dual RAID channels, U160 SCSI
#
# Our linux environment mainly consists of Suse 2.6 kernel machines
#
# AACRAID -------------------------------------------------------------------
# Dell has many utils at http://linux.dell.com/raid.shtml#aacraid . The tool
# we will use is the 'afacli' which comes in tar or RPM. I used the RPM for
# easy setup. At the time of this writup, I downloaded afa-linux-app-A01.tar.gz
# which contained the target RPM to install:
#    > rpm -qilp afaapps-2.7-1.i386.rpm
#    Name        : afaapps                  Relocations: (not relocatable)
#    Version     : 2.7                      Vendor: Adaptec, Inc.
#    Release     : 1                        Build Date: Fri May  3 08:52:06 2002
#    Install date: (not installed)   Build Host: ntc-buildlinux2.ntc.adaptec.com
#    Group       : Utilities/System         Source RPM: afaapps-2.7-1.src.rpm
#    Size        : 1245640                  License: 2000 - 2002, Adaptec Inc.
#    Signature   : (none)
#    Packager    : Nashua Technology Center, Adaptec, Inc.
#    Summary     : DELL PowerEdge Raid Controller 2 (apps)
#    Description :
#    The afacli application consists of a command line interface (CLI)
#    that lets you perform storage management tasks related to
#    managing controllers, disks, containers, and enclosure devices
#    by providing a variety of commands.
#    Distribution: (none)
#    /dev/MAKEDEV.afa
#    /usr/sbin/afacli
#    /usr/sbin/getcfg.afa
#
# Fusion-MPT ----------------------------------------------------------------  
#    The LSI 1030 RAID Controller can be monitored by the mpt-status program
# found at http://www.drugphish.ch/~ratz/mpt-status . It doesn't provide much
# but something to throw up on a BB page is better than nothing.
#
# MEGARC --------------------------------------------------------------------  
#    The target operating systems were Red Hat 7.3 and Suse 9.1. There are 
# several packages that one can use from 3rd-party sources and from
# Dell to assist in reporting the status of the Megaraid hardware, including
# a pre-existing BB extension called "bb-megaserv.sh". That package has it's 
# advantages, but the advantage leveraged in this extenstion is simplicity.
# 
# Instead of installing a running daemon, kernel modules or setting SNMP traps,
# the 'megarc' command is simply executed and its output analyzed. The megarc
# program is found by searching at http://support.dell.com for "megaraid-util".
# At the present time, there were only three found:
#  - megaraid-util-rh8.0-i386.tar.gz (This script is based on this package).
#  - megaraid-util-rh7.3-i386.tar.gz 
#  - megaraid-util-rh7.1.tar.gz 
#
# Here are the specs on the program within the provided tarball:
# > rpm -qilp megarc-1.07-1.i386.rpm
# Name        : megarc                     Relocations: (not relocatable)
# Version     : 1.07                            Vendor: LSI Logic Corporation
# Release     : 1                           Build Date: Wed Nov 13 15:40:23 2002
# Install date: (not installed)             Build Host: localhost.localdomain
# Group       : RAID                        Source RPM: megarc-1.07-1.src.rpm
# Size        : 641102                         License: LSI Logic
# Signature   : (none)
# URL         : http://www.lsil.com
# Summary     : megarc for Dell PowerEdge RAID Controllers configuration utility
# Description :
# Dell PowerEdge RAID controller configuration utility for Red Hat Linux 8.0.
# This tool supports PERC4/Di, PERC 2/SC, PERC 2/DC, PERC 3/DC, PERC 3/DCL, 
# and PERC 3/QC. megaraid driver must be loaded in order to run this tool.
# Distribution: (none)
# /usr/sbin/megarc
# /usr/sbin/megarc.bin
# 
#        **********************************************************************
#              MEGARC PERC/CERC Configuration Utility(LINUX)-1.07(08-19-02)
#              By LSI Logic Corp.,USA
#        **********************************************************************
#
# SOFTWARE -------------------------------------------------------------------  
# 
#
# This script is released under the Gnu Public License
# http://www.gnu.org/copyleft/gpl.html
#
# History: 
#    - Version 1.2b: Added Missing Yellow Warning for Megaraid
#    - Version 1.2a: Added Rebuild Yellow Warning for Megaraid
#    - Version 1.2 : Added AACRAID Support
#    - Version 1.1a: Added Resync Yellow Warning for Fusion-MPT checks 
#    - Version 1.1 : Added Fusion-MPT support
#    - Version 1.0 : Initial version
###############################################################################

##### VARIABLES ###############################################################

# BBHOME CAN BE SET MANUALLY WHEN TESTING.
# OTHERWISE IT SHOULD BE SET FROM THE BB ENVIRONMENT
#BBHOME="/var/BB/bb"; export BBHOME   # FOR TESTING

# BBPROG SHOULD JUST CONTAIN THE NAME OF THIS FILE
# USEFUL WHEN YOU GET ENVIRONMENT DUMPS TO LOCATE THE OFFENDING SCRIPT...
BBPROG=bb-linux-raid.sh; export BBPROG 

# TEST NAME: THIS WILL BECOME A COLUMN ON THE DISPLAY. IT SHOULD BE AS SHORT 
# AS POSSIBLE TO SAVE SPACE. YOU CAN ALSO CREATE A HELP FILE FOR YOUR TEST 
# WHICH SHOULD BE PUT IN www/help/$TEST.html. 
# IT WILL BE LINKED INTO THE DISPLAY AUTOMATICALLY.
TEST="raid"

# There didn't seem to be real need to use the wrapper script provided by Dell
# which recreates the cevice so we call the binary directly
#MEGARC="/usr/sbin/megarc.bin"
MEGARC="/usr/sbin/megarc"

# Used for software raid analysis. Will need to sticky bit if not run as root.
LSRAID="/sbin/lsraid"

# Used for MPTRaid1(). Sudoized
MPTSTATUS="/usr/local/sbin/mpt-status"

# Used for AACRaid(). Sudoized.
AFACLI="/usr/sbin/afacli"

SUDO="/usr/bin/sudo"

MEGACLI="/usr/sbin/MegaCli64"


# Defaults
COLOR="green"
STATUS="OPTIMAL"

##### FUNCTIONS ###############################################################

AACRaid()
{
# Record the launching of this Routine
ROUTINES="$ROUTINES AACRaid"

# Gather Data
CMD_AFACLI="$SUDO $AFACLI"        # command
OUT_AFACLI=`$CMD_AFACLI -h | grep -c afacli`	# permssions check

# Gotta have a scratch space dump out the internally built commands 
if [ -n "$BBTMP" ] && [ -w "$BBTMP" ]; then

   cd $BBTMP

   # Build Step 1 - Identify Controllers
   echo "logfile start afacli.step1.output" > afacli.step1
   echo "controller list" >> afacli.step1
   echo " logfile end" >> afacli.step1
   echo "exit" >> afacli.step1

   # Run Step 1 - Identify Controllers
   $CMD_AFACLI < $BBTMP/afacli.step1
   
   # Add Controller List to the Report
   AACRAID_MSG="<FONT SIZE=+2><b>Controller Lists</b></FONT><p>`awk '/PERC/{print $1}' afacli.step1.output`<p>"

   # Loop through all identified controllers 
   #for controller in `awk '/PERC/{print $1}'afacli.step1.output`; do
   for controller in `cat afacli.step1.output | grep PERC | awk '{print $1}'`; do

        # Build Step 2 - query a controller
	echo "open /readonly=true $controller" > afacli.step2
	echo "logfile start afacli.step2.output" >> afacli.step2
	echo "container list" >> afacli.step2
	echo "disk list" >> afacli.step2
	echo "disk show partition" >> afacli.step2
	echo "disk show smart" >> afacli.step2
	echo "controller details" >> afacli.step2
	echo " logfile end" >> afacli.step2
	echo "exit" >> afacli.step2

	# Run Step 2 - query a controller
	$CMD_AFACLI < $BBTMP/afacli.step2
	AFACLI_OUT2=`cat afacli.step2.output | egrep -v ^'AFA|COMMAND|File' | grep -v 'logfile'`
        CHECK_BATTERY="`cat afacli.step2.output | grep 'Battery State'`"

	# Add controller queries to the Report
        AACRAID_MSG="$AACRAID_MSG<br><FONT SIZE=+2><b>Raid Stats</b></FONT><p> $AFACLI_OUT2"

	# Build Step 3 - list all disks for this controller
	echo "open /readonly=true $controller" > afacli.step3
	echo "logfile start afacli.step3.output" >> afacli.step3
	echo "disk list" >> afacli.step3
	echo " logfile end" >> afacli.step3
	echo "exit" >> afacli.step3
   
	# Run Step 3 - list all disks for this controller
	$CMD_AFACLI < $BBTMP/afacli.step3
	#AFACLI_OUT3=`cat afacli.step3.output | egrep -v ^'AFA|COMMAND|File' | grep -v 'logfile'`

       for disk in `cat afacli.step3.output|awk '/Disk/{print $1}'`;
       do
	   # Build Step 4 - query each set of controller disks for defects
	   echo "$disk" >> $AFACLI_STEP4_FILENAME.tmp.disks 
	   echo "open /readonly=true $controller" > afacli.step4 
	   echo "logfile start afacli.step4.output" >> afacli.step4 
	   echo "disk show defects ($disk)" >> afacli.step4 
	   echo " logfile end" >> afacli.step4 
	   echo "exit" >> afacli.step4 

	   # Run Step 4 - query each set of controller disks for defects
	   $CMD_AFACLI < $BBTMP/afacli.step4 
	   AFACLI_OUT4="$AFACLI_OUT4 `cat afacli.step4.output | egrep -v ^'AFA|COMMAND|logfile|File'`"


	done
   done
   # Add controller queries to the Report
   AACRAID_MSG="$AACRAID_MSG <br><br><p><FONT SIZE=+2><b>Show Disk Defects</b></FONT><p> $AFACLI_OUT4"

fi
# End Gathering Data

# Analyze
# I haven't had the chance to fully explore all the possible messages,
# and so the analysis is sorely lackiing, but it is my understanding 
# that '!' signifies trouble so we search for that and report it - for now.
# One the messages are more fully understood LED blinking will be added to
# inidicate the alerted disk. Example, AFA0> disk blink (0:03:0) 30

CHECK1=`echo $AFACLI_OUT2 | grep '!' | wc -l`
CHECK2=`echo $CHECK_BATTERY | sed -e 's/Battery State: Ok//g'`
BCHECK2=`echo $CHECK_BATTERY | sed -e 's/Battery State: Not Present//g'`

CHECK4=`echo $AFACLI_OUT4 | awk '/GROWN/{gsub(/[^[:digit:]]/,""); print}' | grep -v ^0 | wc -l`

# Judge
MSG=""
if [ "$OUT_AFACLI" -eq 0 ]; then 
   STATUS="UNKNOWN"
   COLOR=yellow
   MSG="&$COLOR AACRaid Message:  Check if permissions on $AFACLI. May need to sticky bit or sudoize. <p>"
elif [ -z "$BBTMP" ]; then
   STATUS="UNKNOWN"
   COLOR=yellow
   MSG="&$COLOR AACRaid Message:  Must define BBTMP or some other scratch space. <p>"
elif [ "$CHECK1" -ne 0 ]; then
   STATUS="ERROR"
   COLOR=red
   MSG="&$COLOR AACRaid Message:  Something is wrong! <p>"
elif [ -n "$CHECK2" ]; then
   if [ -n "$BCHECK2" ]; then
     STATUS="WARNING"
     COLOR=yellow
     MSG="&$COLOR AACRaid Message: $CHECK_BATTERY<p>"
   fi
elif [ "$CHECK4" -ne 0 ]; then
   STATUS="OPTIMAL"
   COLOR=yellow
   MSG="&$COLOR AACRaid Message:  Disk Defects are Growing. <p>"
else
   STATUS="OPTIMAL"
   MSG="&green AACRaid Message: Relax. Things look good. <p>"
fi

# Send Report
GLOBAL_MSG="$GLOBAL_MSG $MSG"
AACRAID_MSG="$AACRAID_MSG"
}

MPTRaid1()
{
# Record the launching of this Routine
ROUTINES="$ROUTINES MPTRaid1"

# Gather Date
CMD_MPT="/usr/local/bin/sudo $MPTSTATUS"	# mpt-status command
OUT_MPT=`$CMD_MPT`				# mpt-status permssions check

CHECK1=`$CMD_MPT | grep -c 'state OPTIMAL'`
CHECK2=`$CMD_MPT | grep -c 'state ONLINE'`
CHECK3=`$CMD_MPT | grep 'state DEGRADED' | grep -c 'RESYNC_IN_PROGRESS'`

# Analyze 
MSG=""
if [ -z "$OUT_MPT" ]; then 
   STATUS="UNKNOWN"
   COLOR=yellow
   MSG="&$COLOR MPTRaid1 Message:  Check if permissions on $MPTSTATUS. May need to sticky bit or sudoize. <p>"
elif [ $CHECK1 -lt 1 ] && [ $CHECK3 -eq 1 ]; then
      STATUS="DEGRADED"
      COLOR=yellow 
      MSG="&$COLOR MPTRaid1 Message: RESYNCING <p>"
elif [ $CHECK1 -lt 1 ]; then
   STATUS="DEGRADED"
   COLOR=red 
   MSG="&$COLOR MPTRaid1 Message: Not OPTIMAL. <p>"
elif [ $CHECK2 -ne 2 ]; then
   STATUS="OFFLINE"
   COLOR=red 
   MSG="&$COLOR MPTRaid1 Message:  Failed 'online' check. <p>"
else
   STATUS="OPTIMAL"
   MSG="&green MPTRaid1 Message: Relax. Things look good. <p>"
fi

# Report
GLOBAL_MSG="$GLOBAL_MSG $MSG"
MPTRAID1_MSG="
<FONT SIZE=+2><b>Mirror Status</b></FONT> ($CMD_MPT) <p>
$OUT_MPT
<p>
"
}

SoftwareRaid()
{
# Record the launching of this Routine
ROUTINES="$ROUTINES SoftwareRaid"

# Gather Data 
CMD_MD="cat /proc/mdstat"	# Kernel Meta-Disk status 
CMD_AP="$LSRAID -A -p"		# Array-based. Listing of all md devices 
CMD_DP="$LSRAID -D -p"		# Disk-based. Description of all member disks
OUT_MD=`$CMD_MD`
OUT_AP=`$CMD_AP`
OUT_DP=`$CMD_DP`

# Analyze
CHECK1=`cat /proc/mdstat | awk '/block/{gsub(/[\[\]]/,""); print $NF}' | grep -c -v 'U'`
CHECK2=`$LSRAID -A -p | awk '/[::alphanum::]/{ print $NF}' | grep -c -v 'online\|spare\|good'`

MSG=""
if [ $CHECK1 -ne 0 ]; then
   STATUS="DEGRADED"
   COLOR=red 
   MSG="&$COLOR SoftwareRaid Message:  Failed all 'U' check. <p>"
elif [ -z "$OUT_AP" ]; then 
   STATUS="UNKNOWN"
   COLOR=yellow
   MSG="&$COLOR SoftwareRaid Message:  Check if permissions on $LSRAID. May need to sticky bit. <p>"
elif [ `echo $OUT_AP | grep -c 'online'` -ne `echo $OUT_AP | grep -c md` ]; then
   STATUS="OFFLINE"
   COLOR=red 
   MSG="&$COLOR SoftwareRaid Message:  Failed 'online' check. <p>"
elif  [ $CHECK2 -ne 0 ]; then
   STATUS="SUSPECT"
   COLOR=yellow 
   MSG="&$COLOR SoftwareRaid Message:  Check if all disks are ok. <p>"
elif [ $CHECK1 -eq 0 ]; then 
   STATUS="OPTIMAL"
   MSG="&green SoftwareRaid Message:  Relax. Things look good. <p>"
else
   STATUS="UNKNOWN"
   COLOR=yellow 
   MSG="&$COLOR SoftwareRaid Message:  Status cannot be analyzed. <p>"
fi

# Report
GLOBAL_MSG="$GLOBAL_MSG $MSG"
SOFTWARERAID_MSG="
<FONT SIZE=+2><b>Kernel Meta-Data Status</b></FONT> ($CMD_MD) <p>
$OUT_MD
<p>

<FONT SIZE=+2><b>Array-based</b></FONT> ($CMD_AP) <p>
$OUT_AP
<p>

<FONT SIZE=+2><b>Disk-based</b></FONT> ($CMD_DP) <p>
$OUT_DP
<p>
"
}

Megaraid()
{

# Record the launching of this Routine
ROUTINES="$ROUTINES Megaraid"

# Gather Data 
CMD_AAI="$MEGARC -AllAdpInfo -nolog"  		  # Adapter Card/Firmware Type
CMD_DI="$MEGARC -ldInfo -a0 -Lall -nolog"    	  # Device Status
CMD_FI="$MEGARC -pdFailInfo -chAll -idAll -a0 -nolog" # Failure Information
CMD_FSI="$MEGARC -FreeSpaceInfo -a0 -nolog"       # Free Array Space Information
CMD_LPI="$MEGARC -LogPhysInfo -alladp -nolog"	  # Show Physical Drive Info
# These commands are not meant to be run through BB, but are useful for
# manual troubleshooting or other automations so here they are.
# $MEGARC -chkonLd -a0 -Lall  	# Check consistency (takes a VERY long time).
# $MEGARC -showRbld -a0 	# Show Rebuild State (progress)
# $MEGARC -getSpeed -chAll -idAll -a0 # Device Speed

OUT_AAI=`$SUDO $CMD_AAI | grep -v 'help\|\[A\|\*\|MEGARC\|By\|Scanning\|Finding' | \
        grep -v SATA | grep -v "specifying physical"`
#OUT_DI=`yes C | $CMD_DI | grep 'rive\|----\|Raid\|Strip\|Status\|0x'`
OUT_DI=`$SUDO $CMD_DI | grep -v 'help\|\[A\|\*\|MEGARC\|By\|Scanning\|Finding' | \
        grep -v SATA | grep -v "specifying physical"`
OUT_FI=`$SUDO $CMD_FI | grep -v 'help\|\[A\|\*\|MEGARC\|By\|Scanning\|Finding' | \
	grep '[::space::]' | grep -v SATA | grep -v "specifying physical"`
OUT_FSI=`$SUDO $CMD_FSI | grep [::space::] | \
	grep -v '\[A\|help\|\*\|MEGARC\|By\|Scanning\|Finding' | grep -v SATA | \ 
	grep -v "specifying physical"`
OUT_LPI=`$SUDO $CMD_LPI | grep -v 'help\|\[A\|\*\|MEGARC\|By\|Scanning\|Finding' | \
	grep -v SATA | grep -v "specifying physical" |  grep 'rive\|RAID'`

# Analyze
MSG=""
NUM=`echo $OUT_DI | grep -c 'Status:'`
if [ `echo $OUT_AAI | grep -c 'Error: No PERC Found'` -ne 0 ]; then 
   STATUS="UNKNOWN"
   COLOR=yellow 
   MSG="&yellow Megaraid Message:  No PERC found. Please remove $MEGARC RPM from this host. <p>"
elif [ `echo $OUT_DI | grep -c 'Failed\|Unable'` -ne 0 ]; then 
   STATUS="UNKNOWN"
   COLOR=yellow 
   MSG="&$COLOR Megaraid Message:  PERC found, but $MEGARC is failing. Check that /dev/megadev0 has 644 permissions. <p>"
elif [ `echo $OUT_DI | grep -c RBLD` != "0" ]; then 
   STATUS="REBUILDING"
   COLOR=yellow 
   MSG="&$COLOR Megaraid Message:  RAID is rebuilding ... <p>"
elif [ `echo $OUT_DI | grep -c OPTIMAL` -ne $NUM ]; then 
   STATUS="DEGRADED"
   COLOR=red 
   MSG="&$COLOR Megaraid Message:  Things are bad. <p>"
elif [ `echo $OUT_DI | grep -c OPTIMAL` -eq $NUM ] && [ $NUM -ne 0 ]; then 
   STATUS="OPTIMAL"
   MSG="&green Megaraid Message:  Relax. Things look good. <p>"
else
   STATUS="UNKNOWN"
   COLOR=yellow 
   MSG="&$COLOR Megaraid Message:  Status cannot be analyzed. <p>"
fi

# Report
GLOBAL_MSG="$GLOBAL_MSG $MSG"
MEGARAID_MSG="
<FONT SIZE=+2><b>Adapter Card/Firmware Type</b></FONT> ($CMD_AAI)
$OUT_AAI
<p>

<FONT SIZE=+2><b>Device Status</b></FONT> ($CMD_DI) <p>
$OUT_DI
<p>

<FONT SIZE=+2><b>Failure Info</b></FONT> ($CMD_FI) <p>
$OUT_FI
<p>

<FONT SIZE=+2><b>Show Physical Device Info</b></FONT> ($CMD_LPI) <p>
$OUT_LPI
<p>

<FONT SIZE=+2><b>Free Array Space Information</b></FONT> ($CMD_FSI) <p>
$OUT_FSI
<p>
"
}

MegaCli()
{

# Record the launching of this Routine
ROUTINES="$ROUTINES MegaCli"

# Gather Data
CMD_AAI="$MEGACLI -AdpAllInfo -aALL -NoLog"              # Adapter Card/Firmware Type
CMD_DI="$MEGACLI -LDInfo -Lall -aALL -NoLog"         # Device Status
CMD_LPI="$MEGACLI -PDList -aALL -NoLog"     # Show Physical Drive Info

OUT_AAI=`$SUDO $CMD_AAI`
OUT_DI=`$SUDO $CMD_DI`
OUT_LPI=`$SUDO $CMD_LPI`
DISPLAY_OUT_LPI=`echo "$OUT_LPI" | egrep '^Slot|Error|^Firmware'`
#OUT_AAI=`$SUDO $CMD_AAI | grep -v 'help\|\[A\|\*\|MEGARC\|By\|Scanning\|Finding' | \
#        grep -v SATA | grep -v "specifying physical"`
#OUT_DI=`$SUDO $CMD_DI | grep -v 'help\|\[A\|\*\|MEGARC\|By\|Scanning\|Finding' | \
#        grep -v SATA | grep -v "specifying physical"`
#OUT_LPI=`$SUDO $CMD_LPI | grep -v 'help\|\[A\|\*\|MEGARC\|By\|Scanning\|Finding' | \
#        grep -v SATA | grep -v "specifying physical" |  grep 'rive\|RAID'`

# Analyze
MSG=""
NUM=`echo "$OUT_DI" | grep -c 'State'`
if [ `echo $OUT_AAI | grep -c 'Error: No PERC Found'` -ne 0 ]; then
   STATUS="UNKNOWN"
   COLOR=yellow
   MSG="&yellow MegaCli Message:  No PERC found. Please remove $MEGACLI RPM from this host. <p>"
elif [ `echo $OUT_DI | grep -c 'Failed\|Unable'` -ne 0 ]; then
   STATUS="UNKNOWN"
   COLOR=yellow
   MSG="&$COLOR MegaCli Message:  PERC found, but $MEGACLI is failing. <p>"
elif [ `echo $OUT_DI | grep -c RBLD` != "0" ]; then
   STATUS="REBUILDING"
   COLOR=yellow
   MSG="&$COLOR MegaCli Message:  RAID is rebuilding ... <p>"
elif [ `echo "$OUT_DI" | grep -c Optimal` -ne $NUM ]; then
   STATUS="DEGRADED"
   COLOR=red
   MSG="&$COLOR MegaCli Message:  Things are bad. <p>"
elif [ `echo "$OUT_DI" | grep -c Optimal` -eq $NUM ] && [ $NUM -ne 0 ]; then
   STATUS="OPTIMAL"
   MSG="&green MegaCli Message:  Relax. Things look good. <p>"
else
   STATUS="UNKNOWN"
   COLOR=yellow
   MSG="&$COLOR MegaCli Message:  Status cannot be analyzed. <p>"
fi

# Report
GLOBAL_MSG="$GLOBAL_MSG $MSG"
MEGACLI_MSG="
<FONT SIZE=+2><b>Device Status</b></FONT> ($CMD_DI) <p>
$OUT_DI
<p>

<FONT SIZE=+2><b>Show Physical Device Info</b></FONT> ($CMD_LPI) <p>
$DISPLAY_OUT_LPI
<p>

<FONT SIZE=+2><b>Adapter Card/Firmware Type</b></FONT> ($CMD_AAI)
$OUT_AAI
<p>

"
}

##### MAIN ####################################################################

### Setup BB Environment and Definitions
if [ -z "$BBHOME" ]; then 
	echo "BBHOME is undefined!"; exit 1 
#else 
#	. $BBHOME/etc/bbdef.sh 
fi

### Analyze
ROUTINES=""
# The criteria to trigger these routines is subject. You may want to differ.
if [ -x "$MEGARC" ]; then Megaraid; fi
if [ -x "$MEGACLI" ]; then MegaCli; fi
#if [ "`cat /proc/mdstat | grep -c 'raid'`" -ne 0 ]; then SoftwareRaid; fi
#if [ "`cat /proc/scsi/scsi | grep -c 'PERCRAID'`" -gt 0 ]; then AACRaid; 
#elif [ "`cat /proc/scsi/scsi | grep -c 'DELL'`" -gt 0 ]; then AACRaid; 
#if [ "`cat /proc/mpt/version | grep -c 'MPT'`" -gt 0 ]; then MPTRaid1; fi

### Report
OUTPUT="
<center>
Routines launched ... $ROUTINES <br>
$GLOBAL_MSG 
$MEGARAID_MSG
$MEGACLI_MSG
$SOFTWARERAID_MSG
$MPTRAID1_MSG
$AACRAID_MSG
</center>
"

$BBHOME/bin/bb $BBDISP "status $MACHINE.raid $COLOR `date` - RAID is $STATUS $OUTPUT"
