Path: blob/main/sys/contrib/openzfs/cmd/zed/zed.d/scrub_finish-notify.sh
48529 views
#!/bin/sh1# shellcheck disable=SC21542#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_finish6# zevent if the pool is not healthy; to always include its output, set7# ZED_NOTIFY_VERBOSE=1.8#9# Exit codes:10# 0: notification sent11# 1: notification failed12# 2: notification not configured13# 3: notification suppressed14# 9: internal error1516[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"17. "${ZED_ZEDLET_DIR}/zed-functions.sh"1819[ -n "${ZEVENT_POOL}" ] || exit 920[ -n "${ZEVENT_SUBCLASS}" ] || exit 92122if [ "${ZEVENT_SUBCLASS}" = "resilver_finish" ]; then23action="resilver"24elif [ "${ZEVENT_SUBCLASS}" = "scrub_finish" ]; then25action="scrub"26else27zed_log_err "unsupported event class \"${ZEVENT_SUBCLASS}\""28exit 929fi3031zed_check_cmd "${ZPOOL}" || exit 93233# For scrub, suppress notification if the pool is healthy34# and verbosity is not enabled.35#36if [ "${ZEVENT_SUBCLASS}" = "scrub_finish" ]; then37healthy="$("${ZPOOL}" status -x "${ZEVENT_POOL}" \38| grep "'${ZEVENT_POOL}' is healthy")"39[ -n "${healthy}" ] && [ "${ZED_NOTIFY_VERBOSE}" -eq 0 ] && exit 340fi4142umask 07743note_subject="ZFS ${ZEVENT_SUBCLASS} event for ${ZEVENT_POOL} on $(hostname)"44note_pathname="$(mktemp)"45{46echo "ZFS has finished a ${action}:"47echo48echo " eid: ${ZEVENT_EID}"49echo " class: ${ZEVENT_SUBCLASS}"50echo " host: $(hostname)"51echo " time: ${ZEVENT_TIME_STRING}"5253"${ZPOOL}" status "${ZEVENT_POOL}"5455} > "${note_pathname}"5657zed_notify "${note_subject}" "${note_pathname}"; rv=$?58rm -f "${note_pathname}"59exit "${rv}"606162