xref: /freebsd/sys/contrib/openzfs/cmd/zed/zed.d/data-notify.sh (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1#!/bin/sh
2#
3# Send notification in response to a DATA error.
4#
5# Only one notification per ZED_NOTIFY_INTERVAL_SECS will be sent for a given
6# class/pool/[vdev] combination.  This protects against spamming the recipient
7# should multiple events occur together in time for the same pool/[vdev].
8#
9# Exit codes:
10#   0: notification sent
11#   1: notification failed
12#   2: notification not configured
13#   3: notification suppressed
14#   9: internal error
15
16[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
17. "${ZED_ZEDLET_DIR}/zed-functions.sh"
18
19[ -n "${ZEVENT_POOL}" ] || exit 9
20[ -n "${ZEVENT_SUBCLASS}" ] || exit 9
21[ -n "${ZED_NOTIFY_DATA}" ] || exit 3
22
23rate_limit_tag="${ZEVENT_POOL};${ZEVENT_VDEV_GUID:-0};${ZEVENT_SUBCLASS};notify"
24zed_rate_limit "${rate_limit_tag}" || exit 3
25
26umask 077
27note_subject="ZFS ${ZEVENT_SUBCLASS} error for ${ZEVENT_POOL} on $(hostname)"
28note_pathname="${TMPDIR:="/tmp"}/$(basename -- "$0").${ZEVENT_EID}.$$"
29{
30    echo "ZFS has detected a data error:"
31    echo
32    echo "   eid: ${ZEVENT_EID}"
33    echo " class: ${ZEVENT_SUBCLASS}"
34    echo "  host: $(hostname)"
35    echo "  time: ${ZEVENT_TIME_STRING}"
36    echo " error: ${ZEVENT_ZIO_ERR}"
37    echo " objid: ${ZEVENT_ZIO_OBJSET}:${ZEVENT_ZIO_OBJECT}"
38    echo "  pool: ${ZEVENT_POOL}"
39} > "${note_pathname}"
40
41zed_notify "${note_subject}" "${note_pathname}"; rv=$?
42rm -f "${note_pathname}"
43exit "${rv}"
44