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