xref: /freebsd/sys/contrib/openzfs/cmd/zed/zed.d/statechange-notify.sh (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1#!/bin/sh
2# shellcheck disable=SC2154
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License Version 1.0 (CDDL-1.0).
8# You can obtain a copy of the license from the top-level file
9# "OPENSOLARIS.LICENSE" or at <http://opensource.org/licenses/CDDL-1.0>.
10# You may not use this file except in compliance with the license.
11#
12# CDDL HEADER END
13#
14
15#
16# Send notification in response to a fault induced statechange
17#
18# ZEVENT_SUBCLASS: 'statechange'
19# ZEVENT_VDEV_STATE_STR: 'DEGRADED', 'FAULTED', 'REMOVED', or 'UNAVAIL'
20#
21# Exit codes:
22#   0: notification sent
23#   1: notification failed
24#   2: notification not configured
25#   3: statechange not relevant
26#   4: statechange string missing (unexpected)
27
28[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
29. "${ZED_ZEDLET_DIR}/zed-functions.sh"
30
31[ -n "${ZEVENT_VDEV_STATE_STR}" ] || exit 4
32
33if [ "${ZEVENT_VDEV_STATE_STR}" != "FAULTED" ] \
34        && [ "${ZEVENT_VDEV_STATE_STR}" != "DEGRADED" ] \
35        && [ "${ZEVENT_VDEV_STATE_STR}" != "REMOVED" ] \
36        && [ "${ZEVENT_VDEV_STATE_STR}" != "UNAVAIL" ]; then
37    exit 3
38fi
39
40umask 077
41note_subject="ZFS device fault for pool ${ZEVENT_POOL} on $(hostname)"
42note_pathname="$(mktemp)"
43{
44    if [ "${ZEVENT_VDEV_STATE_STR}" = "FAULTED" ] ; then
45        echo "The number of I/O errors associated with a ZFS device exceeded"
46        echo "acceptable levels. ZFS has marked the device as faulted."
47    elif [ "${ZEVENT_VDEV_STATE_STR}" = "DEGRADED" ] ; then
48        echo "The number of checksum errors associated with a ZFS device"
49        echo "exceeded acceptable levels. ZFS has marked the device as"
50        echo "degraded."
51    else
52        echo "ZFS has detected that a device was removed."
53    fi
54
55    echo
56    echo " impact: Fault tolerance of the pool may be compromised."
57    echo "    eid: ${ZEVENT_EID}"
58    echo "  class: ${ZEVENT_SUBCLASS}"
59    echo "  state: ${ZEVENT_VDEV_STATE_STR}"
60    echo "   host: $(hostname)"
61    echo "   time: ${ZEVENT_TIME_STRING}"
62
63    [ -n "${ZEVENT_VDEV_TYPE}" ] && echo "  vtype: ${ZEVENT_VDEV_TYPE}"
64    [ -n "${ZEVENT_VDEV_PATH}" ] && echo "  vpath: ${ZEVENT_VDEV_PATH}"
65    [ -n "${ZEVENT_VDEV_PHYSPATH}" ] && echo "  vphys: ${ZEVENT_VDEV_PHYSPATH}"
66    [ -n "${ZEVENT_VDEV_GUID}" ] && echo "  vguid: ${ZEVENT_VDEV_GUID}"
67    [ -n "${ZEVENT_VDEV_DEVID}" ] && echo "  devid: ${ZEVENT_VDEV_DEVID}"
68
69    echo "   pool: ${ZEVENT_POOL} (${ZEVENT_POOL_GUID})"
70
71} > "${note_pathname}"
72
73zed_notify "${note_subject}" "${note_pathname}"; rv=$?
74
75rm -f "${note_pathname}"
76exit "${rv}"
77