Optimize RAIDZ expansion
[zfs.git] / cmd / zed / zed.d / generic-notify.sh
blobe73b053902fa1ec611a708d1de915f6e3b15f4b2
1 #!/bin/sh
2 # shellcheck disable=SC2154
4 # Send notification in response to a given zevent.
6 # This is a generic script than can be symlinked to a file in the
7 # enabled-zedlets directory to have a notification sent when a particular
8 # class of zevents occurs. The symlink filename must begin with the zevent
9 # (sub)class string (e.g., "probe_failure-notify.sh" for the "probe_failure"
10 # subclass). Refer to the zed(8) manpage for details.
12 # Only one notification per ZED_NOTIFY_INTERVAL_SECS will be sent for a given
13 # class/pool combination. This protects against spamming the recipient
14 # should multiple events occur together in time for the same pool.
16 # Exit codes:
17 # 0: notification sent
18 # 1: notification failed
19 # 2: notification not configured
20 # 3: notification suppressed
22 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
23 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
25 # Rate-limit the notification based in part on the filename.
27 rate_limit_tag="${ZEVENT_POOL};${ZEVENT_SUBCLASS};${0##*/}"
28 rate_limit_interval="${ZED_NOTIFY_INTERVAL_SECS}"
29 zed_rate_limit "${rate_limit_tag}" "${rate_limit_interval}" || exit 3
31 umask 077
32 pool_str="${ZEVENT_POOL:+" for ${ZEVENT_POOL}"}"
33 host_str=" on $(hostname)"
34 note_subject="ZFS ${ZEVENT_SUBCLASS} event${pool_str}${host_str}"
35 note_pathname="$(mktemp)"
37 echo "ZFS has posted the following event:"
38 echo
39 echo " eid: ${ZEVENT_EID}"
40 echo " class: ${ZEVENT_SUBCLASS}"
41 echo " host: $(hostname)"
42 echo " time: ${ZEVENT_TIME_STRING}"
44 [ -n "${ZEVENT_VDEV_TYPE}" ] && echo " vtype: ${ZEVENT_VDEV_TYPE}"
45 [ -n "${ZEVENT_VDEV_PATH}" ] && echo " vpath: ${ZEVENT_VDEV_PATH}"
46 [ -n "${ZEVENT_VDEV_GUID}" ] && echo " vguid: ${ZEVENT_VDEV_GUID}"
48 [ -n "${ZEVENT_POOL}" ] && [ -x "${ZPOOL}" ] \
49 && "${ZPOOL}" status "${ZEVENT_POOL}"
51 } > "${note_pathname}"
53 zed_notify "${note_subject}" "${note_pathname}"; rv=$?
54 rm -f "${note_pathname}"
55 exit "${rv}"