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