zdb: fix printf() length for uint64_t devid
[zfs.git] / cmd / zed / zed.d / scrub_finish-notify.sh
blobfc9dc23e04aa7e89236679bb6247e610f7cc15b3
1 #!/bin/sh
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.
10 # Exit codes:
11 # 0: notification sent
12 # 1: notification failed
13 # 2: notification not configured
14 # 3: notification suppressed
15 # 9: internal error
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
24 action="resilver"
25 elif [ "${ZEVENT_SUBCLASS}" = "scrub_finish" ]; then
26 action="scrub"
27 else
28 zed_log_err "unsupported event class \"${ZEVENT_SUBCLASS}\""
29 exit 9
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
43 umask 077
44 note_subject="ZFS ${ZEVENT_SUBCLASS} event for ${ZEVENT_POOL} on $(hostname)"
45 note_pathname="$(mktemp)"
47 echo "ZFS has finished a ${action}:"
48 echo
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}"
60 exit "${rv}"