]> arthur.barton.de Git - netdata.git/blob - plugins.d/alarm-notify.sh
Improve telegram message style
[netdata.git] / plugins.d / alarm-notify.sh
1 #!/usr/bin/env bash
2
3 # (C) Costa Tsaousis
4 # pushover support by Jan Arnold
5
6 me="${0}"
7
8 if [ $(( ${BASH_VERSINFO[0]} )) -lt 4 ]
9 then
10     echo >&2
11     echo >&2 "$me: ERROR"
12     echo >&2 "BASH version 4 or later is required."
13     echo >&2 "You are running version: ${BASH_VERSION}"
14     echo >&2 "Please upgrade."
15     echo >&2
16     exit 1
17 fi
18
19 # defaults to allow running this script by hand
20 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
21 NETDATA_CACHE_DIR="${NETDATA_CACHE_DIR-/var/cache/netdata}"
22 [ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
23 [ -z "${NETDATA_HOSTNAME}" ] && NETDATA_HOSTNAME="$(hostname)"
24 [ -z "${NETDATA_REGISTRY_HOSTNAME}" ] && NETDATA_REGISTRY_HOSTNAME="${NETDATA_HOSTNAME}"
25
26 # -----------------------------------------------------------------------------
27 # parse command line parameters
28
29 recipient="${1}"   # the recepient of the email
30 host="${2}"        # the host this event refers to
31 unique_id="${3}"   # the unique id of this event
32 alarm_id="${4}"    # the unique id of the alarm that generated this event
33 event_id="${5}"    # the incremental id of the event, for this alarm
34 when="${6}"        # the timestamp this event occured
35 name="${7}"        # the name of the alarm, as given in netdata health.d entries
36 chart="${8}"       # the name of the chart (type.id)
37 family="${9}"      # the family of the chart
38 status="${10}"     # the current status : REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
39 old_status="${11}" # the previous status: REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
40 value="${12}"      # the current value
41 old_value="${13}"  # the previous value
42 src="${14}"        # the line number and file the alarm has been configured
43 duration="${15}"   # the duration in seconds the previous state took
44 non_clear_duration="${16}" # the total duration in seconds this is non-clear
45 units="${17}"      # the units of the value
46 info="${18}"       # a short description of the alarm
47
48 # -----------------------------------------------------------------------------
49 # screen statuses we don't need to send a notification
50
51 # don't do anything if this is not WARNING, CRITICAL or CLEAR
52 if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
53 then
54     echo >&2 "${me}: not sending notification for ${status} on '${chart}.${name}'"
55     exit 1
56 fi
57
58 # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
59 if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
60 then
61     echo >&2 "${me}: not sending notification for ${status} on '${chart}.${name}' (last status was ${old_status})"
62     exit 1
63 fi
64
65 # -----------------------------------------------------------------------------
66 # load configuration
67
68 # this is defined here so that private registries
69 # can setup their own
70 # images_base_url="${NETDATA_REGISTRY_URL}"
71 images_base_url="https://registry.my-netdata.io"
72
73 # needed commands
74 # if empty they will be searched in the system path
75 curl=
76 sendmail=
77
78 # enable / disable features
79 SEND_SLACK="YES"
80 SEND_PUSHOVER="YES"
81 SEND_TELEGRAM="YES"
82 SEND_EMAIL="YES"
83
84 # slack configs
85 SLACK_WEBHOOK_URL=
86 DEFAULT_RECIPIENT_SLACK=
87 declare -A role_recipients_slack=()
88
89 # pushover configs
90 PUSHOVER_APP_TOKEN=
91 DEFAULT_RECIPIENT_PUSHOVER=
92 declare -A role_recipients_pushover=()
93
94 # telegram configs
95 TELEGRAM_BOT_TOKEN=
96 DEFAULT_RECIPIENT_TELEGRAM=
97 declare -A role_recipients_telegram=()
98
99 # email configs
100 DEFAULT_RECIPIENT_EMAIL="root"
101 declare -A role_recipients_email=()
102
103 # load the user configuration
104 # this will overwrite the variables above
105 if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ]
106     then
107     source "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf"
108 fi
109
110 # -----------------------------------------------------------------------------
111 # filter recipients based on the criticality of each
112
113 filter_recipient_by_criticality() {
114     local method="${1}" x="${2}" r s
115     shift
116
117     r="${x/|*/}"
118     s="${x/*|/}"
119
120     # no severity filtering for this person
121     [ "${r}" = "${s}" ] && return 0
122
123     # the severity is invalid
124     s="${s^^}"
125     [ "${s}" != "CRITICAL" ] && return 0
126
127     # the new or the old status matches the severity
128     if [ "${s}" = "${status}" -o "${s}" = "${old_status}" ]
129         then
130         [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] && \
131             mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
132
133         # we need to keep track of the notifications we sent
134         # so that the same user will receive the recovery
135         # even if old_status does not match the required severity
136         touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
137         return 0
138     fi
139
140     # it is a cleared alarm we have sent notification for
141     if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]
142         then
143         rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
144         return 0
145     fi
146
147     return 1
148 }
149
150 # -----------------------------------------------------------------------------
151 # find the recipient's addresses per method
152
153 declare -A arr_slack=()
154 declare -A arr_pushover=()
155 declare -A arr_telegram=()
156 declare -A arr_email=()
157
158 # netdata may call us with multiple recipients
159 # so, here we find the unique ones
160 for x in ${recipient//,/ }
161 do
162     # email
163     a="${role_recipients_email[${recipient}]}"
164     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_EMAIL}"
165     for r in ${a//,/ }
166     do
167         [ "${r}" != "disabled" ] && filter_recipient_by_criticality email "${r}" && arr_email[${r/|*/}]="1"
168     done
169
170     # pushover
171     a="${role_recipients_pushover[${recipient}]}"
172     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHOVER}"
173     for r in ${a//,/ }
174     do
175         [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushover "${r}" && arr_pushover[${r/|*/}]="1"
176     done
177
178     # telegram
179     a="${role_recipients_telegram[${recipient}]}"
180     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
181     for r in ${a//,/ }
182     do
183         [ "${r}" != "disabled" ] && filter_recipient_by_criticality telegram "${r}" && arr_telegram[${r/|*/}]="1"
184     done
185
186     # slack
187     a="${role_recipients_slack[${recipient}]}"
188     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SLACK}"
189     for r in ${a//,/ }
190     do
191         [ "${r}" != "disabled" ] && filter_recipient_by_criticality slack "${r}" && arr_slack[${r/|*/}]="1"
192     done
193 done
194
195 # build the list of slack recipients (channels)
196 to_slack="${!arr_slack[*]}"
197 [ -z "${to_slack}" ] && SEND_SLACK="NO"
198
199 # build the list of pushover recipients (user tokens)
200 to_pushover="${!arr_pushover[*]}"
201 [ -z "${to_pushover}" ] && SEND_PUSHOVER="NO"
202
203 # check array of telegram recipients (chat ids)
204 to_telegram="${!arr_telegram[*]}"
205 [ -z "${to_telegram}" ] && SEND_TELEGRAM="NO"
206
207 # build the list of email recipients (email addresses)
208 to_email=
209 for x in "${!arr_email[@]}"
210 do
211     [ ! -z "${to_email}" ] && to_email="${to_email}, "
212     to_email="${to_email}${x}"
213 done
214 [ -z "${to_email}" ] && SEND_EMAIL="NO"
215
216
217 # -----------------------------------------------------------------------------
218 # verify the delivery methods supported
219
220 # check slack
221 [ -z "${SLACK_WEBHOOK_URL}" ] && SEND_SLACK="NO"
222
223 # check pushover
224 [ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO"
225
226 # check telegram
227 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
228
229 if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TELEGRAM}" = "YES" \) -a -z "${curl}" ]
230     then
231     curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
232     if [ -z "${curl}" ]
233         then
234         SEND_PUSHOVER="NO"
235         SEND_TELEGRAM="NO"
236         SEND_SLACK="NO"
237     fi
238 fi
239
240 if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
241     then
242     sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)"
243     [ -z "${sendmail}" ] && SEND_EMAIL="NO"
244 fi
245
246 # check that we have at least a method enabled
247 if [ "${SEND_EMAIL}" != "YES" -a "${SEND_PUSHOVER}" != "YES" -a "${SEND_TELEGRAM}" != "YES" -a "${SEND_SLACK}" != "YES" ]
248     then
249     echo >&2 "All notification methods are disabled. Not sending a notification."
250     exit 1
251 fi
252
253 # -----------------------------------------------------------------------------
254 # get the system hostname
255
256 [ -z "${host}" ] && host="${NETDATA_HOSTNAME}"
257 [ -z "${host}" ] && host="${NETDATA_REGISTRY_HOSTNAME}"
258 [ -z "${host}" ] && host="$(hostname 2>/dev/null)"
259
260 # -----------------------------------------------------------------------------
261 # get the date the alarm happened
262
263 date="$(date --date=@${when} 2>/dev/null)"
264 [ -z "${date}" ] && date="$(date 2>/dev/null)"
265
266 # -----------------------------------------------------------------------------
267 # URL encode a string
268
269 urlencode() {
270     local string="${1}" strlen encoded pos c o
271
272     strlen=${#string}
273     for (( pos=0 ; pos<strlen ; pos++ ))
274     do
275         c=${string:$pos:1}
276         case "$c" in
277             [-_.~a-zA-Z0-9])
278                 o="${c}"
279                 ;;
280
281             *)
282                 printf -v o '%%%02x' "'$c"
283                 ;;
284         esac
285         encoded+="${o}"
286     done
287
288     REPLY="${encoded}"
289     echo "${REPLY}"
290 }
291
292 # -----------------------------------------------------------------------------
293 # convert a duration in seconds, to a human readable duration
294 # using DAYS, MINUTES, SECONDS
295
296 duration4human() {
297     local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
298     d=$(( s / 86400 ))
299     s=$(( s - (d * 86400) ))
300     h=$(( s / 3600 ))
301     s=$(( s - (h * 3600) ))
302     m=$(( s / 60 ))
303     s=$(( s - (m * 60) ))
304
305     if [ ${d} -gt 0 ]
306     then
307         [ ${m} -ge 30 ] && h=$(( h + 1 ))
308         [ ${d} -gt 1 ] && ds="days"
309         [ ${h} -gt 1 ] && hs="hours"
310         if [ ${h} -gt 0 ]
311         then
312             ret="${d} ${ds} and ${h} ${hs}"
313         else
314             ret="${d} ${ds}"
315         fi
316     elif [ ${h} -gt 0 ]
317     then
318         [ ${s} -ge 30 ] && m=$(( m + 1 ))
319         [ ${h} -gt 1 ] && hs="hours"
320         [ ${m} -gt 1 ] && ms="minutes"
321         if [ ${m} -gt 0 ]
322         then
323             ret="${h} ${hs} and ${m} ${ms}"
324         else
325             ret="${h} ${hs}"
326         fi
327     elif [ ${m} -gt 0 ]
328     then
329         [ ${m} -gt 1 ] && ms="minutes"
330         [ ${s} -gt 1 ] && ss="seconds"
331         if [ ${s} -gt 0 ]
332         then
333             ret="${m} ${ms} and ${s} ${ss}"
334         else
335             ret="${m} ${ms}"
336         fi
337     else
338         [ ${s} -gt 1 ] && ss="seconds"
339         ret="${s} ${ss}"
340     fi
341
342     REPLY="${ret}"
343     echo "${REPLY}"
344 }
345
346 # -----------------------------------------------------------------------------
347 # email sender
348
349 send_email() {
350     local ret=
351     if [ "${SEND_EMAIL}" = "YES" ]
352         then
353
354         "${sendmail}" -t
355         ret=$?
356
357         if [ $ret -eq 0 ]
358         then
359             echo >&2 "${me}: Sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
360             return 0
361         else
362             echo >&2 "${me}: Failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
363             return 1
364         fi
365     fi
366
367     return 1
368 }
369
370 # -----------------------------------------------------------------------------
371 # pushover sender
372
373 send_pushover() {
374     local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority
375
376     if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertokens}" -a ! -z "${title}" -a ! -z "${message}" ]
377         then
378
379         # https://pushover.net/api
380         priority=-2
381         case "${status}" in
382             CLEAR) priority=-1;;   # low priority: no sound or vibration
383             WARNING) priotity=0;;  # normal priority: respect quiet hours
384             CRITICAL) priority=1;; # high priority: bypass quiet hours
385             *) priority=-2;;       # lowest priority: no notification at all
386         esac
387
388         for user in ${usertokens}
389         do
390             httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
391                 --form-string "token=${apptoken}" \
392                 --form-string "user=${user}" \
393                 --form-string "html=1" \
394                 --form-string "title=${title}" \
395                 --form-string "message=${message}" \
396                 --form-string "timestamp=${when}" \
397                 --form-string "url=${url}" \
398                 --form-string "url_title=Open netdata dashboard to view the alarm" \
399                 --form-string "priority=${priority}" \
400                 https://api.pushover.net/1/messages.json)
401
402             if [ "${httpcode}" == "200" ]
403             then
404                 echo >&2 "${me}: Sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
405                 sent=$((sent + 1))
406             else
407                 echo >&2 "${me}: Failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
408             fi
409         done
410
411         [ ${sent} -gt 0 ] && return 0
412     fi
413
414     return 1
415 }
416
417
418 # -----------------------------------------------------------------------------
419 # telegram sender
420
421 send_telegram() {
422     local bottoken="${1}" chatids="${2}" message="${3}" httpcode sent=0 chatid disableNotification=""
423
424     if [ "${status}" = "CLEAR" ]; then disableNotification="--data-urlencode disable_notification=true"; fi
425
426     if [ "${SEND_TELEGRAM}" = "YES" -a ! -z "${bottoken}" -a ! -z "${chatids}" -a ! -z "${message}" ];
427     then
428         for chatid in ${chatids}
429         do
430             # https://core.telegram.org/bots/api#sendmessage
431             httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null ${disableNotification} \
432                 --data-urlencode "parse_mode=HTML" \
433                 --data-urlencode "disable_web_page_preview=true" \
434                 --data-urlencode "text=$message" \
435                 "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=$chatid")
436
437             if [ "${httpcode}" == "200" ]
438             then
439                 echo >&2 "${me}: Sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
440                 sent=$((sent + 1))
441             elif [ "${httpcode}" == "401" ]
442             then
443                 echo >&2 "${me}: Failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
444             else
445                 echo >&2 "${me}: Failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
446             fi
447         done
448
449         [ ${sent} -gt 0 ] && return 0
450     fi
451
452     return 1
453 }
454
455 # -----------------------------------------------------------------------------
456 # slack sender
457
458 send_slack() {
459     local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
460
461     [ "${SEND_SLACK}" != "YES" ] && return 1
462
463     case "${status}" in
464         WARNING) color="warning" ;;
465         CRITICAL) color="danger" ;;
466         CLEAR) color="good" ;;
467         *) color="#777777" ;;
468     esac
469
470     for channel in ${channels}
471     do
472         payload="$(cat <<EOF
473         {
474             "channel": "#${channel}",
475             "username": "netdata on ${host}",
476             "icon_url": "${images_base_url}/images/seo-performance-128.png",
477             "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
478             "attachments": [
479                 {
480                     "fallback": "${alarm} - ${chart} (${family}) - ${info}",
481                     "color": "${color}",
482                     "title": "${alarm}",
483                     "title_link": "${goto_url}",
484                     "text": "${info}",
485                     "fields": [
486                         {
487                             "title": "${chart}",
488                             "short": true
489                         },
490                         {
491                             "title": "${family}",
492                             "short": true
493                         }
494                     ],
495                     "thumb_url": "${image}",
496                     "footer": "<${goto_url}|${host}>",
497                     "ts": ${when}
498                 }
499             ]
500         }
501 EOF
502         )"
503
504         httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null -X POST --data-urlencode "payload=${payload}" "${webhook}")
505         if [ "${httpcode}" == "200" ]
506         then
507             echo >&2 "${me}: Sent slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
508             sent=$((sent + 1))
509         else
510             echo >&2 "${me}: Failed to send slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
511         fi
512     done
513
514     [ ${sent} -gt 0 ] && return 0
515
516     return 1
517 }
518
519
520 # -----------------------------------------------------------------------------
521 # prepare the content of the notification
522
523 # the url to send the user on click
524 urlencode "${NETDATA_REGISTRY_HOSTNAME}" >/dev/null; url_host="${REPLY}"
525 urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
526 urlencode "${family}" >/dev/null; url_family="${REPLY}"
527 urlencode "${name}" >/dev/null; url_name="${REPLY}"
528 goto_url="${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html?host=${url_host}&chart=${url_chart}&family=${url_family}&alarm=${url_name}&alarm_unique_id=${unique_id}&alarm_id=${alarm_id}&alarm_event_id=${event_id}"
529
530 # the severity of the alarm
531 severity="${status}"
532
533 # the time the alarm was raised
534 duration4human ${duration} >/dev/null; duration_txt="${REPLY}"
535 duration4human ${non_clear_duration} >/dev/null; non_clear_duration_txt="${REPLY}"
536 raised_for="(was ${old_status,,} for ${duration_txt})"
537
538 # the key status message
539 status_message="status unknown"
540
541 # the color of the alarm
542 color="grey"
543
544 # the alarm value
545 alarm="${name//_/ } = ${value} ${units}"
546
547 # the image of the alarm
548 image="${images_base_url}/images/seo-performance-128.png"
549
550 # prepare the title based on status
551 case "${status}" in
552         CRITICAL)
553         image="${images_base_url}/images/alert-128-red.png"
554         status_message="is critical"
555         color="#ca414b"
556         ;;
557
558     WARNING)
559         image="${images_base_url}/images/alert-128-orange.png"
560         status_message="needs attention"
561         color="#caca4b"
562                 ;;
563
564         CLEAR)
565         image="${images_base_url}/images/check-mark-2-128-green.png"
566         status_message="recovered"
567                 color="#77ca6d"
568
569                 # don't show the value when the status is CLEAR
570                 # for certain alarms, this value might not have any meaning
571                 alarm="${name//_/ } ${raised_for}"
572                 ;;
573 esac
574
575 if [ "${status}" = "CLEAR" ]
576 then
577     severity="Recovered from ${old_status}"
578     if [ $non_clear_duration -gt $duration ]
579     then
580         raised_for="(alarm was raised for ${non_clear_duration_txt})"
581     fi
582
583 elif [ "${old_status}" = "WARNING" -a "${status}" = "CRITICAL" ]
584 then
585     severity="Escalated to ${status}"
586     if [ $non_clear_duration -gt $duration ]
587     then
588         raised_for="(alarm is raised for ${non_clear_duration_txt})"
589     fi
590
591 elif [ "${old_status}" = "CRITICAL" -a "${status}" = "WARNING" ]
592 then
593     severity="Demoted to ${status}"
594     if [ $non_clear_duration -gt $duration ]
595     then
596         raised_for="(alarm is raised for ${non_clear_duration_txt})"
597     fi
598
599 else
600     raised_for=
601 fi
602
603 # prepare HTML versions of elements
604 info_html=
605 [ ! -z "${info}" ] && info_html=" <small><br/>${info}</small>"
606
607 raised_for_html=
608 [ ! -z "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
609
610 # -----------------------------------------------------------------------------
611 # send the slack notification
612
613 # slack aggregates posts from the same username
614 # so we use "${host} ${status}" as the bot username, to make them diff
615
616 send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
617 SENT_SLACK=$?
618
619 # -----------------------------------------------------------------------------
620 # send the pushover notification
621
622 send_pushover "${PUSHOVER_APP_TOKEN}" "${to_pushover}" "${when}" "${goto_url}" "${status}" "${host} ${status_message} - ${name//_/ } - ${chart}" "
623 <font color=\"${color}\"><b>${alarm}</b></font>${info_html}<br/>&nbsp;
624 <small><b>${chart}</b><br/>Chart<br/>&nbsp;</small>
625 <small><b>${family}</b><br/>Family<br/>&nbsp;</small>
626 <small><b>${severity}</b><br/>Severity<br/>&nbsp;</small>
627 <small><b>${date}${raised_for_html}</b><br/>Time<br/>&nbsp;</small>
628 <a href=\"${goto_url}\">View Netdata</a><br/>&nbsp;
629 <small><small>The source of this alarm is line ${src}</small></small>
630 "
631
632 SENT_PUSHOVER=$?
633
634 # -----------------------------------------------------------------------------
635 # send the telegram.org message
636
637 # https://core.telegram.org/bots/api#formatting-options
638 telegram_message="<b>${severity}"
639 [ "${status_message}" != "recovered" ] && telegram_message="${telegram_message}, ${status_message}"
640 telegram_message="${telegram_message}
641 ${chart} (${family})</b>
642 <a href=\"${goto_url}\">${alarm}</a>
643 <i>${info}</i>"
644
645 send_telegram "${TELEGRAM_BOT_TOKEN}" "${to_telegram}" "${telegram_message}"
646
647 SENT_TELEGRAM=$?
648
649 # -----------------------------------------------------------------------------
650 # send the email
651
652 send_email <<EOF
653 To: ${to_email}
654 Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
655 Content-Type: text/html
656
657 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
658 <html xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0; padding: 0;">
659 <body style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 14px; width: 100% !important; min-height: 100%; line-height: 1.6; background: #f6f6f6; margin:0; padding: 0;">
660 <table>
661     <tbody>
662     <tr>
663         <td style="vertical-align: top;" valign="top"></td>
664         <td width="700" style="vertical-align: top; display: block !important; max-width: 700px !important; clear: both !important; margin: 0 auto; padding: 0;" valign="top">
665             <div style="max-width: 700px; display: block; margin: 0 auto; padding: 20px;">
666                 <table width="100%" cellpadding="0" cellspacing="0" style="background: #fff; border: 1px solid #e9e9e9;">
667                     <tbody>
668                     <tr>
669                         <td bgcolor="#eee" style="padding: 5px 20px 5px 20px; background-color: #eee;">
670                             <div style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 20px; color: #777; font-weight: bold;">netdata notification</div>
671                         </td>
672                     </tr>
673                     <tr>
674                         <td bgcolor="${color}" style="font-size: 16px; vertical-align: top; font-weight: 400; text-align: center; margin: 0; padding: 10px; color: #ffffff; background: ${color} !important; border: 1px solid ${color}; border-top-color: ${color};" align="center" valign="top">
675                             <h1 style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-weight: 400; margin: 0;">${host} ${status_message}</h1>
676                         </td>
677                     </tr>
678                     <tr>
679                         <td style="vertical-align: top;" valign="top">
680                             <div style="margin: 0; padding: 20px; max-width: 700px;">
681                                 <table width="100%" cellpadding="0" cellspacing="0" style="max-width:700px">
682                                     <tbody>
683                                     <tr>
684                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding:0 0 20px;" align="left" valign="top">
685                                             <span>${chart}</span>
686                                             <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Chart</span>
687                                         </td>
688                                     </tr>
689                                     <tr style="margin: 0; padding: 0;">
690                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
691                                             <span><b>${alarm}</b>${info_html}</span>
692                                             <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Alarm</span>
693                                         </td>
694                                     </tr>
695                                     <tr>
696                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
697                                             <span>${family}</span>
698                                             <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Family</span>
699                                         </td>
700                                     </tr>
701                                     <tr style="margin: 0; padding: 0;">
702                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top">
703                                             <span>${severity}</span>
704                                             <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Severity</span>
705                                         </td>
706                                     </tr>
707                                     <tr style="margin: 0; padding: 0;">
708                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;" align="left" valign="top"><span>${date}</span>
709                                             <span>${raised_for_html}</span> <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Time</span>
710                                         </td>
711                                     </tr>
712                                     <tr style="margin: 0; padding: 0;">
713                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;">
714                                             <a href="${goto_url}" style="font-size: 14px; color: #ffffff; text-decoration: none; line-height: 1.5; font-weight: bold; text-align: center; display: inline-block; text-transform: capitalize; background: #35568d; border-width: 1px; border-style: solid; border-color: #2b4c86; margin: 0; padding: 10px 15px;" target="_blank">View Netdata</a>
715                                         </td>
716                                     </tr>
717                                     <tr style="text-align: center; margin: 0; padding: 0;">
718                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 11px; vertical-align: top; margin: 0; padding: 10px 0 0 0; color: #666666;" align="center" valign="bottom">The source of this alarm is line <code>${src}</code>
719                                         </td>
720                                     </tr>
721                                     <tr style="text-align: center; margin: 0; padding: 0;">
722                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', 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
723                                             <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance monitoring.
724                                         </td>
725                                     </tr>
726                                     </tbody>
727                                 </table>
728                             </div>
729                         </td>
730                     </tr>
731                     </tbody>
732                 </table>
733             </div>
734         </td>
735     </tr>
736     </tbody>
737 </table>
738 </body>
739 </html>
740 EOF
741
742 SENT_EMAIL=$?
743
744 # -----------------------------------------------------------------------------
745 # let netdata know
746
747 # we did send somehting
748 [ ${SENT_EMAIL} -eq 0 -o ${SENT_PUSHOVER} -eq 0 -o ${SENT_TELEGRAM} -eq 0 -o ${SENT_SLACK} -eq 0 ] && exit 0
749
750 # we did not send anything
751 exit 1