]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cmd/zed/zed.d/trim_finish-notify.sh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / cmd / zed / zed.d / trim_finish-notify.sh
1 #!/bin/sh
2 #
3 # Send notification in response to a TRIM_FINISH. The event
4 # will be received for each vdev in the pool which was trimmed.
5 #
6 # Exit codes:
7 #   0: notification sent
8 #   1: notification failed
9 #   2: notification not configured
10 #   9: internal error
11
12 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
13 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
14
15 [ -n "${ZEVENT_POOL}" ] || exit 9
16 [ -n "${ZEVENT_SUBCLASS}" ] || exit 9
17
18 zed_check_cmd "${ZPOOL}" || exit 9
19
20 umask 077
21 note_subject="ZFS ${ZEVENT_SUBCLASS} event for ${ZEVENT_POOL} on $(hostname)"
22 note_pathname="${TMPDIR:="/tmp"}/$(basename -- "$0").${ZEVENT_EID}.$$"
23 {
24     echo "ZFS has finished a trim:"
25     echo
26     echo "   eid: ${ZEVENT_EID}"
27     echo " class: ${ZEVENT_SUBCLASS}"
28     echo "  host: $(hostname)"
29     echo "  time: ${ZEVENT_TIME_STRING}"
30
31     "${ZPOOL}" status -t "${ZEVENT_POOL}"
32
33 } > "${note_pathname}"
34
35 zed_notify "${note_subject}" "${note_pathname}"; rv=$?
36 rm -f "${note_pathname}"
37 exit "${rv}"