]> git.proxmox.com Git - mirror_zfs-debian.git/blob - cmd/zed/zed.d/generic-email.sh
Imported Upstream version 0.6.4.2
[mirror_zfs-debian.git] / cmd / zed / zed.d / generic-email.sh
1 #!/bin/sh
2 #
3 # Send email to ZED_EMAIL in response to a given zevent.
4 # This is a generic script than can be symlinked to a file in the zed
5 # enabled-scripts directory in order to have email sent when a particular
6 # class of zevents occurs. The symlink filename must begin with the zevent
7 # (sub)class string (eg, "probe_failure-email.sh" for the "probe_failure"
8 # subclass). Refer to the zed(8) manpage for details.
9 # Exit codes:
10 # 0: email sent
11 # 1: email failed
12 # 2: email suppressed
13 # 3: missing executable
14 #
15 test -f "${ZED_ZEDLET_DIR}/zed.rc" && . "${ZED_ZEDLET_DIR}/zed.rc"
16
17 # Only send email if ZED_EMAIL has been configured.
18 test -n "${ZED_EMAIL}" || exit 2
19
20 # Ensure requisite executables are installed.
21 if ! command -v "${MAIL:=mail}" >/dev/null 2>&1; then
22 logger -t "${ZED_SYSLOG_TAG:=zed}" \
23 -p "${ZED_SYSLOG_PRIORITY:=daemon.warning}" \
24 `basename "$0"`: "${MAIL}" not installed
25 exit 3
26 fi
27
28 # Override the default umask to restrict access to the msgbody tmpfile.
29 umask 077
30
31 SUBJECT="ZFS ${ZEVENT_SUBCLASS} event"
32 test -n "${ZEVENT_POOL}" && SUBJECT="${SUBJECT} for ${ZEVENT_POOL}"
33 SUBJECT="${SUBJECT} on `hostname`"
34
35 MSGBODY="${TMPDIR:=/tmp}/`basename \"$0\"`.$$"
36 {
37 echo "A ZFS ${ZEVENT_SUBCLASS} event has been posted:"
38 echo
39 echo " eid: ${ZEVENT_EID}"
40 echo " host: `hostname`"
41 echo " time: ${ZEVENT_TIME_STRING}"
42 test -n "${ZEVENT_VDEV_TYPE}" -a -n "${ZEVENT_VDEV_PATH}" && \
43 echo " vdev: ${ZEVENT_VDEV_TYPE}:${ZEVENT_VDEV_PATH}"
44 test -n "${ZEVENT_POOL}" -a -x "${ZPOOL}" && \
45 "${ZPOOL}" status "${ZEVENT_POOL}"
46 } > "${MSGBODY}"
47
48 test -f "${MSGBODY}" && "${MAIL}" -s "${SUBJECT}" "${ZED_EMAIL}" < "${MSGBODY}"
49 MAIL_STATUS=$?
50 rm -f "${MSGBODY}"
51
52 if test "${MAIL_STATUS}" -ne 0; then
53 logger -t "${ZED_SYSLOG_TAG:=zed}" \
54 -p "${ZED_SYSLOG_PRIORITY:=daemon.warning}" \
55 `basename "$0"`: "${MAIL}" exit="${MAIL_STATUS}"
56 exit 1
57 fi
58
59 exit 0