ZFS Health Check and Email Notification

A simple cron script to monitor the health of a ZFS pool and email you if there are any problems. Tested on Ubuntu 12.04: (Taken from http://zfsguru.com/forum/zfsgurudevelopment/269)
#!/bin/bash
EMAIL_ADD=email@address.com

zpool status -x | grep 'all pools are healthy'

if [ $? -ne 0 ]; then
        /bin/date > /tmp/zfs.stat
        echo >> /tmp/zfs.stat
        /bin/hostname >> /tmp/zfs.stat
        echo >> /tmp/zfs.stat
        /sbin/zpool status -x >> /tmp/zfs.stat
        cat /tmp/zfs.stat | /bin/mail -s "Disk failure in server : `hostname`" $EMAIL_ADD
fi

2 comments:

Tim said...

I just wanted to comment that this bit of scripting was useful, thanks!!

I created this as root in /root/scripts/zfs_health.sh

I set it up in crontab to run hourly and redirected output to /dev/null

I had to fully path the /sbin/zpool command on ubuntu 12.04, and mail was in /usr/bin


Thanks!

Anonymous said...

I updated the paths for Ubuntu 16.04

$ cat zpoolstatuscheckemail.sh
#!/bin/bash
# Version 1.0
# 06/23/2016

EMAIL_ADD=[email goes here]

zpool status -x | grep 'all pools are healthy'

if [ $? -ne 0 ]; then
/bin/date > /tmp/zfs.stat
echo >> /tmp/zfs.stat
/bin/hostname >> /tmp/zfs.stat
echo >> /tmp/zfs.stat
/sbin/zpool status -x >> /tmp/zfs.stat
cat /tmp/zfs.stat | /usr/bin/mail -s "Disk failure in server : `hostname`" $EMAIL_ADD
fi