Path: blob/main/sys/contrib/openzfs/cmd/zed/zed.d/generic-notify.sh
48529 views
#!/bin/sh1# shellcheck disable=SC21542#3# Send notification in response to a given zevent.4#5# This is a generic script than can be symlinked to a file in the6# enabled-zedlets directory to have a notification sent when a particular7# class of zevents occurs. The symlink filename must begin with the zevent8# (sub)class string (e.g., "probe_failure-notify.sh" for the "probe_failure"9# subclass). Refer to the zed(8) manpage for details.10#11# Only one notification per ZED_NOTIFY_INTERVAL_SECS will be sent for a given12# class/pool combination. This protects against spamming the recipient13# should multiple events occur together in time for the same pool.14#15# Exit codes:16# 0: notification sent17# 1: notification failed18# 2: notification not configured19# 3: notification suppressed2021[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"22. "${ZED_ZEDLET_DIR}/zed-functions.sh"2324# Rate-limit the notification based in part on the filename.25#26rate_limit_tag="${ZEVENT_POOL};${ZEVENT_SUBCLASS};${0##*/}"27rate_limit_interval="${ZED_NOTIFY_INTERVAL_SECS}"28zed_rate_limit "${rate_limit_tag}" "${rate_limit_interval}" || exit 32930umask 07731pool_str="${ZEVENT_POOL:+" for ${ZEVENT_POOL}"}"32host_str=" on $(hostname)"33note_subject="ZFS ${ZEVENT_SUBCLASS} event${pool_str}${host_str}"34note_pathname="$(mktemp)"35{36echo "ZFS has posted the following event:"37echo38echo " eid: ${ZEVENT_EID}"39echo " class: ${ZEVENT_SUBCLASS}"40echo " host: $(hostname)"41echo " time: ${ZEVENT_TIME_STRING}"4243[ -n "${ZEVENT_VDEV_TYPE}" ] && echo " vtype: ${ZEVENT_VDEV_TYPE}"44[ -n "${ZEVENT_VDEV_PATH}" ] && echo " vpath: ${ZEVENT_VDEV_PATH}"45[ -n "${ZEVENT_VDEV_GUID}" ] && echo " vguid: ${ZEVENT_VDEV_GUID}"4647[ -n "${ZEVENT_POOL}" ] && [ -x "${ZPOOL}" ] \48&& "${ZPOOL}" status "${ZEVENT_POOL}"4950} > "${note_pathname}"5152zed_notify "${note_subject}" "${note_pathname}"; rv=$?53rm -f "${note_pathname}"54exit "${rv}"555657