xref: /freebsd/sys/contrib/openzfs/cmd/zed/zed.d/trim_finish-notify.sh (revision e92ffd9b626833ebdbf2742c8ffddc6cd94b963e)
1eda14cbcSMatt Macy#!/bin/sh
2*e92ffd9bSMartin Matuska# shellcheck disable=SC2154
3eda14cbcSMatt Macy#
4eda14cbcSMatt Macy# Send notification in response to a TRIM_FINISH. The event
5eda14cbcSMatt Macy# will be received for each vdev in the pool which was trimmed.
6eda14cbcSMatt Macy#
7eda14cbcSMatt Macy# Exit codes:
8eda14cbcSMatt Macy#   0: notification sent
9eda14cbcSMatt Macy#   1: notification failed
10eda14cbcSMatt Macy#   2: notification not configured
11eda14cbcSMatt Macy#   9: internal error
12eda14cbcSMatt Macy
13eda14cbcSMatt Macy[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
14eda14cbcSMatt Macy. "${ZED_ZEDLET_DIR}/zed-functions.sh"
15eda14cbcSMatt Macy
16eda14cbcSMatt Macy[ -n "${ZEVENT_POOL}" ] || exit 9
17eda14cbcSMatt Macy[ -n "${ZEVENT_SUBCLASS}" ] || exit 9
18eda14cbcSMatt Macy
19eda14cbcSMatt Macyzed_check_cmd "${ZPOOL}" || exit 9
20eda14cbcSMatt Macy
21eda14cbcSMatt Macyumask 077
22eda14cbcSMatt Macynote_subject="ZFS ${ZEVENT_SUBCLASS} event for ${ZEVENT_POOL} on $(hostname)"
2316038816SMartin Matuskanote_pathname="$(mktemp)"
24eda14cbcSMatt Macy{
25eda14cbcSMatt Macy    echo "ZFS has finished a trim:"
26eda14cbcSMatt Macy    echo
27eda14cbcSMatt Macy    echo "   eid: ${ZEVENT_EID}"
28eda14cbcSMatt Macy    echo " class: ${ZEVENT_SUBCLASS}"
29eda14cbcSMatt Macy    echo "  host: $(hostname)"
30eda14cbcSMatt Macy    echo "  time: ${ZEVENT_TIME_STRING}"
31eda14cbcSMatt Macy
32eda14cbcSMatt Macy    "${ZPOOL}" status -t "${ZEVENT_POOL}"
33eda14cbcSMatt Macy
34eda14cbcSMatt Macy} > "${note_pathname}"
35eda14cbcSMatt Macy
36eda14cbcSMatt Macyzed_notify "${note_subject}" "${note_pathname}"; rv=$?
37eda14cbcSMatt Macyrm -f "${note_pathname}"
38eda14cbcSMatt Macyexit "${rv}"
39