aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/zed/zed.d
diff options
context:
space:
mode:
authorChris Dunlap <[email protected]>2015-07-28 15:52:40 -0700
committerBrian Behlendorf <[email protected]>2015-07-30 11:52:56 -0700
commit69520d6855d962885e9ec4e2614575bb39c6326b (patch)
tree95364c964fe57bd19fd21f162997bdebd38caeee /cmd/zed/zed.d
parent6f1eccff2c264bf44c63ca40a9279fffc3b5d5b5 (diff)
Rework zed_notify_email for configurable PROG/OPTS
This commit reworks the zed_notify_email() function to allow configuration of the mail executable and command-line arguments. ZED_EMAIL_PROG specifies the name or path of the executable responsible for sending notifications via email. This variable defaults to "mail". ZED_EMAIL_OPTS specifies command-line options passed to ZED_EMAIL_PROG. The following keyword substitutions are performed: - @ADDRESS@ is replaced with the recipient email address(es) - @SUBJECT@ is replaced with the notification subject This variable defaults to "-s '@SUBJECT@' @ADDRESS@". ZED_EMAIL_ADDR replaces ZED_EMAIL (although the latter is retained for backward compatibility). This variable can contain multiple addresses as long as they are delimited by whitespace. Signed-off-by: Chris Dunlap <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #3634 Closes #3631
Diffstat (limited to 'cmd/zed/zed.d')
-rw-r--r--cmd/zed/zed.d/zed-functions.sh39
-rw-r--r--cmd/zed/zed.d/zed.rc23
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.