mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 18:11:00 +03:00
9e246ac3d8
zed monitors ZFS events. When a zevent is posted, zed will run any scripts that have been enabled for the corresponding zevent class. Multiple scripts may be invoked for a given zevent. The zevent nvpairs are passed to the scripts as environment variables. Events are processed synchronously by the single thread, and there is no maximum timeout for script execution. Consequently, a misbehaving script can delay (or forever block) the processing of subsequent zevents. Plans are to address this in future commits. Initial scripts have been developed to log events to syslog and send email in response to checksum/data/io errors and resilver.finish/scrub.finish events. By default, email will only be sent if the ZED_EMAIL variable is configured in zed.rc (which is serving as a config file of sorts until a proper configuration file is implemented). Signed-off-by: Chris Dunlap <cdunlap@llnl.gov> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #2
60 lines
1.9 KiB
Bash
Executable File
60 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Send email to ZED_EMAIL in response to a given zevent.
|
|
# This is a generic script than can be symlinked to a file in the zed
|
|
# enabled-scripts directory in order to have email sent when a particular
|
|
# class of zevents occurs. The symlink filename must begin with the zevent
|
|
# (sub)class string (eg, "probe_failure-email.sh" for the "probe_failure"
|
|
# subclass). Refer to the zed(8) manpage for details.
|
|
# Exit codes:
|
|
# 0: email sent
|
|
# 1: email failed
|
|
# 2: email suppressed
|
|
# 3: missing executable
|
|
#
|
|
test -f "${ZED_SCRIPT_DIR}/zed.rc" && . "${ZED_SCRIPT_DIR}/zed.rc"
|
|
|
|
# Only send email if ZED_EMAIL has been configured.
|
|
test -n "${ZED_EMAIL}" || exit 2
|
|
|
|
# Ensure requisite executables are installed.
|
|
if ! command -v "${MAIL:=mail}" >/dev/null 2>&1; then
|
|
logger -t "${ZED_SYSLOG_TAG:=zed}" \
|
|
-p "${ZED_SYSLOG_PRIORITY:=daemon.warning}" \
|
|
`basename "$0"`: "${MAIL}" not installed
|
|
exit 3
|
|
fi
|
|
|
|
# Override the default umask to restrict access to the msgbody tmpfile.
|
|
umask 077
|
|
|
|
SUBJECT="ZFS ${ZEVENT_SUBCLASS} event"
|
|
test -n "${ZEVENT_POOL}" && SUBJECT="${SUBJECT} for ${ZEVENT_POOL}"
|
|
SUBJECT="${SUBJECT} on `hostname`"
|
|
|
|
MSGBODY="${TMPDIR:=/tmp}/`basename \"$0\"`.$$"
|
|
{
|
|
echo "A ZFS ${ZEVENT_SUBCLASS} event has been posted:"
|
|
echo
|
|
echo " eid: ${ZEVENT_EID}"
|
|
echo " host: `hostname`"
|
|
echo " time: ${ZEVENT_TIME_STRING}"
|
|
test -n "${ZEVENT_VDEV_TYPE}" -a -n "${ZEVENT_VDEV_PATH}" && \
|
|
echo " vdev: ${ZEVENT_VDEV_TYPE}:${ZEVENT_VDEV_PATH}"
|
|
test -n "${ZEVENT_POOL}" -a -x "${ZPOOL}" && \
|
|
"${ZPOOL}" status "${ZEVENT_POOL}"
|
|
} > "${MSGBODY}"
|
|
|
|
test -f "${MSGBODY}" && "${MAIL}" -s "${SUBJECT}" "${ZED_EMAIL}" < "${MSGBODY}"
|
|
MAIL_STATUS=$?
|
|
rm -f "${MSGBODY}"
|
|
|
|
if test "${MAIL_STATUS}" -ne 0; then
|
|
logger -t "${ZED_SYSLOG_TAG:=zed}" \
|
|
-p "${ZED_SYSLOG_PRIORITY:=daemon.warning}" \
|
|
`basename "$0"`: "${MAIL}" exit="${MAIL_STATUS}"
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|