danb35
Hall of Famer
- Joined
- Aug 16, 2011
- Messages
- 15,504
I ran across what promises to be a handy script at https://serverfault.com/a/708808, which is supposed to monitor pool status and light the status LED for failed disks. It uses sas2ircu, so should at a minimum be able to support Supermicro chassis with SAS expander backplanes; it might well have broader applicability.
I've made two small changes to it: (1) I've set a variable for the directory where the script and its few data files will live, and (2) I've added an extension to the data file names to match the pool name (so the script can be used to monitor more than one pool).
Unfortunately, it isn't working;
and here:
I can play with
Any thoughts?
I've made two small changes to it: (1) I've set a variable for the directory where the script and its few data files will live, and (2) I've added an extension to the data file names to match the pool name (so the script can be used to monitor more than one pool).
Unfortunately, it isn't working;
grep is complaining. The offending statements appear to be here: drivelist=$(zpool status $1 | grep -E $'^\t ' | grep -vE "^\W+($1|NAME|mirror|logs|spares)" | sed -E $'s/^[\t ]+//;s/([a-z0-9]+).*/\\1/')and here:
encaddr=$(echo "$saslist" | grep $sasaddr -B 2 | sed -E 'N;s/^.*: ([0-9]+)\n.*: ([0-9]+)/\1:\2/')I can play with
grep a little and have never touched sed, so this really looks like gibberish to me. Here's the complete script:Code:
#! /usr/local/bin/bash
BASEDIR=/mnt/ssdpool/scripts
if [ ! "$1" ]; then
echo "Usage: zpscan.sh pool "
echo "Scan a pool, send email notification and activate leds of failed drives"
exit
fi
if [ ! -d $BASEDIR/.sas2ircu ]; then
mkdir $BASEDIR/.sas2ircu
touch $BASEDIR/.sas2ircu/drives-$1
touch $BASEDIR/.sas2ircu/locs-$1
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" $BASEDIR/.sas2ircu/drives-$1)
location=$(echo $record | cut -f 3 -d " ")
echo Locating: $record
sas2ircu 0 locate $location ON
if [ ! "$(egrep $location $BASEDIR/.sas2ircu/locs-$1)" ]; then
echo $location >> $BASEDIR/.sas2ircu/locs-$1
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 "" > $BASEDIR/.sas2ircu/drives-$1
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 >> $BASEDIR/.sas2ircu/drives-$1
done
for loc in $(cat $BASEDIR/.sas2ircu/locs-$1);
do
sas2ircu 0 locate $loc OFF
done
printf "" > $BASEDIR/.sas2ircu/locs-$1
fi
Any thoughts?