3ware RAID status script

August 24, 2013 by

Recently I have had a streak of bad luck with hard drives behind 3ware RAID controllers dying. The 3ware CLI is a great tool, but it doesn’t have a simple way of setting up recurring health checks of the RAID array and to send alerts if an array becomes degraded. Therefore, I set out to write a script that would check the health status of my 3ware RAID arrays on a daily basis. I found a great script to start out from here, but I wanted a little more, so I enhanced it a bit.

Because I have several 3ware RAID cards and various models, I decided to make the script as generic as possible, while at the same time automatically find the RAID unit, so that I wouldn’t have to specify that every time I install the script. Below is my updated version of the script. To install it I put the contents in a file called raidhealth in /etc/cron.daily and change the permissions to 0700.

#!/bin/bash

# 3Ware CLI RAID Report
#
# You will need to install the tw_cli utility which you can
# download for free from www.3ware.com or you can get it from
# 3rd party repositories.

##########################################################
#   Variables you need to set.                           #
##########################################################

# Email address to which status reports are sent
EMAIL="someone@example.com"

##########################################################
#  Do NOT edit below unless you know what you're doing.  #
##########################################################

HOSTNAME=$(hostname -f)
DATE=$(date +%Y-%m-%d)
TIME=$(date +%H:%M)

# Find the controller ID
CONTROLLER_ID=`tw_cli info | awk 'NR==4' | awk '{print $1}'`

# Find the RAID unit ID
UNIT_ID=`tw_cli info $CONTROLLER_ID | awk 'NR==4' | awk '{print $1}'`

# Use the controller ID to get info on RAID status
STATUS=`tw_cli info $CONTROLLER_ID $UNIT_ID status | awk '{print $4}'`

# Check the status and send email with the appropriate subject
if [ "$STATUS" != "OK" ];
then
  echo "=== WARNING: RAID DEGRADED! ===" > /tmp/raidhealth.txt
  echo "" >> /tmp/raidhealth.txt
  echo "Date: $DATE" >> /tmp/raidhealth.txt
  echo "Time: $TIME" >> /tmp/raidhealth.txt
  tw_cli info $CONTROLLER_ID >> /tmp/raidhealth.txt
  mailx -s "RAID $STATUS: $HOSTNAME" $EMAIL < /tmp/raidhealth.txt
else
  echo "Date: $DATE" > /tmp/raidhealth.txt
  echo "Time: $TIME" >> /tmp/raidhealth.txt
  tw_cli info $CONTROLLER_ID >> /tmp/raidhealth.txt
  mailx -s "RAID $STATUS: $HOSTNAME" $EMAIL < /tmp/raidhealth.txt
fi

Once you have installed the script, updated the email address and given it the proper permissions, to test that the script works, simply run it from the command line as root:

# cd /etc/cron.daily
# ./raidhealth

Since I first implemented this script, my bout of dying hard drives have continued and this script has accurately alerted me about degraded arrays on several occasions. That said, I don't issue any guarantees that it will work for you.

Leave a Reply