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