]> arthur.barton.de Git - netdata.git/blob - plugins.d/alarm-notify.sh
Merge pull request #1543 from tech-no-logical/tech-no-logical-patch-1
[netdata.git] / plugins.d / alarm-notify.sh
1 #!/usr/bin/env bash
2
3 # netdata
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6 # GPL v3+
7 #
8 # Script to send alarm notifications for netdata
9 #
10 # Features:
11 #  - multiple notification methods
12 #  - multiple roles per alarm
13 #  - multiple recipients per role
14 #  - severity filtering per recipient
15 #
16 # Supported notification methods:
17 #  - emails
18 #  - slack.com notifications
19 #  - pushover.net notifications
20 #  - pushbullet.com push notifications by Tiago Peralta @tperalta82 PR #1070
21 #  - telegram.org notifications by @hashworks PR #1002
22 #  - twilio.com notifications by Levi Blaney @shadycuz PR #1211
23 #  - kafka notifications
24 #  - pagerduty.com notifications by Jim Cooley @jimcooley PR #1373
25 #  - messagebird.com notifications by @tech_no_logical
26
27 # -----------------------------------------------------------------------------
28 # testing notifications
29
30 if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
31 then
32     if [ "${2}" = "test" ]
33     then
34         recipient="${1}"
35     else
36         recipient="${2}"
37     fi
38
39     [ -z "${recipient}" ] && recipient="sysadmin"
40
41     id=1
42     last="CLEAR"
43     for x in "CRITICAL" "WARNING" "CLEAR"
44     do
45         echo >&2
46         echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
47
48         "${0}" "${recipient}" "$(hostname)" 1 1 "${id}" "$(date +%s)" "test_alarm" "test.chart" "test.family" "${x}" "${last}" 100 90 "${0}" 1 $((0 + id)) "units" "this is a test alarm to verify notifications work"
49         if [ $? -ne 0 ]
50         then
51             echo >&2 "# FAILED"
52         else
53             echo >&2 "# OK"
54         fi
55
56         last="${x}"
57         id=$((id + 1))
58     done
59
60     exit 1
61 fi
62
63 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
64 export LC_ALL=C
65
66 # -----------------------------------------------------------------------------
67
68 PROGRAM_NAME="$(basename "${0}")"
69
70 logdate() {
71     date "+%Y-%m-%d %H:%M:%S"
72 }
73
74 log() {
75     local status="${1}"
76     shift
77
78     echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
79
80 }
81
82 warning() {
83     log WARNING "${@}"
84 }
85
86 error() {
87     log ERROR "${@}"
88 }
89
90 info() {
91     log INFO "${@}"
92 }
93
94 fatal() {
95     log FATAL "${@}"
96     exit 1
97 }
98
99 debug=0
100 debug() {
101     [ ${debug} -eq 1 ] && log DEBUG "${@}"
102 }
103
104 # -----------------------------------------------------------------------------
105
106 # check for BASH v4+ (required for associative arrays)
107 [ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && \
108     fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
109
110 # -----------------------------------------------------------------------------
111 # defaults to allow running this script by hand
112
113 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
114 NETDATA_CACHE_DIR="${NETDATA_CACHE_DIR-/var/cache/netdata}"
115 [ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
116 [ -z "${NETDATA_HOSTNAME}" ] && NETDATA_HOSTNAME="$(hostname)"
117 [ -z "${NETDATA_REGISTRY_HOSTNAME}" ] && NETDATA_REGISTRY_HOSTNAME="${NETDATA_HOSTNAME}"
118
119 # -----------------------------------------------------------------------------
120 # parse command line parameters
121
122 roles="${1}"       # the roles that should be notified for this event
123 host="${2}"        # the host generated this event
124 unique_id="${3}"   # the unique id of this event
125 alarm_id="${4}"    # the unique id of the alarm that generated this event
126 event_id="${5}"    # the incremental id of the event, for this alarm id
127 when="${6}"        # the timestamp this event occurred
128 name="${7}"        # the name of the alarm, as given in netdata health.d entries
129 chart="${8}"       # the name of the chart (type.id)
130 family="${9}"      # the family of the chart
131 status="${10}"     # the current status : REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
132 old_status="${11}" # the previous status: REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
133 value="${12}"      # the current value of the alarm
134 old_value="${13}"  # the previous value of the alarm
135 src="${14}"        # the line number and file the alarm has been configured
136 duration="${15}"   # the duration in seconds of the previous alarm state
137 non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
138 units="${17}"      # the units of the value
139 info="${18}"       # a short description of the alarm
140
141 # -----------------------------------------------------------------------------
142 # screen statuses we don't need to send a notification
143
144 # don't do anything if this is not WARNING, CRITICAL or CLEAR
145 if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
146 then
147     info "not sending notification for ${status} on '${chart}.${name}'"
148     exit 1
149 fi
150
151 # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
152 if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
153 then
154     info "not sending notification for ${status} on '${chart}.${name}' (last status was ${old_status})"
155     exit 1
156 fi
157
158 # -----------------------------------------------------------------------------
159 # load configuration
160
161 # By default fetch images from the global public registry.
162 # This is required by default, since all notification methods need to download
163 # images via the Internet, and private registries might not be reachable.
164 # This can be overwritten at the configuration file.
165 images_base_url="https://registry.my-netdata.io"
166
167 # needed commands
168 # if empty they will be searched in the system path
169 curl=
170 sendmail=
171
172 # enable / disable features
173 SEND_SLACK="YES"
174 SEND_PUSHOVER="YES"
175 SEND_TWILIO="YES"
176 SEND_MESSAGEBIRD="YES"
177 SEND_TELEGRAM="YES"
178 SEND_EMAIL="YES"
179 SEND_PUSHBULLET="YES"
180 SEND_KAFKA="YES"
181 SEND_PD="YES"
182
183 # slack configs
184 SLACK_WEBHOOK_URL=
185 DEFAULT_RECIPIENT_SLACK=
186 declare -A role_recipients_slack=()
187
188 # pushover configs
189 PUSHOVER_APP_TOKEN=
190 DEFAULT_RECIPIENT_PUSHOVER=
191 declare -A role_recipients_pushover=()
192
193 # pushbullet configs
194 PUSHBULLET_ACCESS_TOKEN=
195 DEFAULT_RECIPIENT_PUSHBULLET=
196 declare -A role_recipients_pushbullet=()
197
198 # twilio configs
199 TWILIO_ACCOUNT_SID=
200 TWILIO_ACCOUNT_TOKEN=
201 TWILIO_NUMBER=
202 DEFAULT_RECIPIENT_TWILIO=
203 declare -A role_recipients_twilio=()
204
205 # messagebird configs
206 MESSAGEBIRD_ACCESS_KEY=
207 MESSAGEBIRD_NUMBER=
208 DEFAULT_RECIPIENT_MESSAGEBIRD=
209 declare -A role_recipients_messagebird=()
210
211 # telegram configs
212 TELEGRAM_BOT_TOKEN=
213 DEFAULT_RECIPIENT_TELEGRAM=
214 declare -A role_recipients_telegram=()
215
216 # kafka configs
217 KAFKA_URL=
218 KAFKA_SENDER_IP=
219
220 # pagerduty.com configs
221 PD_SERVICE_KEY=
222 declare -A role_recipients_pd=()
223
224 # email configs
225 DEFAULT_RECIPIENT_EMAIL="root"
226 declare -A role_recipients_email=()
227
228 # load the user configuration
229 # this will overwrite the variables above
230 if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ]
231     then
232     source "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf"
233 fi
234
235 # -----------------------------------------------------------------------------
236 # filter a recipient based on alarm event severity
237
238 filter_recipient_by_criticality() {
239     local method="${1}" x="${2}" r s
240     shift
241
242     r="${x/|*/}" # the recipient
243     s="${x/*|/}" # the severity required for notifying this recipient
244
245     # no severity filtering for this person
246     [ "${r}" = "${s}" ] && return 0
247
248     # the severity is invalid
249     s="${s^^}"
250     [ "${s}" != "CRITICAL" ] && return 0
251
252     # the new or the old status matches the severity
253     if [ "${s}" = "${status}" -o "${s}" = "${old_status}" ]
254         then
255         [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] && \
256             mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
257
258         # we need to keep track of the notifications we sent
259         # so that the same user will receive the recovery
260         # even if old_status does not match the required severity
261         touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
262         return 0
263     fi
264
265     # it is a cleared alarm we have sent notification for
266     if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]
267         then
268         rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
269         return 0
270     fi
271
272     return 1
273 }
274
275 # -----------------------------------------------------------------------------
276 # find the recipients' addresses per method
277
278 declare -A arr_slack=()
279 declare -A arr_pushover=()
280 declare -A arr_pushbullet=()
281 declare -A arr_twilio=()
282 declare -A arr_telegram=()
283 declare -A arr_pd=()
284 declare -A arr_email=()
285
286 # netdata may call us with multiple roles, and roles may have multiple but
287 # overlapping recipients - so, here we find the unique recipients.
288 for x in ${roles//,/ }
289 do
290     # the roles 'silent' and 'disabled' mean:
291     # don't send a notification for this role
292     [ "${x}" = "silent" -o "${x}" = "disabled" ] && continue
293
294     # email
295     a="${role_recipients_email[${x}]}"
296     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_EMAIL}"
297     for r in ${a//,/ }
298     do
299         [ "${r}" != "disabled" ] && filter_recipient_by_criticality email "${r}" && arr_email[${r/|*/}]="1"
300     done
301
302     # pushover
303     a="${role_recipients_pushover[${x}]}"
304     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHOVER}"
305     for r in ${a//,/ }
306     do
307         [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushover "${r}" && arr_pushover[${r/|*/}]="1"
308     done
309
310     # pushbullet
311     a="${role_recipients_pushbullet[${x}]}"
312     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHBULLET}"
313     for r in ${a//,/ }
314     do
315         [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushbullet "${r}" && arr_pushbullet[${r/|*/}]="1"
316     done
317
318     # twilio
319     a="${role_recipients_twilio[${x}]}"
320     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TWILIO}"
321     for r in ${a//,/ }
322     do
323         [ "${r}" != "disabled" ] && filter_recipient_by_criticality twilio "${r}" && arr_twilio[${r/|*/}]="1"
324     done
325
326     # messagebird
327     a="${role_recipients_messagebird[${x}]}"
328     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
329     for r in ${a//,/ }
330     do
331         [ "${r}" != "disabled" ] && filter_recipient_by_criticality messagebird "${r}" && arr_messagebird[${r/|*/}]="1"
332     done
333
334     # telegram
335     a="${role_recipients_telegram[${x}]}"
336     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
337     for r in ${a//,/ }
338     do
339         [ "${r}" != "disabled" ] && filter_recipient_by_criticality telegram "${r}" && arr_telegram[${r/|*/}]="1"
340     done
341
342     # slack
343     a="${role_recipients_slack[${x}]}"
344     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SLACK}"
345     for r in ${a//,/ }
346     do
347         [ "${r}" != "disabled" ] && filter_recipient_by_criticality slack "${r}" && arr_slack[${r/|*/}]="1"
348     done
349
350     # pagerduty.com
351     a="${role_recipients_pd[${x}]}"
352     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PD}"
353     for r in ${a//,/ }
354     do
355         [ "${r}" != "disabled" ] && filter_recipient_by_criticality pd "${r}" && arr_pd[${r/|*/}]="1"
356     done
357 done
358
359 # build the list of slack recipients (channels)
360 to_slack="${!arr_slack[*]}"
361 [ -z "${to_slack}" ] && SEND_SLACK="NO"
362
363 # build the list of pushover recipients (user tokens)
364 to_pushover="${!arr_pushover[*]}"
365 [ -z "${to_pushover}" ] && SEND_PUSHOVER="NO"
366
367 # build the list of pushbulet recipients (user tokens)
368 to_pushbullet="${!arr_pushbullet[*]}"
369 [ -z "${to_pushbullet}" ] && SEND_PUSHBULLET="NO"
370
371 # build the list of twilio recipients (phone numbers)
372 to_twilio="${!arr_twilio[*]}"
373 [ -z "${to_twilio}" ] && SEND_TWILIO="NO"
374
375 # build the list of messagebird recipients (phone numbers)
376 to_messagebird="${!arr_messagebird[*]}"
377 [ -z "${to_messagebird}" ] && SEND_MESSAGEBIRD="NO"
378
379 # check array of telegram recipients (chat ids)
380 to_telegram="${!arr_telegram[*]}"
381 [ -z "${to_telegram}" ] && SEND_TELEGRAM="NO"
382
383 # build the list of pagerduty recipients (service keys)
384 to_pd="${!arr_pd[*]}"
385 [ -z "${to_pd}" ] && SEND_PD="NO"
386
387 # build the list of email recipients (email addresses)
388 to_email=
389 for x in "${!arr_email[@]}"
390 do
391     [ ! -z "${to_email}" ] && to_email="${to_email}, "
392     to_email="${to_email}${x}"
393 done
394 [ -z "${to_email}" ] && SEND_EMAIL="NO"
395
396
397 # -----------------------------------------------------------------------------
398 # verify the delivery methods supported
399
400 # check slack
401 [ -z "${SLACK_WEBHOOK_URL}" ] && SEND_SLACK="NO"
402
403 # check pushover
404 [ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO"
405
406 # check pushbullet
407 [ -z "${PUSHBULLET_ACCESS_TOKEN}" ] && SEND_PUSHBULLET="NO"
408
409 # check twilio
410 [ -z "${TWILIO_ACCOUNT_TOKEN}" -o -z "${TWILIO_ACCOUNT_SID}" -o -z "${TWILIO_NUMBER}" ] && SEND_TWILIO="NO"
411
412 # check messagebird
413 [ -z "${MESSAGEBIRD_ACCESS_KEY}" -o -z "${MESSAGEBIRD_NUMBER}" ] && SEND_MESSAGEBIRD="NO"
414
415 # check telegram
416 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
417
418 # check kafka
419 [ -z "${KAFKA_URL}" -o -z "${KAFKA_SENDER_IP}" ] && SEND_KAFKA="NO"
420
421 # check pagerduty.com
422 # if we need pd-send, check for the pd-send command
423 # https://www.pagerduty.com/docs/guides/agent-install-guide/
424 if [ "${SEND_PD}" = "YES" ]
425     then
426     pd_send="$(which pd-send 2>/dev/null || command -v pd-send 2>/dev/null)"
427     if [ -z "${pd_send}" ]
428         then
429         # no pd-send available
430         # disable pagerduty.com
431         SEND_PD="NO"
432     fi
433 fi
434
435 # if we need curl, check for the curl command
436 if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TWILIO}" = "YES" -o "${SEND_MESSAGEBIRD}" = "YES" -o "${SEND_TELEGRAM}" = "YES" -o "${SEND_PUSHBULLET}" = "YES" -o "${SEND_KAFKA}" = "YES" \) -a -z "${curl}" ]
437     then
438     curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
439     if [ -z "${curl}" ]
440         then
441         # no curl available
442         # disable all curl based methods
443         SEND_PUSHOVER="NO"
444         SEND_PUSHBULLET="NO"
445         SEND_TELEGRAM="NO"
446         SEND_SLACK="NO"
447         SEND_TWILIO="NO"
448         SEND_MESSAGEBIRD="NO"
449         SEND_KAFKA="NO"
450     fi
451 fi
452
453 # if we need sendmail, check for the sendmail command
454 if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
455     then
456     sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)"
457     [ -z "${sendmail}" ] && SEND_EMAIL="NO"
458 fi
459
460 # check that we have at least a method enabled
461 if [   "${SEND_EMAIL}"          != "YES" \
462     -a "${SEND_PUSHOVER}"       != "YES" \
463     -a "${SEND_TELEGRAM}"       != "YES" \
464     -a "${SEND_SLACK}"          != "YES" \
465     -a "${SEND_TWILIO}"         != "YES" \
466     -a "${SEND_MESSAGEBIRD}"    != "YES" \
467     -a "${SEND_PUSHBULLET}"     != "YES" \
468     -a "${SEND_KAFKA}"          != "YES" \
469     -a "${SEND_PD}"             != "YES" \
470     ]
471     then
472     fatal "All notification methods are disabled. Not sending notification to '${roles}' for '${name}' = '${value}' of chart '${chart}' for status '${status}'."
473 fi
474
475 # -----------------------------------------------------------------------------
476 # find a suitable hostname to use, if netdata did not supply a hostname
477
478 [ -z "${host}" ] && host="${NETDATA_HOSTNAME}"
479 [ -z "${host}" ] && host="${NETDATA_REGISTRY_HOSTNAME}"
480 [ -z "${host}" ] && host="$(hostname 2>/dev/null)"
481
482 # -----------------------------------------------------------------------------
483 # get the date the alarm happened
484
485 date="$(date --date=@${when} 2>/dev/null)"
486 [ -z "${date}" ] && date="$(date 2>/dev/null)"
487
488 # -----------------------------------------------------------------------------
489 # function to URL encode a string
490
491 urlencode() {
492     local string="${1}" strlen encoded pos c o
493
494     strlen=${#string}
495     for (( pos=0 ; pos<strlen ; pos++ ))
496     do
497         c=${string:${pos}:1}
498         case "${c}" in
499             [-_.~a-zA-Z0-9])
500                 o="${c}"
501                 ;;
502
503             *)
504                 printf -v o '%%%02x' "'${c}"
505                 ;;
506         esac
507         encoded+="${o}"
508     done
509
510     REPLY="${encoded}"
511     echo "${REPLY}"
512 }
513
514 # -----------------------------------------------------------------------------
515 # function to convert a duration in seconds, to a human readable duration
516 # using DAYS, MINUTES, SECONDS
517
518 duration4human() {
519     local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
520     d=$(( s / 86400 ))
521     s=$(( s - (d * 86400) ))
522     h=$(( s / 3600 ))
523     s=$(( s - (h * 3600) ))
524     m=$(( s / 60 ))
525     s=$(( s - (m * 60) ))
526
527     if [ ${d} -gt 0 ]
528     then
529         [ ${m} -ge 30 ] && h=$(( h + 1 ))
530         [ ${d} -gt 1 ] && ds="days"
531         [ ${h} -gt 1 ] && hs="hours"
532         if [ ${h} -gt 0 ]
533         then
534             ret="${d} ${ds} and ${h} ${hs}"
535         else
536             ret="${d} ${ds}"
537         fi
538     elif [ ${h} -gt 0 ]
539     then
540         [ ${s} -ge 30 ] && m=$(( m + 1 ))
541         [ ${h} -gt 1 ] && hs="hours"
542         [ ${m} -gt 1 ] && ms="minutes"
543         if [ ${m} -gt 0 ]
544         then
545             ret="${h} ${hs} and ${m} ${ms}"
546         else
547             ret="${h} ${hs}"
548         fi
549     elif [ ${m} -gt 0 ]
550     then
551         [ ${m} -gt 1 ] && ms="minutes"
552         [ ${s} -gt 1 ] && ss="seconds"
553         if [ ${s} -gt 0 ]
554         then
555             ret="${m} ${ms} and ${s} ${ss}"
556         else
557             ret="${m} ${ms}"
558         fi
559     else
560         [ ${s} -gt 1 ] && ss="seconds"
561         ret="${s} ${ss}"
562     fi
563
564     REPLY="${ret}"
565     echo "${REPLY}"
566 }
567
568 # -----------------------------------------------------------------------------
569 # email sender
570
571 send_email() {
572     local ret=
573     if [ "${SEND_EMAIL}" = "YES" ]
574         then
575
576         "${sendmail}" -t
577         ret=$?
578
579         if [ ${ret} -eq 0 ]
580         then
581             info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
582             return 0
583         else
584             error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
585             return 1
586         fi
587     fi
588
589     return 1
590 }
591
592 # -----------------------------------------------------------------------------
593 # pushover sender
594
595 send_pushover() {
596     local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority
597
598     if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertokens}" -a ! -z "${title}" -a ! -z "${message}" ]
599         then
600
601         # https://pushover.net/api
602         priority=-2
603         case "${status}" in
604             CLEAR) priority=-1;;   # low priority: no sound or vibration
605             WARNING) priotity=0;;  # normal priority: respect quiet hours
606             CRITICAL) priority=1;; # high priority: bypass quiet hours
607             *) priority=-2;;       # lowest priority: no notification at all
608         esac
609
610         for user in ${usertokens}
611         do
612             httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
613                 --form-string "token=${apptoken}" \
614                 --form-string "user=${user}" \
615                 --form-string "html=1" \
616                 --form-string "title=${title}" \
617                 --form-string "message=${message}" \
618                 --form-string "timestamp=${when}" \
619                 --form-string "url=${url}" \
620                 --form-string "url_title=Open netdata dashboard to view the alarm" \
621                 --form-string "priority=${priority}" \
622                 https://api.pushover.net/1/messages.json)
623
624             if [ "${httpcode}" == "200" ]
625             then
626                 info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
627                 sent=$((sent + 1))
628             else
629                 error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
630             fi
631         done
632
633         [ ${sent} -gt 0 ] && return 0
634     fi
635
636     return 1
637 }
638
639 # -----------------------------------------------------------------------------
640 # pushbullet sender
641
642 send_pushbullet() {
643     local userapikey="${1}" recipients="${2}"  title="${3}" message="${4}" httpcode sent=0 user
644     if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikey}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
645         then
646         #https://docs.pushbullet.com/#create-push
647         for user in ${recipients}
648         do
649             httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
650               --header 'Access-Token: '${userapikey}'' \
651               --header 'Content-Type: application/json' \
652               --data-binary  @<(cat <<EOF
653                               {"title": "${title}",
654                               "type": "note",
655                               "email": "${user}",
656                               "body": "$( echo -n ${message})"}
657 EOF
658                ) "https://api.pushbullet.com/v2/pushes" -X POST)
659
660             if [ "${httpcode}" == "200" ]
661             then
662                 info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
663                 sent=$((sent + 1))
664             else
665                 error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
666             fi
667         done
668
669         [ ${sent} -gt 0 ] && return 0
670     fi
671
672     return 1
673 }
674
675 # -----------------------------------------------------------------------------
676 # kafka sender
677
678 send_kafka() {
679     local httpcode sent=0 
680     if [ "${SEND_KAFKA}" = "YES" ]
681         then
682             httpcode=$(${curl} -X POST --write-out %{http_code} --silent --output /dev/null \
683                 --data "{host_ip:\"${KAFKA_SENDER_IP}\",when:${when},name:\"${name}\",chart:\"${chart}\",family:\"${family}\",status:\"${status}\",old_status:\"${old_status}\",value:${value},old_value:${old_value},duration:${duration},non_clear_duration:${non_clear_duration},units:\"${units}\",info:\"${info}\"}" \
684                 "${KAFKA_URL}")
685
686             if [ "${httpcode}" == "204" ]
687             then
688                 info "sent kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}'"
689                 sent=$((sent + 1))
690             else
691                 error "failed to send kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}' with HTTP error code ${httpcode}."
692             fi
693
694         [ ${sent} -gt 0 ] && return 0
695     fi
696
697     return 1
698 }
699
700 # -----------------------------------------------------------------------------
701 # pagerduty.com sender
702
703 send_pd() {
704     local recipients="${1}" sent=0
705     unset t
706     case ${status} in
707         CLEAR)    t='resolve';;
708         WARNING)  t='trigger';;
709         CRITICAL) t='trigger';;
710     esac
711
712     if [ ${SEND_PD} = "YES" -a ! -z "${t}" ]
713         then
714         for PD_SERVICE_KEY in ${recipients}
715         do
716             d="${status} ${name}=${value} ${units} - ${host}, ${family}"
717             ${pd_send} -k ${PD_SERVICE_KEY} \
718                        -t ${t} \
719                        -d "${d}" \
720                        -i ${alarm_id} \
721                        -f 'info'="${info}" \
722                        -f 'value_w_units'="${value} ${units}" \
723                        -f 'when'="${when}" \
724                        -f 'duration'="${duration}" \
725                        -f 'roles'="${roles}" \
726                        -f 'host'="${host}" \
727                        -f 'unique_id'="${unique_id}" \
728                        -f 'alarm_id'="${alarm_id}" \
729                        -f 'event_id'="${event_id}" \
730                        -f 'name'="${name}" \
731                        -f 'chart'="${chart}" \
732                        -f 'family'="${family}" \
733                        -f 'status'="${status}" \
734                        -f 'old_status'="${old_status}" \
735                        -f 'value'="${value}" \
736                        -f 'old_value'="${old_value}" \
737                        -f 'src'="${src}" \
738                        -f 'non_clear_duration'="${non_clear_duration}" \
739                        -f 'units'="${units}"
740             retval=$?
741             if [ ${retval} -eq 0 ]
742                 then
743                     info "sent pagerduty.com notification using service key ${PD_SERVICE_KEY::-26}....: ${d}"
744                     sent=$((sent + 1))
745                 else
746                     error "failed to send pagerduty.com notification using service key ${PD_SERVICE_KEY::-26}.... (error code ${retval}): ${d}"
747             fi
748         done
749
750         [ ${sent} -gt 0 ] && return 0
751     fi
752
753     return 1
754 }
755
756 # -----------------------------------------------------------------------------
757 # twilio sender
758
759 send_twilio() {
760     local accountsid="${1}" accounttoken="${2}" twilionumber="${3}" recipients="${4}"  title="${5}" message="${6}" httpcode sent=0 user
761     if [ "${SEND_TWILIO}" = "YES" -a ! -z "${accountsid}" -a ! -z "${accounttoken}" -a ! -z "${twilionumber}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
762         then
763         #https://www.twilio.com/packages/labs/code/bash/twilio-sms
764         for user in ${recipients}
765         do
766             httpcode=$(${curl} -X POST --write-out %{http_code} --silent --output /dev/null \
767                 --data-urlencode "From=${twilionumber}" \
768                 --data-urlencode "To=${user}" \
769                 --data-urlencode "Body=${title} ${message}" \
770                 -u "${accountsid}:${accounttoken}" \
771                 "https://api.twilio.com/2010-04-01/Accounts/${accountsid}/Messages.json")
772
773             if [ "${httpcode}" == "201" ]
774             then
775                 info "sent Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
776                 sent=$((sent + 1))
777             else
778                 error "failed to send Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
779             fi
780         done
781
782         [ ${sent} -gt 0 ] && return 0
783     fi
784
785     return 1
786 }
787
788 # -----------------------------------------------------------------------------
789 # messagebird sender
790
791 send_messagebird() {
792     local accesskey="${1}" messagebirdnumber="${2}" recipients="${3}"  title="${4}" message="${5}" httpcode sent=0 user
793     if [ "${SEND_MESSAGEBIRD}" = "YES" -a ! -z "${accesskey}" -a ! -z "${messagebirdnumber}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
794         then
795         #https://developers.messagebird.com/docs/messaging
796         for user in ${recipients}
797         do
798             httpcode=$(${curl} -X POST --write-out %{http_code} --silent --output /dev/null \
799                 --data-urlencode "originator=${messagebirdnumber}" \
800                 --data-urlencode "recipients=${user}" \
801                 --data-urlencode "body=${title} ${message}" \
802                         --data-urlencode "datacoding=auto" \
803                 -H "Authorization: AccessKey ${accesskey}" \
804                 "https://rest.messagebird.com/messages")
805
806             if [ "${httpcode}" == "201" ]
807             then
808                 info "sent Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
809                 sent=$((sent + 1))
810             else
811                 error "failed to send Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
812             fi
813         done
814
815         [ ${sent} -gt 0 ] && return 0
816     fi
817
818     return 1
819 }
820
821 # -----------------------------------------------------------------------------
822 # telegram sender
823
824 send_telegram() {
825     local bottoken="${1}" chatids="${2}" message="${3}" httpcode sent=0 chatid disableNotification=""
826
827     if [ "${status}" = "CLEAR" ]; then disableNotification="--data-urlencode disable_notification=true"; fi
828
829     if [ "${SEND_TELEGRAM}" = "YES" -a ! -z "${bottoken}" -a ! -z "${chatids}" -a ! -z "${message}" ];
830     then
831         for chatid in ${chatids}
832         do
833             # https://core.telegram.org/bots/api#sendmessage
834             httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null ${disableNotification} \
835                 --data-urlencode "parse_mode=HTML" \
836                 --data-urlencode "disable_web_page_preview=true" \
837                 --data-urlencode "text=${message}" \
838                 "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatid}")
839
840             if [ "${httpcode}" == "200" ]
841             then
842                 info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
843                 sent=$((sent + 1))
844             elif [ "${httpcode}" == "401" ]
845             then
846                 error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
847             else
848                 error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
849             fi
850         done
851
852         [ ${sent} -gt 0 ] && return 0
853     fi
854
855     return 1
856 }
857
858 # -----------------------------------------------------------------------------
859 # slack sender
860
861 send_slack() {
862     local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
863
864     [ "${SEND_SLACK}" != "YES" ] && return 1
865
866     case "${status}" in
867         WARNING)  color="warning" ;;
868         CRITICAL) color="danger" ;;
869         CLEAR)    color="good" ;;
870         *)        color="#777777" ;;
871     esac
872
873     for channel in ${channels}
874     do
875         payload="$(cat <<EOF
876         {
877             "channel": "#${channel}",
878             "username": "netdata on ${host}",
879             "icon_url": "${images_base_url}/images/seo-performance-128.png",
880             "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
881             "attachments": [
882                 {
883                     "fallback": "${alarm} - ${chart} (${family}) - ${info}",
884                     "color": "${color}",
885                     "title": "${alarm}",
886                     "title_link": "${goto_url}",
887                     "text": "${info}",
888                     "fields": [
889                         {
890                             "title": "${chart}",
891                             "short": true
892                         },
893                         {
894                             "title": "${family}",
895                             "short": true
896                         }
897                     ],
898                     "thumb_url": "${image}",
899                     "footer": "<${goto_url}|${host}>",
900                     "ts": ${when}
901                 }
902             ]
903         }
904 EOF
905         )"
906
907         httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null -X POST --data-urlencode "payload=${payload}" "${webhook}")
908         if [ "${httpcode}" == "200" ]
909         then
910             info "sent slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
911             sent=$((sent + 1))
912         else
913             error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
914         fi
915     done
916
917     [ ${sent} -gt 0 ] && return 0
918
919     return 1
920 }
921
922
923 # -----------------------------------------------------------------------------
924 # prepare the content of the notification
925
926 # the url to send the user on click
927 urlencode "${NETDATA_REGISTRY_HOSTNAME}" >/dev/null; url_host="${REPLY}"
928 urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
929 urlencode "${family}" >/dev/null; url_family="${REPLY}"
930 urlencode "${name}" >/dev/null; url_name="${REPLY}"
931 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}"
932
933 # the severity of the alarm
934 severity="${status}"
935
936 # the time the alarm was raised
937 duration4human ${duration} >/dev/null; duration_txt="${REPLY}"
938 duration4human ${non_clear_duration} >/dev/null; non_clear_duration_txt="${REPLY}"
939 raised_for="(was ${old_status,,} for ${duration_txt})"
940
941 # the key status message
942 status_message="status unknown"
943
944 # the color of the alarm
945 color="grey"
946
947 # the alarm value
948 alarm="${name//_/ } = ${value} ${units}"
949
950 # the image of the alarm
951 image="${images_base_url}/images/seo-performance-128.png"
952
953 # prepare the title based on status
954 case "${status}" in
955         CRITICAL)
956         image="${images_base_url}/images/alert-128-red.png"
957         status_message="is critical"
958         color="#ca414b"
959         ;;
960
961     WARNING)
962         image="${images_base_url}/images/alert-128-orange.png"
963         status_message="needs attention"
964         color="#caca4b"
965                 ;;
966
967         CLEAR)
968         image="${images_base_url}/images/check-mark-2-128-green.png"
969         status_message="recovered"
970                 color="#77ca6d"
971                 ;;
972 esac
973
974 if [ "${status}" = "CLEAR" ]
975 then
976     severity="Recovered from ${old_status}"
977     if [ ${non_clear_duration} -gt ${duration} ]
978     then
979         raised_for="(alarm was raised for ${non_clear_duration_txt})"
980     fi
981
982     # don't show the value when the status is CLEAR
983     # for certain alarms, this value might not have any meaning
984     alarm="${name//_/ } ${raised_for}"
985
986 elif [ "${old_status}" = "WARNING" -a "${status}" = "CRITICAL" ]
987 then
988     severity="Escalated to ${status}"
989     if [ ${non_clear_duration} -gt ${duration} ]
990     then
991         raised_for="(alarm is raised for ${non_clear_duration_txt})"
992     fi
993
994 elif [ "${old_status}" = "CRITICAL" -a "${status}" = "WARNING" ]
995 then
996     severity="Demoted to ${status}"
997     if [ ${non_clear_duration} -gt ${duration} ]
998     then
999         raised_for="(alarm is raised for ${non_clear_duration_txt})"
1000     fi
1001
1002 else
1003     raised_for=
1004 fi
1005
1006 # prepare HTML versions of elements
1007 info_html=
1008 [ ! -z "${info}" ] && info_html=" <small><br/>${info}</small>"
1009
1010 raised_for_html=
1011 [ ! -z "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
1012
1013 # -----------------------------------------------------------------------------
1014 # send the slack notification
1015
1016 # slack aggregates posts from the same username
1017 # so we use "${host} ${status}" as the bot username, to make them diff
1018
1019 send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
1020 SENT_SLACK=$?
1021
1022 # -----------------------------------------------------------------------------
1023 # send the pushover notification
1024
1025 send_pushover "${PUSHOVER_APP_TOKEN}" "${to_pushover}" "${when}" "${goto_url}" "${status}" "${host} ${status_message} - ${name//_/ } - ${chart}" "
1026 <font color=\"${color}\"><b>${alarm}</b></font>${info_html}<br/>&nbsp;
1027 <small><b>${chart}</b><br/>Chart<br/>&nbsp;</small>
1028 <small><b>${family}</b><br/>Family<br/>&nbsp;</small>
1029 <small><b>${severity}</b><br/>Severity<br/>&nbsp;</small>
1030 <small><b>${date}${raised_for_html}</b><br/>Time<br/>&nbsp;</small>
1031 <a href=\"${goto_url}\">View Netdata</a><br/>&nbsp;
1032 <small><small>The source of this alarm is line ${src}</small></small>
1033 "
1034
1035 SENT_PUSHOVER=$?
1036
1037 # -----------------------------------------------------------------------------
1038 # send the pushbullet notification
1039
1040 send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${to_pushbullet}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\n
1041 Severity: ${severity}\n
1042 Chart: ${chart}\n
1043 Family: ${family}\n
1044 To View Netdata go to: ${goto_url}\n
1045 The source of this alarm is line ${src}"
1046
1047 SENT_PUSHBULLET=$?
1048
1049 # -----------------------------------------------------------------------------
1050 # send the twilio SMS
1051
1052 send_twilio "${TWILIO_ACCOUNT_SID}" "${TWILIO_ACCOUNT_TOKEN}" "${TWILIO_NUMBER}" "${to_twilio}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm} 
1053 Severity: ${severity}
1054 Chart: ${chart}
1055 Family: ${family}
1056 ${info}"
1057
1058 SENT_TWILIO=$?
1059
1060 # -----------------------------------------------------------------------------
1061 # send the messagebird SMS
1062
1063 send_messagebird "${MESSAGEBIRD_ACCESS_KEY}" "${MESSAGEBIRD_NUMBER}" "${to_messagebird}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm} 
1064 Severity: ${severity}
1065 Chart: ${chart}
1066 Family: ${family}
1067 ${info}"
1068
1069 SENT_MESSAGEBIRD=$?
1070
1071
1072 # -----------------------------------------------------------------------------
1073 # send the telegram.org message
1074
1075 # https://core.telegram.org/bots/api#formatting-options
1076 send_telegram "${TELEGRAM_BOT_TOKEN}" "${to_telegram}" "${host} ${status_message} - <b>${name//_/ }</b>
1077 ${chart} (${family})
1078 <a href=\"${goto_url}\">${alarm}</a>
1079 <i>${info}</i>"
1080
1081 SENT_TELEGRAM=$?
1082
1083
1084 # -----------------------------------------------------------------------------
1085 # send the kafka message
1086
1087 send_kafka
1088 SENT_KAFKA=$?
1089
1090
1091 # -----------------------------------------------------------------------------
1092 # send the pagerduty.com message
1093
1094 send_pd "${to_pd}"
1095 SENT_PD=$?
1096
1097
1098 # -----------------------------------------------------------------------------
1099 # send the email
1100
1101 send_email <<EOF
1102 To: ${to_email}
1103 Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
1104 Content-Type: text/html
1105
1106 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1107 <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;">
1108 <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;">
1109 <table>
1110     <tbody>
1111     <tr>
1112         <td style="vertical-align: top;" valign="top"></td>
1113         <td width="700" style="vertical-align: top; display: block !important; max-width: 700px !important; clear: both !important; margin: 0 auto; padding: 0;" valign="top">
1114             <div style="max-width: 700px; display: block; margin: 0 auto; padding: 20px;">
1115                 <table width="100%" cellpadding="0" cellspacing="0" style="background: #fff; border: 1px solid #e9e9e9;">
1116                     <tbody>
1117                     <tr>
1118                         <td bgcolor="#eee" style="padding: 5px 20px 5px 20px; background-color: #eee;">
1119                             <div style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 20px; color: #777; font-weight: bold;">netdata notification</div>
1120                         </td>
1121                     </tr>
1122                     <tr>
1123                         <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">
1124                             <h1 style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-weight: 400; margin: 0;">${host} ${status_message}</h1>
1125                         </td>
1126                     </tr>
1127                     <tr>
1128                         <td style="vertical-align: top;" valign="top">
1129                             <div style="margin: 0; padding: 20px; max-width: 700px;">
1130                                 <table width="100%" cellpadding="0" cellspacing="0" style="max-width:700px">
1131                                     <tbody>
1132                                     <tr>
1133                                         <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">
1134                                             <span>${chart}</span>
1135                                             <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Chart</span>
1136                                         </td>
1137                                     </tr>
1138                                     <tr style="margin: 0; padding: 0;">
1139                                         <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">
1140                                             <span><b>${alarm}</b>${info_html}</span>
1141                                             <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Alarm</span>
1142                                         </td>
1143                                     </tr>
1144                                     <tr>
1145                                         <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">
1146                                             <span>${family}</span>
1147                                             <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Family</span>
1148                                         </td>
1149                                     </tr>
1150                                     <tr style="margin: 0; padding: 0;">
1151                                         <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">
1152                                             <span>${severity}</span>
1153                                             <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Severity</span>
1154                                         </td>
1155                                     </tr>
1156                                     <tr style="margin: 0; padding: 0;">
1157                                         <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>
1158                                             <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>
1159                                         </td>
1160                                     </tr>
1161                                     <tr style="margin: 0; padding: 0;">
1162                                         <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;">
1163                                             <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>
1164                                         </td>
1165                                     </tr>
1166                                     <tr style="text-align: center; margin: 0; padding: 0;">
1167                                         <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>
1168                                         </td>
1169                                     </tr>
1170                                     <tr style="text-align: center; margin: 0; padding: 0;">
1171                                         <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
1172                                             <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance monitoring.
1173                                         </td>
1174                                     </tr>
1175                                     </tbody>
1176                                 </table>
1177                             </div>
1178                         </td>
1179                     </tr>
1180                     </tbody>
1181                 </table>
1182             </div>
1183         </td>
1184     </tr>
1185     </tbody>
1186 </table>
1187 </body>
1188 </html>
1189 EOF
1190
1191 SENT_EMAIL=$?
1192
1193 # -----------------------------------------------------------------------------
1194 # let netdata know
1195
1196 if [   ${SENT_EMAIL}        -eq 0 \
1197     -o ${SENT_PUSHOVER}     -eq 0 \
1198     -o ${SENT_TELEGRAM}     -eq 0 \
1199     -o ${SENT_SLACK}        -eq 0 \
1200     -o ${SENT_TWILIO}       -eq 0 \
1201     -o ${SENT_MESSAGEBIRD}  -eq 0 \
1202     -o ${SENT_PUSHBULLET}   -eq 0 \
1203     -o ${SENT_KAFKA}        -eq 0 \
1204     -o ${SENT_PD}           -eq 0 \
1205     ]
1206     then
1207     # we did send something
1208     exit 0
1209 fi
1210
1211 # we did not send anything
1212 exit 1