@cryptotaxi247 / netdata-1 / commits / 01e2f26c2

Add support for providing FQDN in alarm notifications. (#4943)

##### Summary This adds an option to alarm-notify.sh to make it use the system's FQDN instead of it's simple hostname when sending alarm notifications. This can be enabled by adding `use_fqdn="YES"` to `health_alarm_notify.conf`. This does not work correctly for alarms being sent by a master node on behalf of a slave system, and includes an explicit check so that it falls back to just sending the simple hostname in such cases. This commit also cleans up misuse of the `${this_host}` variable, which is supposed to just be a temporary variable. ##### Component Name health ##### Additional Information Minimally tested, it runs correctly on my systems and does as advertised. Relevant to:#809 Fixes: #2477

Austin S. Hemmelgarn committed Dec 9, 2018 at 10:05 UTC 01e2f26c2981b583fb6c749b7e1ae14d97e0e6c8
2 files changed +44 -9
health/notifications/alarm-notify.sh.in
+26 -9
@@ -198,7 +198,7 @@ if [ ${1} = "unittest" ] ; then
198 old_status="${5}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
199 else
200 roles="${1}" # the roles that should be notified for this event
201 - host="${2}" # the host generated this event
201 + args_host="${2}" # the host generated this event
202 unique_id="${3}" # the unique id of this event
203 alarm_id="${4}" # the unique id of the alarm that generated this event
204 event_id="${5}" # the incremental id of the event, for this alarm id
@@ -222,8 +222,14 @@ fi
222 # -----------------------------------------------------------------------------
223 # find a suitable hostname to use, if netdata did not supply a hostname
224
225 -this_host=$(hostname -s 2>/dev/null)
226 -[ -z "${host}" ] && host="${this_host}"
225 +if [ -z ${args_host} ]
226 + then
227 + this_host=$(hostname -s 2>/dev/null)
228 + host="${this_host}"
229 + args_host="${this_host}"
230 +else
231 + host="${args_host}"
232 +fi
233
234 # -----------------------------------------------------------------------------
235 # screen statuses we don't need to send a notification
@@ -254,6 +260,9 @@ images_base_url="https://registry.my-netdata.io"
260 # curl options to use
261 curl_options=""
262
263 +# hostname handling
264 +use_fqdn="NO"
265 +
266 # needed commands
267 # if empty they will be searched in the system path
268 curl=
@@ -374,6 +383,14 @@ if [ -z ${EMAIL_CHARSET} ]
383 EMAIL_CHARSET="UTF-8"
384 fi
385
386 +# If we've been asked to use FQDN's for the URL's in the alarm, do so,
387 +# unless we're sending an alarm for a slave system which we can't get the
388 +# FQDN of easily.
389 +if [ "${use_fqdn}" = "YES" -a "${host}" = "$(hostname -s 2>/dev/null)" ]
390 + then
391 + host="$(hostname -f 2>/dev/null)"
392 +fi
393 +
394 # -----------------------------------------------------------------------------
395 # filter a recipient based on alarm event severity
396
@@ -1277,7 +1294,7 @@ send_slack() {
1294 }
1295 ],
1296 "thumb_url": "${image}",
1280 - "footer": "by <${goto_url}|${this_host}>",
1297 + "footer": "by <${goto_url}|${host}>",
1298 "ts": ${when}
1299 }
1300 ]
@@ -1410,7 +1427,7 @@ send_alerta() {
1427 "source": "${src}",
1428 "moreInfo": "<a href=\"${goto_url}\">View Netdata</a>"
1429 },
1413 - "origin": "netdata/${this_host}",
1430 + "origin": "netdata/${host}",
1431 "type": "netdataAlarm",
1432 "rawData": "${BASH_ARGV[@]}"
1433 }
@@ -1536,7 +1553,7 @@ send_discord() {
1553 ],
1554 "thumb_url": "${image}",
1555 "footer_icon": "${images_base_url}/images/banner-icon-144x144.png",
1539 - "footer": "${this_host}",
1556 + "footer": "${host}",
1557 "ts": ${when}
1558 }
1559 ]
@@ -1734,7 +1751,7 @@ send_syslog() {
1751 # prepare the content of the notification
1752
1753 # the url to send the user on click
1737 -urlencode "${host}" >/dev/null; url_host="${REPLY}"
1754 +urlencode "${args_host}" >/dev/null; url_host="${REPLY}"
1755 urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
1756 urlencode "${family}" >/dev/null; url_family="${REPLY}"
1757 urlencode "${name}" >/dev/null; url_name="${REPLY}"
@@ -2055,7 +2072,7 @@ Severity: ${severity}
2072 URL : ${goto_url}
2073 Source : ${src}
2074 Date : ${date}
2058 -Notification generated on ${this_host}
2075 +Notification generated on ${host}
2076
2077 --multipart-boundary
2078 Content-Type: text/html; encoding=${EMAIL_CHARSET}
@@ -2128,7 +2145,7 @@ Content-Transfer-Encoding: 8bit
2145 </tr>
2146 <tr style="text-align: center; margin: 0; padding: 0;">
2147 <td style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; vertical-align: top; margin:0; padding: 20px 0 0 0; color: #666666; border-top: 1px solid #f0f0f0;" align="center" valign="bottom">Sent by
2131 - <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance and health monitoring, on <code>${this_host}</code>.
2148 + <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance and health monitoring, on <code>${host}</code>.
2149 </td>
2150 </tr>
2151 </tbody>
health/notifications/health_alarm_notify.conf
+18
@@ -63,6 +63,24 @@
63 date_format=''
64
65
66 +#------------------------------------------------------------------------------
67 +# hostname handling
68 +#
69 +# By default, Netdata will use the simple hostname for the system (the
70 +# hostname with everything after the first `.` removed) when displaying
71 +# the hostname in alert notifications. If you prefer, you can uncomment
72 +# the line below to have Netdata instead use the host's fully qualified
73 +# domain name.
74 +#
75 +# This does not report correct FQDN's for slave systems for which this
76 +# sytem is a master.
77 +#
78 +# Additionally, if the system host name is overridden in /etc/netdata.conf
79 +# with the `hostname` option, that name will be used unconditionally
80 +# instead of this.
81 +#use_fqdn='YES'
82 +
83 +
84 #------------------------------------------------------------------------------
85 # external commands
86