Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/openzfs/cmd/zed/zed.d/scrub_finish-notify.sh
48529 views
1
#!/bin/sh
2
# shellcheck disable=SC2154
3
#
4
# Send notification in response to a RESILVER_FINISH or SCRUB_FINISH.
5
#
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.
9
#
10
# Exit codes:
11
# 0: notification sent
12
# 1: notification failed
13
# 2: notification not configured
14
# 3: notification suppressed
15
# 9: internal error
16
17
[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
18
. "${ZED_ZEDLET_DIR}/zed-functions.sh"
19
20
[ -n "${ZEVENT_POOL}" ] || exit 9
21
[ -n "${ZEVENT_SUBCLASS}" ] || exit 9
22
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
30
fi
31
32
zed_check_cmd "${ZPOOL}" || exit 9
33
34
# For scrub, suppress notification if the pool is healthy
35
# and verbosity is not enabled.
36
#
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
41
fi
42
43
umask 077
44
note_subject="ZFS ${ZEVENT_SUBCLASS} event for ${ZEVENT_POOL} on $(hostname)"
45
note_pathname="$(mktemp)"
46
{
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}"
53
54
"${ZPOOL}" status "${ZEVENT_POOL}"
55
56
} > "${note_pathname}"
57
58
zed_notify "${note_subject}" "${note_pathname}"; rv=$?
59
rm -f "${note_pathname}"
60
exit "${rv}"
61
62