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