@cryptotaxi247 / netdata-1 / commits / 87149271a

send emails using -f and -F sendmail options to support sender verification; fixes #2586

Costa Tsaousis (ktsaou) committed Aug 19, 2017 at 15:03 UTC 87149271a60a4cea1f8e739a8037e3fdd22d9fb7
2 files changed +32 -6
conf.d/health_alarm_notify.conf
+5
@@ -96,6 +96,11 @@ curl=""
96
97 # the email address sending email notifications
98 # the default is the system user netdata runs as (usually: netdata)
99 +# The following formats are supported:
100 +# EMAIL_SENDER="user@domain"
101 +# EMAIL_SENDER="User Name <user@domain>"
102 +# EMAIL_SENDER="'User Name' <user@domain>"
103 +# EMAIL_SENDER="\"User Name\" <user@domain>"
104 EMAIL_SENDER=""
105
106 # enable/disable sending emails
plugins.d/alarm-notify.sh
+27 -6
@@ -288,7 +288,7 @@ DEFAULT_RECIPIENT_CUSTOM=
288 declare -A role_recipients_custom=()
289
290 # email configs
291 -EMAIL_SENDER=""
291 +EMAIL_SENDER=
292 DEFAULT_RECIPIENT_EMAIL="root"
293 EMAIL_CHARSET=$(locale charmap 2>/dev/null)
294 declare -A role_recipients_email=()
@@ -703,11 +703,35 @@ duration4human() {
703 # email sender
704
705 send_email() {
706 - local ret=
706 + local ret= opts=
707 if [ "${SEND_EMAIL}" = "YES" ]
708 then
709
710 - "${sendmail}" -t
710 + if [ ! -z "${EMAIL_SENDER}" ]
711 + then
712 + if [[ "${EMAIL_SENDER}" =~ \".*\"\ \<.*\> ]]
713 + then
714 + opts=" -f '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)' -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
715 + elif [[ "${EMAIL_SENDER}" =~ \'.*\'\ \<.*\> ]]
716 + then
717 + opts=" -f '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)' -F $(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
718 + elif [[ "${EMAIL_SENDER}" =~ .*\ \<.*\> ]]
719 + then
720 + opts=" -f '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)' -F '$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)'"
721 + else
722 + opts=" -f '${EMAIL_SENDER}'"
723 + fi
724 + fi
725 +
726 + if [ "${debug}" = "1" ]
727 + then
728 + echo >&2 "--- BEGIN sendmail command ---"
729 + printf >&2 "%q " "${sendmail}" -t ${opts}
730 + echo >&2
731 + echo >&2 "--- END sendmail command ---"
732 + fi
733 +
734 + "${sendmail}" -t ${opts}
735 ret=$?
736
737 if [ ${ret} -eq 0 ]
@@ -1398,10 +1422,7 @@ SENT_HIPCHAT=$?
1422 # -----------------------------------------------------------------------------
1423 # send the email
1424
1401 -[ -z "${EMAIL_SENDER}" ] && EMAIL_SENDER="${USER-netdata}"
1402 -
1425 send_email <<EOF
1404 -From: ${EMAIL_SENDER}
1426 To: ${to_email}
1427 Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
1428 MIME-Version: 1.0