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