]> git.proxmox.com Git - mirror_zfs-debian.git/blob - cmd/zed/zed.d/resilver.finish-notify.sh
Imported Upstream version 0.6.5.3
[mirror_zfs-debian.git] / cmd / zed / zed.d / resilver.finish-notify.sh
1 #!/bin/sh
2 #
3 # Send notification in response to a RESILVER.FINISH or SCRUB.FINISH.
4 #
5 # By default, "zpool status" output will only be included for a scrub.finish
6 # zevent if the pool is not healthy; to always include its output, set
7 # ZED_NOTIFY_VERBOSE=1.
8 #
9 # Exit codes:
10 # 0: notification sent
11 # 1: notification failed
12 # 2: notification not configured
13 # 3: notification suppressed
14 # 9: internal error
15
16 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
17 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
18
19 [ -n "${ZEVENT_POOL}" ] || exit 9
20 [ -n "${ZEVENT_SUBCLASS}" ] || exit 9
21
22 if [ "${ZEVENT_SUBCLASS}" = "resilver.finish" ]; then
23 action="resilver"
24 elif [ "${ZEVENT_SUBCLASS}" = "scrub.finish" ]; then
25 action="scrub"
26 else
27 zed_log_err "unsupported event class \"${ZEVENT_SUBCLASS}\""
28 exit 9
29 fi
30
31 zed_check_cmd "${ZPOOL}" || exit 9
32
33 # For scrub, suppress notification if the pool is healthy
34 # and verbosity is not enabled.
35 #
36 if [ "${ZEVENT_SUBCLASS}" = "scrub.finish" ]; then
37 healthy="$("${ZPOOL}" status -x "${ZEVENT_POOL}" \
38 | grep "'${ZEVENT_POOL}' is healthy")"
39 [ -n "${healthy}" ] && [ "${ZED_NOTIFY_VERBOSE}" -eq 0 ] && exit 3
40 fi
41
42 umask 077
43 note_subject="ZFS ${ZEVENT_SUBCLASS} event for ${ZEVENT_POOL} on $(hostname)"
44 note_pathname="${TMPDIR:="/tmp"}/$(basename -- "$0").${ZEVENT_EID}.$$"
45 {
46 echo "ZFS has finished a ${action}:"
47 echo
48 echo " eid: ${ZEVENT_EID}"
49 echo " class: ${ZEVENT_SUBCLASS}"
50 echo " host: $(hostname)"
51 echo " time: ${ZEVENT_TIME_STRING}"
52
53 "${ZPOOL}" status "${ZEVENT_POOL}"
54
55 } > "${note_pathname}"
56
57 zed_notify "${note_subject}" "${note_pathname}"; rv=$?
58 rm -f "${note_pathname}"
59 exit "${rv}"