2 # shellcheck disable=SC2154
4 # Send notification in response to a RESILVER_FINISH or SCRUB_FINISH.
6 # By default, "zpool status" output will only be included for a scrub_finish
7 # zevent if the pool is not healthy; to always include its output, set
8 # ZED_NOTIFY_VERBOSE=1.
11 # 0: notification sent
12 # 1: notification failed
13 # 2: notification not configured
14 # 3: notification suppressed
17 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && .
"${ZED_ZEDLET_DIR}/zed.rc"
18 .
"${ZED_ZEDLET_DIR}/zed-functions.sh"
20 [ -n "${ZEVENT_POOL}" ] ||
exit 9
21 [ -n "${ZEVENT_SUBCLASS}" ] ||
exit 9
23 if [ "${ZEVENT_SUBCLASS}" = "resilver_finish" ]; then
25 elif [ "${ZEVENT_SUBCLASS}" = "scrub_finish" ]; then
28 zed_log_err
"unsupported event class \"${ZEVENT_SUBCLASS}\""
32 zed_check_cmd
"${ZPOOL}" ||
exit 9
34 # For scrub, suppress notification if the pool is healthy
35 # and verbosity is not enabled.
37 if [ "${ZEVENT_SUBCLASS}" = "scrub_finish" ]; then
38 healthy
="$("${ZPOOL}" status -x "${ZEVENT_POOL}" \
39 | grep "'${ZEVENT_POOL}' is healthy
")"
40 [ -n "${healthy}" ] && [ "${ZED_NOTIFY_VERBOSE}" -eq 0 ] && exit 3
44 note_subject
="ZFS ${ZEVENT_SUBCLASS} event for ${ZEVENT_POOL} on $(hostname)"
45 note_pathname
="$(mktemp)"
47 echo "ZFS has finished a ${action}:"
49 echo " eid: ${ZEVENT_EID}"
50 echo " class: ${ZEVENT_SUBCLASS}"
51 echo " host: $(hostname)"
52 echo " time: ${ZEVENT_TIME_STRING}"
54 "${ZPOOL}" status
"${ZEVENT_POOL}"
56 } > "${note_pathname}"
58 zed_notify
"${note_subject}" "${note_pathname}"; rv
=$?
59 rm -f "${note_pathname}"