January 15, 2025 · backup selfhost linux software

ZFS Health Notifications by Email

Screen-Shot-2025-01-15-at-8.43.38-PM-1

ZFS on my home server has been working reliably for the past 6+ years, with no failures identified so far during the automatic scrubs. However, I was hoping to be pushed a notification if there are any problems during the scrub process. After some research, I found that there is a daemon called ZED (ZFS Event Daemon) which monitors the health of the zpools. Since I wasn't regularly checking the ZED logs, I looked for a way to be informed of a degraded pool or impending failure.

ZED fortunately has the ability to send notifications via a SMTP server. Here are the requirements:

  • ZFS pool running ZED
  • SMTP server (WAN access or port 25 traffic NOT required).
  • ability to redirect mail / make aliases (optional)

Step 1: Create Mail Account

User accounts for simple notifications or alerts should have the least amount of system privileges. To create a user without a home folder and no login access, add the --no-create-home and --system flags respectively.

For example, to make a user called alerts, for alerts@naut.ca

sudo adduser --no-create-home --system  alerts

# to set the password
sudo passwd alerts

Step 2: Setup Redirect (optional)

I set up a mail alias in order to redirect all notifications sent to the alerts account to my personal account:

# cat /etc/aliases
postmaster:yoon
alerts:yoon

# update aliases
sudo newaliases

Step 3: Setup Mailer Utilities

sSMTP was chosen as the system mailer due to its ease of use. Install with:

sudo apt install mailutils ssmtp

Then update the configuration file at /etc/ssmtp/ssmtp.conf. The configuration update may require a restart to fully take effect.

root=
# SMTP server is located at cloud.naut.ca on port 465
mailhub=cloud.naut.ca:465

AuthUser=alerts
AuthPass=PASS_HERE

# Force TLS
UseTLS=YES

# Where will the mail seem to come from?
rewriteDomain=foobar.naut.ca

# The full hostname
hostname=foobar

Step 4: Setup ZED for Email Notifications

Lastly, update the ZED configuration file at /etc/zfs/zed.d/zed.rc. Make sure that ZED_EMAIL_ADDR is your destination email address. To be notified of successful ZFS scrubs, set ZED_NOTIFY_VERBOSE=1. Here are the changed lines from my configuration:

# zed.rc – ZEDLET configuration.

# multiple addresses can be specified if they are delimited by whitespace.
ZED_EMAIL_ADDR="alerts@naut.ca"

# Minimum number of seconds between notifications for a similar event.
ZED_NOTIFY_INTERVAL_SECS=3600

ZED_NOTIFY_VERBOSE=1

Finally restart the daemon with: sudo systemctl restart zfs-zed.

Step 5: Testing

Lastly, trigger a scrub with zfs scrub POOL and wait for the success (or failure) notification!