diff options
-rw-r--r-- | conf.d/health_alarm_notify.conf | 5 | ||||
-rwxr-xr-x | plugins.d/alarm-notify.sh | 33 |
2 files changed, 32 insertions, 6 deletions
diff --git a/conf.d/health_alarm_notify.conf b/conf.d/health_alarm_notify.conf index 48560a64db..641272ceda 100644 --- a/conf.d/health_alarm_notify.conf +++ b/conf.d/health_alarm_notify.conf @@ -96,6 +96,11 @@ curl="" # the email address sending email notifications # the default is the system user netdata runs as (usually: netdata) +# The following formats are supported: +# EMAIL_SENDER="user@domain" +# EMAIL_SENDER="User Name <user@domain>" +# EMAIL_SENDER="'User Name' <user@domain>" +# EMAIL_SENDER="\"User Name\" <user@domain>" EMAIL_SENDER="" # enable/disable sending emails diff --git a/plugins.d/alarm-notify.sh b/plugins.d/alarm-notify.sh index ddfae68ddf..5367841e63 100755 --- a/plugins.d/alarm-notify.sh +++ b/plugins.d/alarm-notify.sh @@ -288,7 +288,7 @@ DEFAULT_RECIPIENT_CUSTOM= declare -A role_recipients_custom=() # email configs -EMAIL_SENDER="" +EMAIL_SENDER= DEFAULT_RECIPIENT_EMAIL="root" EMAIL_CHARSET=$(locale charmap 2>/dev/null) declare -A role_recipients_email=() @@ -703,11 +703,35 @@ duration4human() { # email sender send_email() { - local ret= + local ret= opts= if [ "${SEND_EMAIL}" = "YES" ] then - "${sendmail}" -t + if [ ! -z "${EMAIL_SENDER}" ] + then + if [[ "${EMAIL_SENDER}" =~ \".*\"\ \<.*\> ]] + then + opts=" -f '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)' -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)" + elif [[ "${EMAIL_SENDER}" =~ \'.*\'\ \<.*\> ]] + then + opts=" -f '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)' -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)" + elif [[ "${EMAIL_SENDER}" =~ .*\ \<.*\> ]] + then + opts=" -f '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)' -F '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)'" + else + opts=" -f '${EMAIL_SENDER}'" + fi + fi + + if [ "${debug}" = "1" ] + then + echo >&2 "--- BEGIN sendmail command ---" + printf >&2 "%q " "${sendmail}" -t ${opts} + echo >&2 + echo >&2 "--- END sendmail command ---" + fi + + "${sendmail}" -t ${opts} ret=$? if [ ${ret} -eq 0 ] @@ -1398,10 +1422,7 @@ SENT_HIPCHAT=$? # ----------------------------------------------------------------------------- # send the email -[ -z "${EMAIL_SENDER}" ] && EMAIL_SENDER="${USER-netdata}" - send_email <<EOF -From: ${EMAIL_SENDER} To: ${to_email} Subject: ${host} ${status_message} - ${name//_/ } - ${chart} MIME-Version: 1.0 |