]> git.proxmox.com Git - mirror_zfs-debian.git/blob - cmd/zed/zed.d/resilver.finish-email.sh
Imported Upstream version 0.6.4.2
[mirror_zfs-debian.git] / cmd / zed / zed.d / resilver.finish-email.sh
1 #!/bin/sh
2 #
3 # Send email to ZED_EMAIL in response to a RESILVER.FINISH or SCRUB.FINISH.
4 # By default, "zpool status" output will only be included in the email for
5 # a scrub.finish zevent if the pool is not healthy; to always include its
6 # output, set ZED_EMAIL_VERBOSE=1.
7 # Exit codes:
8 # 0: email sent
9 # 1: email failed
10 # 2: email suppressed
11 # 3: missing executable
12 # 4: unsupported event class
13 # 5: internal error
14 #
15 test -f "${ZED_ZEDLET_DIR}/zed.rc" && . "${ZED_ZEDLET_DIR}/zed.rc"
16
17 test -n "${ZEVENT_POOL}" || exit 5
18 test -n "${ZEVENT_SUBCLASS}" || exit 5
19
20 if test "${ZEVENT_SUBCLASS}" = "resilver.finish"; then
21 ACTION="resilvering"
22 elif test "${ZEVENT_SUBCLASS}" = "scrub.finish"; then
23 ACTION="scrubbing"
24 else
25 logger -t "${ZED_SYSLOG_TAG:=zed}" \
26 -p "${ZED_SYSLOG_PRIORITY:=daemon.warning}" \
27 `basename "$0"`: unsupported event class \"${ZEVENT_SUBCLASS}\"
28 exit 4
29 fi
30
31 # Only send email if ZED_EMAIL has been configured.
32 test -n "${ZED_EMAIL}" || exit 2
33
34 # Ensure requisite executables are installed.
35 if ! command -v "${MAIL:=mail}" >/dev/null 2>&1; then
36 logger -t "${ZED_SYSLOG_TAG:=zed}" \
37 -p "${ZED_SYSLOG_PRIORITY:=daemon.warning}" \
38 `basename "$0"`: "${MAIL}" not installed
39 exit 3
40 fi
41 if ! test -x "${ZPOOL}"; then
42 logger -t "${ZED_SYSLOG_TAG:=zed}" \
43 -p "${ZED_SYSLOG_PRIORITY:=daemon.warning}" \
44 `basename "$0"`: "${ZPOOL}" not installed
45 exit 3
46 fi
47
48 # For scrub, suppress email if pool is healthy and verbosity is not enabled.
49 if test "${ZEVENT_SUBCLASS}" = "scrub.finish"; then
50 HEALTHY=`"${ZPOOL}" status -x "${ZEVENT_POOL}" | \
51 grep "'${ZEVENT_POOL}' is healthy"`
52 test -n "${HEALTHY}" -a "${ZED_EMAIL_VERBOSE:=0}" = 0 && exit 2
53 fi
54
55 "${MAIL}" -s "ZFS ${ZEVENT_SUBCLASS} event for ${ZEVENT_POOL} on `hostname`" \
56 "${ZED_EMAIL}" <<EOF
57 A ZFS pool has finished ${ACTION}:
58
59 eid: ${ZEVENT_EID}
60 host: `hostname`
61 time: ${ZEVENT_TIME_STRING}
62 `"${ZPOOL}" status "${ZEVENT_POOL}"`
63 EOF
64 MAIL_STATUS=$?
65
66 if test "${MAIL_STATUS}" -ne 0; then
67 logger -t "${ZED_SYSLOG_TAG:=zed}" \
68 -p "${ZED_SYSLOG_PRIORITY:=daemon.warning}" \
69 `basename "$0"`: "${MAIL}" exit="${MAIL_STATUS}"
70 exit 1
71 fi
72
73 exit 0