Monitor Utility for 3ware / LSI RAID on Linux

For those seeking a small and efficient script to monitor 3ware RAID array through command line, here is a small script on how to do it. The script was initially posted on cpanelconfig.com but the site no longer exist. So we wanted to help those looking for the same thing.

For liability concerns, this post is provided AS IS. Proceed at your own risk. Though we’ve tested this script, we can’t guarantee it to function 100% all the time, nor are we responsible for any issues that may arise of using this script.

The script will allow you to monitor the RAID array and receive notifications when the array is down. The script consist of 3 items:

raid-health.sh : file that contains the check RAID script and send email
raid-health-body.txt: body message of the sent email
tw_cli: This is the tool available from 3ware to run CLI (Command Line Interface) through shell. This must be downloaded to a folder

First thing is the raid-health.sh script as follow, you can place it anywhere on your system (If you copy/paste through PuTTy, watch for changed quotation marks):

#!/bin/bash
com=`/home/path/to/script/tw_cli info c0 u0 status | awk ‘{print $4}’`
echo $com
if [ “$com” != “OK” ];
then
mail -s “RAID Warning Subject Line
email@yourdomain.com < /home/path/to/raid-health-body.txt
fi
The lines in red indicate a change is required. These are the paths, email addresses.

Second, create raid-health-body.txt file or copy the following text to a file named raid-health-body.txt:

RAID is DEGRADED on someservername.server.com

Make sure both raid-health.sh and raid-health-body.txt files are CHMOD 644 or 755 so the cron job can execute them.

Last, add the following line to your cron job (typically root) under /var/spool/cron :

0 8,19 * * * /home/path/to/raid-health.sh > /dev/null 2>&1

The above will check the RAID staus at 8 am and 7 pm. Save the cron job and watch for the emails when the RAID fails.

Tips:
===
– The above script was altered to send emails when the array status is NOT OK. This means if the array is in Verify or Rebuild mode, it will send an email. Preferred to schedule the cron to run outside of verify periods. If you wish to change this behavior, simply replace the line:

if [ “$com” != “OK” ]; with      if [ “$com” = “DEGRADED” ];


– It is better to test the script before adding it to the cron. Do that by running the file raid-health.sh

– If you get any syntex errors, check the quotation marks on the script to match the one written above.

– The line /tw_cli info c0 u0 status   means check controller #0 , Logical Unit # 0. If you have multiple controllers or multiple logical units, the above need to be changed.