From 9419ac28c550d0c06959fcc081b92cf05d5686f1 Mon Sep 17 00:00:00 2001 From: Matthias Klumpp Date: Sat, 19 Mar 2022 02:34:55 +0100 Subject: [PATCH] Add script to send mail in case btrfs issues were detected This can be very useful for smaller setups where the admin still would like to receive an email in case a disk in a btrfs RAID array fails. Partially resolves #88 --- btrfs-errmail.service | 7 +++++ btrfs-errmail.sh | 53 ++++++++++++++++++++++++++++++++++++++ btrfs-errmail.timer | 10 +++++++ sysconfig.btrfsmaintenance | 10 +++++++ 4 files changed, 80 insertions(+) create mode 100644 btrfs-errmail.service create mode 100755 btrfs-errmail.sh create mode 100644 btrfs-errmail.timer diff --git a/btrfs-errmail.service b/btrfs-errmail.service new file mode 100644 index 0000000..89d4d79 --- /dev/null +++ b/btrfs-errmail.service @@ -0,0 +1,7 @@ +[Unit] +Description=Check for btrfs issues and send an email if any were found +Documentation=man:btrfs + +[Service] +Type=simple +ExecStart=/usr/share/btrfsmaintenance/btrfs-errmail.sh diff --git a/btrfs-errmail.sh b/btrfs-errmail.sh new file mode 100755 index 0000000..546c086 --- /dev/null +++ b/btrfs-errmail.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Copyright (c) 2022 Matthias Klumpp + +umask 022 +PATH=/sbin:/bin:/usr/sbin:/usr/bin +export PATH + +if [ -f /etc/sysconfig/btrfsmaintenance ] ; then + . /etc/sysconfig/btrfsmaintenance +fi + +if [ -f /etc/default/btrfsmaintenance ] ; then + . /etc/default/btrfsmaintenance +fi + +. $(dirname $(realpath "$0"))/btrfsmaintenance-functions + +if [ -z "$BTRFS_MAILADDR" ] +then + # no email set, nothing to do for us + exit 0 +fi + +BTRFS_STATS_MOUNTPOINTS=$(expand_auto_mountpoint "auto") +OIFS="$IFS" +IFS=: +for MM in $BTRFS_STATS_MOUNTPOINTS; do + if ! is_btrfs "$MM"; then + echo "Path $MM is not btrfs, skipping" + continue + fi + devstats=$(btrfs device stats --check $MM 2>&1) + if [ $? -ne 0 ]; then + mail_body="$(sendmail -t <