I know this is an old question, but it gave me a few of the pieces I put together, and i thought i'd shoot back the script i came up with, since this is an almost exact match to my situation:
it requires sas2ircu: http://www.avagotech.com/docs-and-downloads/host-bus-adapters/host-bus-adapters-common-files/sas_sata_6g_p20/SAS2IRCU_P20.zip
and from the ports, bash and sg3_utils
It does make a few assumptions, i think the main one is that it is attached to controller 0. you can use sas2ircu list
to identify your controller number.
It will check the selected pool (via zpool status).
If there are no errors it will:
- save a file (at /root/.sas2ircu/drives) with a mapping of device
names to enclosure slots
- turn off any leds previously activated by
this script (this is stored in /root/.sas2ircu/locs)
If there are errors it will:
- send an email with the full output of zpool status
- activate the leds
of any failed drives (and store the locations activates in
/root/.sas2ircu locs so they can later be deactivated)
anyway here is the script. I run it as an hourly cron job.
#! /usr/local/bin/bash
if [ ! "$1" ]; then
echo "Usage: zpscan.sh pool [email]"
echo "Scan a pool, send email notification and activate leds of failed drives"
exit
fi
if [ ! -d /root/.sas2ircu ]; then
mkdir /root/.sas2ircu
touch /root/.sas2ircu/drives
touch /root/.sas2ircu/locs
fi
if [ "$2" ]; then
email="$2"
else
email="root"
fi
condition=$(/sbin/zpool status $1 | egrep -i '(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover)')
if [ "${condition}" ]; then
emailSubject="`hostname` - ZFS pool - HEALTH fault"
mailbody=$(zpool status $1)
echo "Sending email notification of degraded zpool $1"
echo "$mailbody" | mail -s "Degraded Zpool $1 on hostname" $email
drivelist=$(zpool status $1 | grep -E "(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED)" | grep -vE "^\W+($1|NAME|mirror|logs|spares)" | sed -E $'s/.*was \/dev\/([0-9a-z]+)/\\1/;s/^[\t ]+([0-9a-z]+)[\t ]+.*$/\\1/')
echo "Locating failed drives."
for drive in $drivelist;
do
record=$(grep -E "^$drive" /root/.sas2ircu/drives)
location=$(echo $record | cut -f 3 -d " ")
echo Locating: $record
sas2ircu 0 locate $location ON
if [ ! "$(egrep $location /root/.sas2ircu/locs)" ]; then
echo $location >> /root/.sas2ircu/locs
fi
done
else
echo "Saving drive list."
drivelist=$(zpool status $1 | grep -E $'^\t ' | grep -vE "^\W+($1|NAME|mirror|logs|spares)" | sed -E $'s/^[\t ]+//;s/([a-z0-9]+).*/\\1/')
saslist=$(sas2ircu 0 display)
printf "" > /root/.sas2ircu/drives
for drive in $drivelist;
do
sasaddr=$(sg_vpd -i -q $drive 2>/dev/null | sed -E '2!d;s/,.*//;s/ 0x//;s/([0-9a-f]{7})([0-9a-f])([0-9a-f]{4})([0-9a-f]{4})/\1-\2-\3-\4/')
encaddr=$(echo "$saslist" | grep $sasaddr -B 2 | sed -E 'N;s/^.*: ([0-9]+)\n.*: ([0-9]+)/\1:\2/')
echo $drive $sasaddr $encaddr >> /root/.sas2ircu/drives
done
for loc in $(cat /root/.sas2ircu/locs);
do
sas2ircu 0 locate $loc OFF
done
printf "" > /root/.sas2ircu/locs
fi
for loc in $(cat /root/.sas2ircu/locs);
do
sas2ircu 0 locate $loc OFF
done
printf "" > /root/.sas2ircu/locs
fi