4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
8 # Script to send alarm notifications for netdata
11 # - multiple notification methods
12 # - multiple roles per alarm
13 # - multiple recipients per role
14 # - severity filtering per recipient
16 # Supported notification methods:
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
25 # -----------------------------------------------------------------------------
26 # testing notifications
28 if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
30 if [ "${2}" = "test" ]
37 [ -z "${recipient}" ] && recipient="sysadmin"
41 for x in "CRITICAL" "WARNING" "CLEAR"
44 echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
46 "${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"
61 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
64 # -----------------------------------------------------------------------------
66 PROGRAM_NAME="$(basename "${0}")"
69 date "+%Y-%m-%d %H:%M:%S"
76 echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
99 [ ${debug} -eq 1 ] && log DEBUG "${@}"
102 # -----------------------------------------------------------------------------
104 # check for BASH v4+ (required for associative arrays)
105 [ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && \
106 fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
108 # -----------------------------------------------------------------------------
109 # defaults to allow running this script by hand
111 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
112 NETDATA_CACHE_DIR="${NETDATA_CACHE_DIR-/var/cache/netdata}"
113 [ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
114 [ -z "${NETDATA_HOSTNAME}" ] && NETDATA_HOSTNAME="$(hostname)"
115 [ -z "${NETDATA_REGISTRY_HOSTNAME}" ] && NETDATA_REGISTRY_HOSTNAME="${NETDATA_HOSTNAME}"
117 # -----------------------------------------------------------------------------
118 # parse command line parameters
120 roles="${1}" # the roles that should be notified for this event
121 host="${2}" # the host generated this event
122 unique_id="${3}" # the unique id of this event
123 alarm_id="${4}" # the unique id of the alarm that generated this event
124 event_id="${5}" # the incremental id of the event, for this alarm id
125 when="${6}" # the timestamp this event occurred
126 name="${7}" # the name of the alarm, as given in netdata health.d entries
127 chart="${8}" # the name of the chart (type.id)
128 family="${9}" # the family of the chart
129 status="${10}" # the current status : REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
130 old_status="${11}" # the previous status: REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
131 value="${12}" # the current value of the alarm
132 old_value="${13}" # the previous value of the alarm
133 src="${14}" # the line number and file the alarm has been configured
134 duration="${15}" # the duration in seconds of the previous alarm state
135 non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
136 units="${17}" # the units of the value
137 info="${18}" # a short description of the alarm
139 # -----------------------------------------------------------------------------
140 # screen statuses we don't need to send a notification
142 # don't do anything if this is not WARNING, CRITICAL or CLEAR
143 if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
145 info "not sending notification for ${status} on '${chart}.${name}'"
149 # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
150 if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
152 info "not sending notification for ${status} on '${chart}.${name}' (last status was ${old_status})"
156 # -----------------------------------------------------------------------------
159 # By default fetch images from the global public registry.
160 # This is required by default, since all notification methods need to download
161 # images via the Internet, and private registries might not be reachable.
162 # This can be overwritten at the configuration file.
163 images_base_url="https://registry.my-netdata.io"
166 # if empty they will be searched in the system path
170 # enable / disable features
176 SEND_PUSHBULLET="YES"
181 DEFAULT_RECIPIENT_SLACK=
182 declare -A role_recipients_slack=()
186 DEFAULT_RECIPIENT_PUSHOVER=
187 declare -A role_recipients_pushover=()
190 PUSHBULLET_ACCESS_TOKEN=
191 DEFAULT_RECIPIENT_PUSHBULLET=
192 declare -A role_recipients_pushbullet=()
196 TWILIO_ACCOUNT_TOKEN=
198 DEFAULT_RECIPIENT_TWILIO=
199 declare -A role_recipients_twilio=()
203 DEFAULT_RECIPIENT_TELEGRAM=
204 declare -A role_recipients_telegram=()
211 DEFAULT_RECIPIENT_EMAIL="root"
212 declare -A role_recipients_email=()
214 # load the user configuration
215 # this will overwrite the variables above
216 if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ]
218 source "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf"
221 # -----------------------------------------------------------------------------
222 # filter a recipient based on alarm event severity
224 filter_recipient_by_criticality() {
225 local method="${1}" x="${2}" r s
228 r="${x/|*/}" # the recipient
229 s="${x/*|/}" # the severity required for notifying this recipient
231 # no severity filtering for this person
232 [ "${r}" = "${s}" ] && return 0
234 # the severity is invalid
236 [ "${s}" != "CRITICAL" ] && return 0
238 # the new or the old status matches the severity
239 if [ "${s}" = "${status}" -o "${s}" = "${old_status}" ]
241 [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] && \
242 mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
244 # we need to keep track of the notifications we sent
245 # so that the same user will receive the recovery
246 # even if old_status does not match the required severity
247 touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
251 # it is a cleared alarm we have sent notification for
252 if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]
254 rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
261 # -----------------------------------------------------------------------------
262 # find the recipients' addresses per method
264 declare -A arr_slack=()
265 declare -A arr_pushover=()
266 declare -A arr_pushbullet=()
267 declare -A arr_twilio=()
268 declare -A arr_telegram=()
269 declare -A arr_email=()
271 # netdata may call us with multiple roles, and roles may have multiple but
272 # overlapping recipients - so, here we find the unique recipients.
273 for x in ${roles//,/ }
275 # the roles 'silent' and 'disabled' mean:
276 # don't send a notification for this role
277 [ "${x}" = "silent" -o "${x}" = "disabled" ] && continue
280 a="${role_recipients_email[${x}]}"
281 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_EMAIL}"
284 [ "${r}" != "disabled" ] && filter_recipient_by_criticality email "${r}" && arr_email[${r/|*/}]="1"
288 a="${role_recipients_pushover[${x}]}"
289 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHOVER}"
292 [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushover "${r}" && arr_pushover[${r/|*/}]="1"
296 a="${role_recipients_pushbullet[${x}]}"
297 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHBULLET}"
300 [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushbullet "${r}" && arr_pushbullet[${r/|*/}]="1"
304 a="${role_recipients_twilio[${x}]}"
305 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TWILIO}"
308 [ "${r}" != "disabled" ] && filter_recipient_by_criticality twilio "${r}" && arr_twilio[${r/|*/}]="1"
312 a="${role_recipients_telegram[${x}]}"
313 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
316 [ "${r}" != "disabled" ] && filter_recipient_by_criticality telegram "${r}" && arr_telegram[${r/|*/}]="1"
320 a="${role_recipients_slack[${x}]}"
321 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SLACK}"
324 [ "${r}" != "disabled" ] && filter_recipient_by_criticality slack "${r}" && arr_slack[${r/|*/}]="1"
328 # build the list of slack recipients (channels)
329 to_slack="${!arr_slack[*]}"
330 [ -z "${to_slack}" ] && SEND_SLACK="NO"
332 # build the list of pushover recipients (user tokens)
333 to_pushover="${!arr_pushover[*]}"
334 [ -z "${to_pushover}" ] && SEND_PUSHOVER="NO"
336 # build the list of pushbulet recipients (user tokens)
337 to_pushbullet="${!arr_pushbullet[*]}"
338 [ -z "${to_pushbullet}" ] && SEND_PUSHBULLET="NO"
340 # build the list of twilio recipients (phone numbers)
341 to_twilio="${!arr_twilio[*]}"
342 [ -z "${to_twilio}" ] && SEND_TWILIO="NO"
344 # check array of telegram recipients (chat ids)
345 to_telegram="${!arr_telegram[*]}"
346 [ -z "${to_telegram}" ] && SEND_TELEGRAM="NO"
348 # build the list of email recipients (email addresses)
350 for x in "${!arr_email[@]}"
352 [ ! -z "${to_email}" ] && to_email="${to_email}, "
353 to_email="${to_email}${x}"
355 [ -z "${to_email}" ] && SEND_EMAIL="NO"
358 # -----------------------------------------------------------------------------
359 # verify the delivery methods supported
362 [ -z "${SLACK_WEBHOOK_URL}" ] && SEND_SLACK="NO"
365 [ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO"
368 [ -z "${PUSHBULLET_ACCESS_TOKEN}" ] && SEND_PUSHBULLET="NO"
371 [ -z "${TWILIO_ACCOUNT_TOKEN}" -o -z "${TWILIO_ACCOUNT_SID}" -o -z "${TWILIO_NUMBER}" ] && SEND_TWILIO="NO"
374 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
377 [ -z "${KAFKA_URL}" -o -z "${KAFKA_SENDER_IP}" ] && SEND_KAFKA="NO"
379 # if we need curl, check for the curl command
380 if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TWILIO}" = "YES" -o "${SEND_TELEGRAM}" = "YES" -o "${SEND_PUSHBULLET}" = "YES" -o "${SEND_KAFKA}" = "YES" \) -a -z "${curl}" ]
382 curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
386 # disable all curl based methods
396 # if we need sendmail, check for the sendmail command
397 if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
399 sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)"
400 [ -z "${sendmail}" ] && SEND_EMAIL="NO"
403 # check that we have at least a method enabled
404 if [ "${SEND_EMAIL}" != "YES" \
405 -a "${SEND_PUSHOVER}" != "YES" \
406 -a "${SEND_TELEGRAM}" != "YES" \
407 -a "${SEND_SLACK}" != "YES" \
408 -a "${SEND_TWILIO}" != "YES" \
409 -a "${SEND_PUSHBULLET}" != "YES" \
410 -a "${SEND_KAFKA}" != "YES" \
413 fatal "All notification methods are disabled. Not sending notification to '${role}' for '${name}' = '${value}' of chart '${chart}' for status '${status}'."
416 # -----------------------------------------------------------------------------
417 # find a suitable hostname to use, if netdata did not supply a hostname
419 [ -z "${host}" ] && host="${NETDATA_HOSTNAME}"
420 [ -z "${host}" ] && host="${NETDATA_REGISTRY_HOSTNAME}"
421 [ -z "${host}" ] && host="$(hostname 2>/dev/null)"
423 # -----------------------------------------------------------------------------
424 # get the date the alarm happened
426 date="$(date --date=@${when} 2>/dev/null)"
427 [ -z "${date}" ] && date="$(date 2>/dev/null)"
429 # -----------------------------------------------------------------------------
430 # function to URL encode a string
433 local string="${1}" strlen encoded pos c o
436 for (( pos=0 ; pos<strlen ; pos++ ))
445 printf -v o '%%%02x' "'${c}"
455 # -----------------------------------------------------------------------------
456 # function to convert a duration in seconds, to a human readable duration
457 # using DAYS, MINUTES, SECONDS
460 local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
462 s=$(( s - (d * 86400) ))
464 s=$(( s - (h * 3600) ))
466 s=$(( s - (m * 60) ))
470 [ ${m} -ge 30 ] && h=$(( h + 1 ))
471 [ ${d} -gt 1 ] && ds="days"
472 [ ${h} -gt 1 ] && hs="hours"
475 ret="${d} ${ds} and ${h} ${hs}"
481 [ ${s} -ge 30 ] && m=$(( m + 1 ))
482 [ ${h} -gt 1 ] && hs="hours"
483 [ ${m} -gt 1 ] && ms="minutes"
486 ret="${h} ${hs} and ${m} ${ms}"
492 [ ${m} -gt 1 ] && ms="minutes"
493 [ ${s} -gt 1 ] && ss="seconds"
496 ret="${m} ${ms} and ${s} ${ss}"
501 [ ${s} -gt 1 ] && ss="seconds"
509 # -----------------------------------------------------------------------------
514 if [ "${SEND_EMAIL}" = "YES" ]
522 info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
525 error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
533 # -----------------------------------------------------------------------------
537 local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority
539 if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertokens}" -a ! -z "${title}" -a ! -z "${message}" ]
542 # https://pushover.net/api
545 CLEAR) priority=-1;; # low priority: no sound or vibration
546 WARNING) priotity=0;; # normal priority: respect quiet hours
547 CRITICAL) priority=1;; # high priority: bypass quiet hours
548 *) priority=-2;; # lowest priority: no notification at all
551 for user in ${usertokens}
553 httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
554 --form-string "token=${apptoken}" \
555 --form-string "user=${user}" \
556 --form-string "html=1" \
557 --form-string "title=${title}" \
558 --form-string "message=${message}" \
559 --form-string "timestamp=${when}" \
560 --form-string "url=${url}" \
561 --form-string "url_title=Open netdata dashboard to view the alarm" \
562 --form-string "priority=${priority}" \
563 https://api.pushover.net/1/messages.json)
565 if [ "${httpcode}" == "200" ]
567 info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
570 error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
574 [ ${sent} -gt 0 ] && return 0
580 # -----------------------------------------------------------------------------
584 local userapikey="${1}" recipients="${2}" title="${3}" message="${4}" httpcode sent=0 user
585 if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikey}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
587 #https://docs.pushbullet.com/#create-push
588 for user in ${recipients}
590 httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
591 --header 'Access-Token: '${userapikey}'' \
592 --header 'Content-Type: application/json' \
593 --data-binary @<(cat <<EOF
594 {"title": "${title}",
597 "body": "$( echo -n ${message})"}
599 ) "https://api.pushbullet.com/v2/pushes" -X POST)
601 if [ "${httpcode}" == "200" ]
603 info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
606 error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
610 [ ${sent} -gt 0 ] && return 0
616 # -----------------------------------------------------------------------------
620 local httpcode sent=0
621 if [ "${SEND_KAFKA}" = "YES" ]
623 httpcode=$(${curl} -X POST --write-out %{http_code} --silent --output /dev/null \
624 --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}\"}" \
627 if [ "${httpcode}" == "204" ]
629 info "sent kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}'"
632 error "failed to send kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}' with HTTP error code ${httpcode}."
635 [ ${sent} -gt 0 ] && return 0
641 # -----------------------------------------------------------------------------
645 local accountsid="${1}" accounttoken="${2}" twilionumber="${3}" recipients="${4}" title="${5}" message="${6}" httpcode sent=0 user
646 if [ "${SEND_TWILIO}" = "YES" -a ! -z "${accountsid}" -a ! -z "${accounttoken}" -a ! -z "${twilionumber}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
648 #https://www.twilio.com/packages/labs/code/bash/twilio-sms
649 for user in ${recipients}
651 httpcode=$(${curl} -X POST --write-out %{http_code} --silent --output /dev/null \
652 --data-urlencode "From=${twilionumber}" \
653 --data-urlencode "To=${user}" \
654 --data-urlencode "Body=${title} ${message}" \
655 -u "${accountsid}:${accounttoken}" \
656 "https://api.twilio.com/2010-04-01/Accounts/${accountsid}/Messages.json")
658 if [ "${httpcode}" == "201" ]
660 info "sent Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
663 error "failed to send Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
667 [ ${sent} -gt 0 ] && return 0
673 # -----------------------------------------------------------------------------
677 local bottoken="${1}" chatids="${2}" message="${3}" httpcode sent=0 chatid disableNotification=""
679 if [ "${status}" = "CLEAR" ]; then disableNotification="--data-urlencode disable_notification=true"; fi
681 if [ "${SEND_TELEGRAM}" = "YES" -a ! -z "${bottoken}" -a ! -z "${chatids}" -a ! -z "${message}" ];
683 for chatid in ${chatids}
685 # https://core.telegram.org/bots/api#sendmessage
686 httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null ${disableNotification} \
687 --data-urlencode "parse_mode=HTML" \
688 --data-urlencode "disable_web_page_preview=true" \
689 --data-urlencode "text=${message}" \
690 "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatid}")
692 if [ "${httpcode}" == "200" ]
694 info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
696 elif [ "${httpcode}" == "401" ]
698 error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
700 error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
704 [ ${sent} -gt 0 ] && return 0
710 # -----------------------------------------------------------------------------
714 local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
716 [ "${SEND_SLACK}" != "YES" ] && return 1
719 WARNING) color="warning" ;;
720 CRITICAL) color="danger" ;;
721 CLEAR) color="good" ;;
722 *) color="#777777" ;;
725 for channel in ${channels}
729 "channel": "#${channel}",
730 "username": "netdata on ${host}",
731 "icon_url": "${images_base_url}/images/seo-performance-128.png",
732 "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
735 "fallback": "${alarm} - ${chart} (${family}) - ${info}",
738 "title_link": "${goto_url}",
746 "title": "${family}",
750 "thumb_url": "${image}",
751 "footer": "<${goto_url}|${host}>",
759 httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null -X POST --data-urlencode "payload=${payload}" "${webhook}")
760 if [ "${httpcode}" == "200" ]
762 info "sent slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
765 error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
769 [ ${sent} -gt 0 ] && return 0
775 # -----------------------------------------------------------------------------
776 # prepare the content of the notification
778 # the url to send the user on click
779 urlencode "${NETDATA_REGISTRY_HOSTNAME}" >/dev/null; url_host="${REPLY}"
780 urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
781 urlencode "${family}" >/dev/null; url_family="${REPLY}"
782 urlencode "${name}" >/dev/null; url_name="${REPLY}"
783 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}"
785 # the severity of the alarm
788 # the time the alarm was raised
789 duration4human ${duration} >/dev/null; duration_txt="${REPLY}"
790 duration4human ${non_clear_duration} >/dev/null; non_clear_duration_txt="${REPLY}"
791 raised_for="(was ${old_status,,} for ${duration_txt})"
793 # the key status message
794 status_message="status unknown"
796 # the color of the alarm
800 alarm="${name//_/ } = ${value} ${units}"
802 # the image of the alarm
803 image="${images_base_url}/images/seo-performance-128.png"
805 # prepare the title based on status
808 image="${images_base_url}/images/alert-128-red.png"
809 status_message="is critical"
814 image="${images_base_url}/images/alert-128-orange.png"
815 status_message="needs attention"
820 image="${images_base_url}/images/check-mark-2-128-green.png"
821 status_message="recovered"
826 if [ "${status}" = "CLEAR" ]
828 severity="Recovered from ${old_status}"
829 if [ ${non_clear_duration} -gt ${duration} ]
831 raised_for="(alarm was raised for ${non_clear_duration_txt})"
834 # don't show the value when the status is CLEAR
835 # for certain alarms, this value might not have any meaning
836 alarm="${name//_/ } ${raised_for}"
838 elif [ "${old_status}" = "WARNING" -a "${status}" = "CRITICAL" ]
840 severity="Escalated to ${status}"
841 if [ ${non_clear_duration} -gt ${duration} ]
843 raised_for="(alarm is raised for ${non_clear_duration_txt})"
846 elif [ "${old_status}" = "CRITICAL" -a "${status}" = "WARNING" ]
848 severity="Demoted to ${status}"
849 if [ ${non_clear_duration} -gt ${duration} ]
851 raised_for="(alarm is raised for ${non_clear_duration_txt})"
858 # prepare HTML versions of elements
860 [ ! -z "${info}" ] && info_html=" <small><br/>${info}</small>"
863 [ ! -z "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
865 # -----------------------------------------------------------------------------
866 # send the slack notification
868 # slack aggregates posts from the same username
869 # so we use "${host} ${status}" as the bot username, to make them diff
871 send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
874 # -----------------------------------------------------------------------------
875 # send the pushover notification
877 send_pushover "${PUSHOVER_APP_TOKEN}" "${to_pushover}" "${when}" "${goto_url}" "${status}" "${host} ${status_message} - ${name//_/ } - ${chart}" "
878 <font color=\"${color}\"><b>${alarm}</b></font>${info_html}<br/>
879 <small><b>${chart}</b><br/>Chart<br/> </small>
880 <small><b>${family}</b><br/>Family<br/> </small>
881 <small><b>${severity}</b><br/>Severity<br/> </small>
882 <small><b>${date}${raised_for_html}</b><br/>Time<br/> </small>
883 <a href=\"${goto_url}\">View Netdata</a><br/>
884 <small><small>The source of this alarm is line ${src}</small></small>
889 # -----------------------------------------------------------------------------
890 # send the pushbullet notification
892 send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${to_pushbullet}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\n
893 Severity: ${severity}\n
896 To View Netdata go to: ${goto_url}\n
897 The source of this alarm is line ${src}"
901 # -----------------------------------------------------------------------------
902 # send the twilio SMS
904 send_twilio "${TWILIO_ACCOUNT_SID}" "${TWILIO_ACCOUNT_TOKEN}" "${TWILIO_NUMBER}" "${to_twilio}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
905 Severity: ${severity}
912 # -----------------------------------------------------------------------------
913 # send the telegram.org message
915 # https://core.telegram.org/bots/api#formatting-options
916 send_telegram "${TELEGRAM_BOT_TOKEN}" "${to_telegram}" "${host} ${status_message} - <b>${name//_/ }</b>
918 <a href=\"${goto_url}\">${alarm}</a>
924 # -----------------------------------------------------------------------------
925 # send the kafka message
931 # -----------------------------------------------------------------------------
936 Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
937 Content-Type: text/html
939 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
940 <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;">
941 <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;">
945 <td style="vertical-align: top;" valign="top"></td>
946 <td width="700" style="vertical-align: top; display: block !important; max-width: 700px !important; clear: both !important; margin: 0 auto; padding: 0;" valign="top">
947 <div style="max-width: 700px; display: block; margin: 0 auto; padding: 20px;">
948 <table width="100%" cellpadding="0" cellspacing="0" style="background: #fff; border: 1px solid #e9e9e9;">
951 <td bgcolor="#eee" style="padding: 5px 20px 5px 20px; background-color: #eee;">
952 <div style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 20px; color: #777; font-weight: bold;">netdata notification</div>
956 <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">
957 <h1 style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-weight: 400; margin: 0;">${host} ${status_message}</h1>
961 <td style="vertical-align: top;" valign="top">
962 <div style="margin: 0; padding: 20px; max-width: 700px;">
963 <table width="100%" cellpadding="0" cellspacing="0" style="max-width:700px">
966 <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">
967 <span>${chart}</span>
968 <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Chart</span>
971 <tr style="margin: 0; padding: 0;">
972 <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">
973 <span><b>${alarm}</b>${info_html}</span>
974 <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Alarm</span>
978 <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">
979 <span>${family}</span>
980 <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Family</span>
983 <tr style="margin: 0; padding: 0;">
984 <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">
985 <span>${severity}</span>
986 <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Severity</span>
989 <tr style="margin: 0; padding: 0;">
990 <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>
991 <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>
994 <tr style="margin: 0; padding: 0;">
995 <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;">
996 <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>
999 <tr style="text-align: center; margin: 0; padding: 0;">
1000 <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>
1003 <tr style="text-align: center; margin: 0; padding: 0;">
1004 <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
1005 <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance monitoring.
1026 # -----------------------------------------------------------------------------
1029 if [ ${SENT_EMAIL} -eq 0 \
1030 -o ${SENT_PUSHOVER} -eq 0 \
1031 -o ${SENT_TELEGRAM} -eq 0 \
1032 -o ${SENT_SLACK} -eq 0 \
1033 -o ${SENT_TWILIO} -eq 0 \
1034 -o ${SENT_PUSHBULLET} -eq 0 \
1035 -o ${SENT_KAFKA} -eq 0 \
1038 # we did send something
1042 # we did not send anything