diff options
-rw-r--r-- | cmd/zed/zed.d/zed-functions.sh | 39 | ||||
-rw-r--r-- | cmd/zed/zed.d/zed.rc | 23 |
2 files changed, 51 insertions, 11 deletions
diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh index 83c36ba6f..1ddafa99f 100644 --- a/cmd/zed/zed.d/zed-functions.sh +++ b/cmd/zed/zed.d/zed-functions.sh @@ -207,16 +207,25 @@ zed_notify() # zed_notify_email (subject, pathname) # -# Send a notification via email to the address specified by ZED_EMAIL. +# Send a notification via email to the address specified by ZED_EMAIL_ADDR. # -# Requires the mail executable to be installed in the standard PATH. +# Requires the mail executable to be installed in the standard PATH, or +# ZED_EMAIL_PROG to be defined with the pathname of an executable capable of +# reading a message body from stdin. +# +# Command-line options to the mail executable can be specified in +# ZED_EMAIL_OPTS. This undergoes the following keyword substitutions: +# - @ADDRESS@ is replaced with the space-delimited recipient email address(es) +# - @SUBJECT@ is replaced with the notification subject # # Arguments # subject: notification subject # pathname: pathname containing the notification message (OPTIONAL) # # Globals -# ZED_EMAIL +# ZED_EMAIL_PROG +# ZED_EMAIL_OPTS +# ZED_EMAIL_ADDR # # Return # 0: notification sent @@ -228,19 +237,33 @@ zed_notify_email() local subject="$1" local pathname="${2:-"/dev/null"}" - [ -n "${ZED_EMAIL}" ] || return 2 + : "${ZED_EMAIL_PROG:="mail"}" + : "${ZED_EMAIL_OPTS:="-s '@SUBJECT@' @ADDRESS@"}" + + # For backward compatibility with ZED_EMAIL. + if [ -n "${ZED_EMAIL}" ] && [ -z "${ZED_EMAIL_ADDR}" ]; then + ZED_EMAIL_ADDR="${ZED_EMAIL}" + fi + [ -n "${ZED_EMAIL_ADDR}" ] || return 2 + + zed_check_cmd "${ZED_EMAIL_PROG}" || return 1 [ -n "${subject}" ] || return 1 if [ ! -r "${pathname}" ]; then - zed_log_err "mail cannot read \"${pathname}\"" + zed_log_err \ + "$(basename "${ZED_EMAIL_PROG}") cannot read \"${pathname}\"" return 1 fi - zed_check_cmd "mail" || return 1 + ZED_EMAIL_OPTS="$(echo "${ZED_EMAIL_OPTS}" \ + | sed -e "s/@ADDRESS@/${ZED_EMAIL_ADDR}/g" \ + -e "s/@SUBJECT@/${subject}/g")" - mail -s "${subject}" "${ZED_EMAIL}" < "${pathname}" >/dev/null 2>&1; rv=$? + # shellcheck disable=SC2086 + eval "${ZED_EMAIL_PROG}" ${ZED_EMAIL_OPTS} < "${pathname}" >/dev/null 2>&1 + rv=$? if [ "${rv}" -ne 0 ]; then - zed_log_err "mail exit=${rv}" + zed_log_err "$(basename "${ZED_EMAIL_PROG}") exit=${rv}" return 1 fi return 0 diff --git a/cmd/zed/zed.d/zed.rc b/cmd/zed/zed.d/zed.rc index c2336287f..f80fa3338 100644 --- a/cmd/zed/zed.d/zed.rc +++ b/cmd/zed/zed.d/zed.rc @@ -10,11 +10,28 @@ #ZED_DEBUG_LOG="/tmp/zed.debug.log" ## -# Email address of the zpool administrator for receipt of notifications. -# Email will only be sent if ZED_EMAIL is defined. +# Email address of the zpool administrator for receipt of notifications; +# multiple addresses can be specified if they are delimited by whitespace. +# Email will only be sent if ZED_EMAIL_ADDR is defined. # Disabled by default; uncomment to enable. # -#ZED_EMAIL="root" +#ZED_EMAIL_ADDR="root" + +## +# Name or path of executable responsible for sending notifications via email; +# the mail program must be capable of reading a message body from stdin. +# Email will only be sent if ZED_EMAIL_ADDR is defined. +# +#ZED_EMAIL_PROG="mail" + +## +# Command-line options for ZED_EMAIL_PROG. +# The string @ADDRESS@ will be replaced with the recipient email address(es). +# The string @SUBJECT@ will be replaced with the notification subject; +# this should be protected with quotes to prevent word-splitting. +# Email will only be sent if ZED_EMAIL_ADDR is defined. +# +#ZED_EMAIL_OPTS="-s '@SUBJECT@' @ADDRESS@" ## # Default directory for zed lock files. |