@cryptotaxi247 / netdata-1 / commits / 7c9ba1dc4

Add the option to thread email notifications.

This adds a new configuration option in health_alarm_nofity.conf to insert In-Reply-To and References haders in email notifications. The contents of these headers are composed in a deterministic way from the chart name, alarm name, and host name. This allows email clients to sort netdata alert emails into groups based on the combination of chart, alarm, and host, which can help significantly when dealing with a large number of alerts. It also provides something for scripts that might process and filter thes emails to match on that's a bit easier to parse than the subject line. We default to not enabling this so that people who have their e-mail clients configured for threaded reading don't see an unexpected change in behavior. Strictly speaking, this is technically a misuse of the headers, as they are supposed to only reference the Message-ID header of an existing e-mail. However, I know of no e-mail clients that enforce standards compliant behavior (as it would break threading picked up partway through a thread), so we should be safe. Minimally tested (using the test-alert.sh script and running for a short while on a server where I synthetically induced lots of alerts).

Austin S. Hemmelgarn committed May 29, 2018 at 16:29 UTC 7c9ba1dc41d97f17343b10945851cb7cf94d6cb3
2 files changed +18
conf.d/health_alarm_notify.conf
+8
@@ -171,6 +171,14 @@ DEFAULT_RECIPIENT_EMAIL="root"
171 # autodetected from the environment.
172 #EMAIL_CHARSET="UTF-8"
173
174 +# You can also have netdata add headers to the message that will
175 +# cause most e-mail clients to treat all notifications for a given
176 +# chart+alarm+host combination as a single thread. This can help
177 +# simplify tracking of alarms, as it provides an easy wway for scripts
178 +# to corelate messages and also will cause most clients to group all the
179 +# messages together. THis is off by default.
180 +#EMAIL_THREADING="YES"
181 +
182
183 #------------------------------------------------------------------------------
184 # pushover (pushover.net) global notification options
plugins.d/alarm-notify.sh
+10
@@ -326,6 +326,7 @@ declare -A role_recipients_custom=()
326 EMAIL_SENDER=
327 DEFAULT_RECIPIENT_EMAIL="root"
328 EMAIL_CHARSET=$(locale charmap 2>/dev/null)
329 +EMAIL_THREADING=
330 declare -A role_recipients_email=()
331
332 # irc configs
@@ -781,6 +782,14 @@ date=$(date --date=@${when} "${date_format}" 2>/dev/null)
782 [ -z "${date}" ] && date=$(date --date=@${when} 2>/dev/null)
783 [ -z "${date}" ] && date=$(date 2>/dev/null)
784
785 +# ----------------------------------------------------------------------------
786 +# prepare some extra headers if we've been asked to thread e-mails
787 +if [ "${SEND_EMAIL}" == "YES" -a "${EMAIL_THREADING}" == "YES" ] ; then
788 + email_thread_headers="In-Reply-To: <${chart}-${name}@${host}>\nReferences: <${chart}-${name}@${host}>"
789 +else
790 + email_thread_headers=
791 +fi
792 +
793 # -----------------------------------------------------------------------------
794 # function to URL encode a string
795
@@ -1891,6 +1900,7 @@ To: ${to_email}
1900 Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
1901 MIME-Version: 1.0
1902 Content-Type: multipart/alternative; boundary="multipart-boundary"
1903 +${email_thread_headers}
1904
1905 This is a MIME-encoded multipart message
1906