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' 18eda14cbcSMatt Macy# ZEVENT_VDEV_STATE_STR: 'DEGRADED', 'FAULTED' or 'REMOVED' 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" ] \ 34eda14cbcSMatt Macy && [ "${ZEVENT_VDEV_STATE_STR}" != "REMOVED" ]; then 35eda14cbcSMatt Macy exit 3 36eda14cbcSMatt Macyfi 37eda14cbcSMatt Macy 38eda14cbcSMatt Macyumask 077 39eda14cbcSMatt Macynote_subject="ZFS device fault for pool ${ZEVENT_POOL_GUID} on $(hostname)" 40*16038816SMartin Matuskanote_pathname="$(mktemp)" 41eda14cbcSMatt Macy{ 42eda14cbcSMatt Macy if [ "${ZEVENT_VDEV_STATE_STR}" = "FAULTED" ] ; then 43eda14cbcSMatt Macy echo "The number of I/O errors associated with a ZFS device exceeded" 44eda14cbcSMatt Macy echo "acceptable levels. ZFS has marked the device as faulted." 45eda14cbcSMatt Macy elif [ "${ZEVENT_VDEV_STATE_STR}" = "DEGRADED" ] ; then 46eda14cbcSMatt Macy echo "The number of checksum errors associated with a ZFS device" 47eda14cbcSMatt Macy echo "exceeded acceptable levels. ZFS has marked the device as" 48eda14cbcSMatt Macy echo "degraded." 49eda14cbcSMatt Macy else 50eda14cbcSMatt Macy echo "ZFS has detected that a device was removed." 51eda14cbcSMatt Macy fi 52eda14cbcSMatt Macy 53eda14cbcSMatt Macy echo 54eda14cbcSMatt Macy echo " impact: Fault tolerance of the pool may be compromised." 55eda14cbcSMatt Macy echo " eid: ${ZEVENT_EID}" 56eda14cbcSMatt Macy echo " class: ${ZEVENT_SUBCLASS}" 57eda14cbcSMatt Macy echo " state: ${ZEVENT_VDEV_STATE_STR}" 58eda14cbcSMatt Macy echo " host: $(hostname)" 59eda14cbcSMatt Macy echo " time: ${ZEVENT_TIME_STRING}" 60eda14cbcSMatt Macy 61eda14cbcSMatt Macy [ -n "${ZEVENT_VDEV_TYPE}" ] && echo " vtype: ${ZEVENT_VDEV_TYPE}" 62eda14cbcSMatt Macy [ -n "${ZEVENT_VDEV_PATH}" ] && echo " vpath: ${ZEVENT_VDEV_PATH}" 63eda14cbcSMatt Macy [ -n "${ZEVENT_VDEV_PHYSPATH}" ] && echo " vphys: ${ZEVENT_VDEV_PHYSPATH}" 64eda14cbcSMatt Macy [ -n "${ZEVENT_VDEV_GUID}" ] && echo " vguid: ${ZEVENT_VDEV_GUID}" 65eda14cbcSMatt Macy [ -n "${ZEVENT_VDEV_DEVID}" ] && echo " devid: ${ZEVENT_VDEV_DEVID}" 66eda14cbcSMatt Macy 67eda14cbcSMatt Macy echo " pool: ${ZEVENT_POOL_GUID}" 68eda14cbcSMatt Macy 69eda14cbcSMatt Macy} > "${note_pathname}" 70eda14cbcSMatt Macy 71eda14cbcSMatt Macyzed_notify "${note_subject}" "${note_pathname}"; rv=$? 72eda14cbcSMatt Macy 73eda14cbcSMatt Macyrm -f "${note_pathname}" 74eda14cbcSMatt Macyexit "${rv}" 75