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