summaryrefslogtreecommitdiffstats
path: root/plugins.d
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <ahferroin7@gmail.com>2017-08-15 08:43:51 -0400
committerAustin S. Hemmelgarn <ahferroin7@gmail.com>2017-08-15 08:43:51 -0400
commit8b8ba4849d27615e2f7fc4b3c5a8ff44e8958a30 (patch)
treecc5d04e4ec7be95f673a47390a51f663c0d91a30 /plugins.d
parent4e79eb91a517e88a022e9604c407fccaffc56f26 (diff)
Further reduce spam score by adding encoding info.
A lot of spam filters are more likely to flag email without an encoding in the Content-Type headers as spam. Netdata is technically not locale aware, but the email message is sent from a bash script, and bash is locale aware, so the message will be encoded in whatever the environment dictated character encoding is (which is usually UTF-8) these days. It turns out that my assessment in the previous commit was incorrect, and it actually is trivial to get a MIME compatible encoding name from a shell script, so lets try to make sure the encoding is set automatically. When not explicitly set by the user, we first try to determine the system encoding using the `locale` command. If this fails and the user has not explicitly set an encoding, then it defaults to UTF-8, which is the de-facto standard on all modern Linux distributions and thus should be correct most of the time. Users can override the detection by setting EMAIL_CHARSET in health_alarm_notify.conf. For English speaking users, this should result in no change. For non-English speaking users, this may fix display of non-punycode encoded hostnames.
Diffstat (limited to 'plugins.d')
-rwxr-xr-xplugins.d/alarm-notify.sh13
1 files changed, 11 insertions, 2 deletions
diff --git a/plugins.d/alarm-notify.sh b/plugins.d/alarm-notify.sh
index 1c0c1d548b..ddfae68ddf 100755
--- a/plugins.d/alarm-notify.sh
+++ b/plugins.d/alarm-notify.sh
@@ -290,6 +290,7 @@ declare -A role_recipients_custom=()
# email configs
EMAIL_SENDER=""
DEFAULT_RECIPIENT_EMAIL="root"
+EMAIL_CHARSET=$(locale charmap 2>/dev/null)
declare -A role_recipients_email=()
# load the user configuration
@@ -301,6 +302,14 @@ else
error "Cannot find file ${NETDATA_CONFIG_DIR}/health_alarm_notify.conf. Using internal defaults."
fi
+# If we didn't autodetect the character set for e-mail and it wasn't
+# set by the user, we need to set it to a reasonable default. UTF-8
+# should be correct for almost all modern UNIX systems.
+if [ -z ${EMAIL_CHARSET} ]
+ then
+ EMAIL_CHARSET="UTF-8"
+fi
+
# -----------------------------------------------------------------------------
# filter a recipient based on alarm event severity
@@ -1401,7 +1410,7 @@ Content-Type: multipart/alternative; boundary="multipart-boundary"
This is a MIME-encoded multipart message
--multipart-boundary
-Content-Type: text/plain
+Content-Type: text/plain; encoding=${EMAIL_CHARSET}
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
@@ -1419,7 +1428,7 @@ Date : ${date}
Notification generated on ${this_host}
--multipart-boundary
-Content-Type: text/html
+Content-Type: text/html; encoding=${EMAIL_CHARSET}
Content-Disposition: inline
Content-Transfer-Encoding: 8bit