Path: blob/main/sys/contrib/openzfs/cmd/zed/zed.d/statechange-notify.sh
48529 views
#!/bin/sh1# SPDX-License-Identifier: CDDL-1.02# shellcheck disable=SC21543#4# CDDL HEADER START5#6# The contents of this file are subject to the terms of the7# Common Development and Distribution License Version 1.0 (CDDL-1.0).8# You can obtain a copy of the license from the top-level file9# "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 END13#1415#16# Send notification in response to a fault induced statechange17#18# ZEVENT_SUBCLASS: 'statechange'19# ZEVENT_VDEV_STATE_STR: 'DEGRADED', 'FAULTED', 'REMOVED', or 'UNAVAIL'20#21# Exit codes:22# 0: notification sent23# 1: notification failed24# 2: notification not configured25# 3: statechange not relevant26# 4: statechange string missing (unexpected)2728[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"29. "${ZED_ZEDLET_DIR}/zed-functions.sh"3031[ -n "${ZEVENT_VDEV_STATE_STR}" ] || exit 43233if [ "${ZEVENT_VDEV_STATE_STR}" != "FAULTED" ] \34&& [ "${ZEVENT_VDEV_STATE_STR}" != "DEGRADED" ] \35&& [ "${ZEVENT_VDEV_STATE_STR}" != "REMOVED" ] \36&& [ "${ZEVENT_VDEV_STATE_STR}" != "UNAVAIL" ]; then37exit 338fi3940umask 07741note_subject="ZFS device fault for pool ${ZEVENT_POOL} on $(hostname)"42note_pathname="$(mktemp)"43{44if [ "${ZEVENT_VDEV_STATE_STR}" = "FAULTED" ] ; then45echo "The number of I/O errors associated with a ZFS device exceeded"46echo "acceptable levels. ZFS has marked the device as faulted."47elif [ "${ZEVENT_VDEV_STATE_STR}" = "DEGRADED" ] ; then48echo "The number of checksum errors associated with a ZFS device"49echo "exceeded acceptable levels. ZFS has marked the device as"50echo "degraded."51else52echo "ZFS has detected that a device was removed."53fi5455echo56echo " impact: Fault tolerance of the pool may be compromised."57echo " eid: ${ZEVENT_EID}"58echo " class: ${ZEVENT_SUBCLASS}"59echo " state: ${ZEVENT_VDEV_STATE_STR}"60echo " host: $(hostname)"61echo " time: ${ZEVENT_TIME_STRING}"6263[ -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}"6869echo " pool: ${ZEVENT_POOL} (${ZEVENT_POOL_GUID})"7071} > "${note_pathname}"7273zed_notify "${note_subject}" "${note_pathname}"; rv=$?7475rm -f "${note_pathname}"76exit "${rv}"777879