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