2008.08.03 - 15:08:24 PDT
This should be compatible with any controller supported by tw_cli.
#!/bin/bash
TW_CLI="/YOUR_PATH_TO/tw_cli" # change this for your environment
RAID_CHECK_CMD="$TW_CLI /c0 show allunitstatus"
RAID_FULLSTATUS_CMD="$TW_CLI /c0 show all"
EMAIL_TO="YOUR_EMAIL@DDRESS" # change this for your environment
EMAIL_FROM="FROM_EMAIL@DDRESS" # change this for your environment
SENDMAIL="/usr/sbin/sendmail -f $EMAIL_FROM"
TOUCH="/bin/touch"
SEMAPHORE="/root/.raidstatus_mailed" # change this if you like
HOSTNAME=$(hostname -f) # THIS IS NOT CROSS-PLATFORM SAFE - should be OK for any linux, otherwise remove the -f
INTERVAL=600
while : ; do
if $RAID_CHECK_CMD |grep -q 'Not Optimal Units = [^0]'; then # Scream OH SHIT and run.
# Been an hour since I emailed last?
if [ ! \( -r $SEMAPHORE \) -o \( $(($(date +%s) - $(date +%s -r $SEMAPHORE))) -gt 3600 \) ]; then
FULLSTATUS="$($RAID_FULLSTATUS_CMD)"
$SENDMAIL $EMAIL_TO <<EOM
From: "3ware 9650SE on $HOSTNAME" <$EMAIL_FROM>
To: <$EMAIL_TO>
Subject: RAID problem detected on $HOSTNAME
$0 has detected a problem
Full controller status:
$FULLSTATUS
Please resolve this ASAP.
EOM
touch $SEMAPHORE
fi
fi
sleep $INTERVAL
done
#!/bin/bash
TW_CLI="/YOUR_PATH_TO/tw_cli" # change this for your environment
RAID_CHECK_CMD="$TW_CLI /c0 show allunitstatus"
RAID_FULLSTATUS_CMD="$TW_CLI /c0 show all"
EMAIL_TO="YOUR_EMAIL@DDRESS" # change this for your environment
EMAIL_FROM="FROM_EMAIL@DDRESS" # change this for your environment
SENDMAIL="/usr/sbin/sendmail -f $EMAIL_FROM"
TOUCH="/bin/touch"
SEMAPHORE="/root/.raidstatus_mailed" # change this if you like
HOSTNAME=$(hostname -f) # THIS IS NOT CROSS-PLATFORM SAFE - should be OK for any linux, otherwise remove the -f
INTERVAL=600
while : ; do
if $RAID_CHECK_CMD |grep -q 'Not Optimal Units = [^0]'; then # Scream OH SHIT and run.
# Been an hour since I emailed last?
if [ ! \( -r $SEMAPHORE \) -o \( $(($(date +%s) - $(date +%s -r $SEMAPHORE))) -gt 3600 \) ]; then
FULLSTATUS="$($RAID_FULLSTATUS_CMD)"
$SENDMAIL $EMAIL_TO <<EOM
From: "3ware 9650SE on $HOSTNAME" <$EMAIL_FROM>
To: <$EMAIL_TO>
Subject: RAID problem detected on $HOSTNAME
$0 has detected a problem
Full controller status:
$FULLSTATUS
Please resolve this ASAP.
EOM
touch $SEMAPHORE
fi
fi
sleep $INTERVAL
done


