diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-08-19 15:03:36 +0300 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-08-19 15:03:36 +0300 |
commit | 87149271a60a4cea1f8e739a8037e3fdd22d9fb7 (patch) | |
tree | ff4ece826d6ef29fdc87760a7cccd14e6deff2b3 /plugins.d | |
parent | 918919e46c4e76aad12e9f1495d81719ea8bf343 (diff) |
send emails using -f and -F sendmail options to support sender verification; fixes #2586
Diffstat (limited to 'plugins.d')
-rwxr-xr-x | plugins.d/alarm-notify.sh | 33 |
1 files changed, 27 insertions, 6 deletions
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 |