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