xref: /freebsd/sys/contrib/openzfs/cmd/zed/zed.d/data-notify.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#!/bin/sh
2# shellcheck disable=SC2154
3#
4# Send notification in response to a DATA error.
5#
6# Only one notification per ZED_NOTIFY_INTERVAL_SECS will be sent for a given
7# class/pool/[vdev] combination.  This protects against spamming the recipient
8# should multiple events occur together in time for the same pool/[vdev].
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[ -n "${ZED_NOTIFY_DATA}" ] || exit 3
23
24rate_limit_tag="${ZEVENT_POOL};${ZEVENT_VDEV_GUID:-0};${ZEVENT_SUBCLASS};notify"
25zed_rate_limit "${rate_limit_tag}" || exit 3
26
27umask 077
28note_subject="ZFS ${ZEVENT_SUBCLASS} error for ${ZEVENT_POOL} on $(hostname)"
29note_pathname="$(mktemp)"
30{
31    echo "ZFS has detected a data error:"
32    echo
33    echo "   eid: ${ZEVENT_EID}"
34    echo " class: ${ZEVENT_SUBCLASS}"
35    echo "  host: $(hostname)"
36    echo "  time: ${ZEVENT_TIME_STRING}"
37    echo " error: ${ZEVENT_ZIO_ERR}"
38    echo " objid: ${ZEVENT_ZIO_OBJSET}:${ZEVENT_ZIO_OBJECT}"
39    echo "  pool: ${ZEVENT_POOL}"
40} > "${note_pathname}"
41
42zed_notify "${note_subject}" "${note_pathname}"; rv=$?
43rm -f "${note_pathname}"
44exit "${rv}"
45