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
24 # - pagerduty.com notifications by Jim Cooley @jimcooley PR#????
26 # -----------------------------------------------------------------------------
27 # testing notifications
29 if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
31 if [ "${2}" = "test" ]
38 [ -z "${recipient}" ] && recipient="sysadmin"
42 for x in "CRITICAL" "WARNING" "CLEAR"
45 echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
47 "${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"
62 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
65 # -----------------------------------------------------------------------------
67 PROGRAM_NAME="$(basename "${0}")"
70 date "+%Y-%m-%d %H:%M:%S"
77 echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
100 [ ${debug} -eq 1 ] && log DEBUG "${@}"
103 # -----------------------------------------------------------------------------
105 # check for BASH v4+ (required for associative arrays)
106 [ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && \
107 fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
109 # -----------------------------------------------------------------------------
110 # defaults to allow running this script by hand
112 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
113 NETDATA_CACHE_DIR="${NETDATA_CACHE_DIR-/var/cache/netdata}"
114 [ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
115 [ -z "${NETDATA_HOSTNAME}" ] && NETDATA_HOSTNAME="$(hostname)"
116 [ -z "${NETDATA_REGISTRY_HOSTNAME}" ] && NETDATA_REGISTRY_HOSTNAME="${NETDATA_HOSTNAME}"
118 # -----------------------------------------------------------------------------
119 # parse command line parameters
121 roles="${1}" # the roles that should be notified for this event
122 host="${2}" # the host generated this event
123 unique_id="${3}" # the unique id of this event
124 alarm_id="${4}" # the unique id of the alarm that generated this event
125 event_id="${5}" # the incremental id of the event, for this alarm id
126 when="${6}" # the timestamp this event occurred
127 name="${7}" # the name of the alarm, as given in netdata health.d entries
128 chart="${8}" # the name of the chart (type.id)
129 family="${9}" # the family of the chart
130 status="${10}" # the current status : REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
131 old_status="${11}" # the previous status: REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
132 value="${12}" # the current value of the alarm
133 old_value="${13}" # the previous value of the alarm
134 src="${14}" # the line number and file the alarm has been configured
135 duration="${15}" # the duration in seconds of the previous alarm state
136 non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
137 units="${17}" # the units of the value
138 info="${18}" # a short description of the alarm
140 # -----------------------------------------------------------------------------
141 # screen statuses we don't need to send a notification
143 # don't do anything if this is not WARNING, CRITICAL or CLEAR
144 if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
146 info "not sending notification for ${status} on '${chart}.${name}'"
150 # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
151 if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
153 info "not sending notification for ${status} on '${chart}.${name}' (last status was ${old_status})"
157 # -----------------------------------------------------------------------------
160 # By default fetch images from the global public registry.
161 # This is required by default, since all notification methods need to download
162 # images via the Internet, and private registries might not be reachable.
163 # This can be overwritten at the configuration file.
164 images_base_url="https://registry.my-netdata.io"
167 # if empty they will be searched in the system path
171 # enable / disable features
177 SEND_PUSHBULLET="YES"
183 DEFAULT_RECIPIENT_SLACK=
184 declare -A role_recipients_slack=()
188 DEFAULT_RECIPIENT_PUSHOVER=
189 declare -A role_recipients_pushover=()
192 PUSHBULLET_ACCESS_TOKEN=
193 DEFAULT_RECIPIENT_PUSHBULLET=
194 declare -A role_recipients_pushbullet=()
198 TWILIO_ACCOUNT_TOKEN=
200 DEFAULT_RECIPIENT_TWILIO=
201 declare -A role_recipients_twilio=()
205 DEFAULT_RECIPIENT_TELEGRAM=
206 declare -A role_recipients_telegram=()
212 # pagerduty.com configs
216 DEFAULT_RECIPIENT_EMAIL="root"
217 declare -A role_recipients_email=()
219 # load the user configuration
220 # this will overwrite the variables above
221 if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ]
223 source "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf"
226 # -----------------------------------------------------------------------------
227 # filter a recipient based on alarm event severity
229 filter_recipient_by_criticality() {
230 local method="${1}" x="${2}" r s
233 r="${x/|*/}" # the recipient
234 s="${x/*|/}" # the severity required for notifying this recipient
236 # no severity filtering for this person
237 [ "${r}" = "${s}" ] && return 0
239 # the severity is invalid
241 [ "${s}" != "CRITICAL" ] && return 0
243 # the new or the old status matches the severity
244 if [ "${s}" = "${status}" -o "${s}" = "${old_status}" ]
246 [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] && \
247 mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
249 # we need to keep track of the notifications we sent
250 # so that the same user will receive the recovery
251 # even if old_status does not match the required severity
252 touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
256 # it is a cleared alarm we have sent notification for
257 if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]
259 rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
266 # -----------------------------------------------------------------------------
267 # find the recipients' addresses per method
269 declare -A arr_slack=()
270 declare -A arr_pushover=()
271 declare -A arr_pushbullet=()
272 declare -A arr_twilio=()
273 declare -A arr_telegram=()
274 declare -A arr_email=()
276 # netdata may call us with multiple roles, and roles may have multiple but
277 # overlapping recipients - so, here we find the unique recipients.
278 for x in ${roles//,/ }
280 # the roles 'silent' and 'disabled' mean:
281 # don't send a notification for this role
282 [ "${x}" = "silent" -o "${x}" = "disabled" ] && continue
285 a="${role_recipients_email[${x}]}"
286 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_EMAIL}"
289 [ "${r}" != "disabled" ] && filter_recipient_by_criticality email "${r}" && arr_email[${r/|*/}]="1"
293 a="${role_recipients_pushover[${x}]}"
294 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHOVER}"
297 [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushover "${r}" && arr_pushover[${r/|*/}]="1"
301 a="${role_recipients_pushbullet[${x}]}"
302 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHBULLET}"
305 [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushbullet "${r}" && arr_pushbullet[${r/|*/}]="1"
309 a="${role_recipients_twilio[${x}]}"
310 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TWILIO}"
313 [ "${r}" != "disabled" ] && filter_recipient_by_criticality twilio "${r}" && arr_twilio[${r/|*/}]="1"
317 a="${role_recipients_telegram[${x}]}"
318 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
321 [ "${r}" != "disabled" ] && filter_recipient_by_criticality telegram "${r}" && arr_telegram[${r/|*/}]="1"
325 a="${role_recipients_slack[${x}]}"
326 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SLACK}"
329 [ "${r}" != "disabled" ] && filter_recipient_by_criticality slack "${r}" && arr_slack[${r/|*/}]="1"
333 # build the list of slack recipients (channels)
334 to_slack="${!arr_slack[*]}"
335 [ -z "${to_slack}" ] && SEND_SLACK="NO"
337 # build the list of pushover recipients (user tokens)
338 to_pushover="${!arr_pushover[*]}"
339 [ -z "${to_pushover}" ] && SEND_PUSHOVER="NO"
341 # build the list of pushbulet recipients (user tokens)
342 to_pushbullet="${!arr_pushbullet[*]}"
343 [ -z "${to_pushbullet}" ] && SEND_PUSHBULLET="NO"
345 # build the list of twilio recipients (phone numbers)
346 to_twilio="${!arr_twilio[*]}"
347 [ -z "${to_twilio}" ] && SEND_TWILIO="NO"
349 # check array of telegram recipients (chat ids)
350 to_telegram="${!arr_telegram[*]}"
351 [ -z "${to_telegram}" ] && SEND_TELEGRAM="NO"
353 # build the list of email recipients (email addresses)
355 for x in "${!arr_email[@]}"
357 [ ! -z "${to_email}" ] && to_email="${to_email}, "
358 to_email="${to_email}${x}"
360 [ -z "${to_email}" ] && SEND_EMAIL="NO"
363 # -----------------------------------------------------------------------------
364 # verify the delivery methods supported
367 [ -z "${SLACK_WEBHOOK_URL}" ] && SEND_SLACK="NO"
370 [ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO"
373 [ -z "${PUSHBULLET_ACCESS_TOKEN}" ] && SEND_PUSHBULLET="NO"
376 [ -z "${TWILIO_ACCOUNT_TOKEN}" -o -z "${TWILIO_ACCOUNT_SID}" -o -z "${TWILIO_NUMBER}" ] && SEND_TWILIO="NO"
379 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
382 [ -z "${KAFKA_URL}" -o -z "${KAFKA_SENDER_IP}" ] && SEND_KAFKA="NO"
384 # check pagerduty.com
385 [ -z "${PD_SERVICE_KEY}" ] && SEND_PD="NO"
387 # if we need pd-send, check for the pd-send command
388 if [ "${SEND_PD}" = "YES" ]
390 pd_send="$(which pd-send 2>/dev/null || command -v pd-send 2>/dev/null)"
391 if [ -z "${pd_send}" ]
393 # no pd-send available
394 # disable pagerduty.com
399 # if we need curl, check for the curl command
400 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}" ]
402 curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
406 # disable all curl based methods
416 # if we need sendmail, check for the sendmail command
417 if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
419 sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)"
420 [ -z "${sendmail}" ] && SEND_EMAIL="NO"
423 # check that we have at least a method enabled
424 if [ "${SEND_EMAIL}" != "YES" \
425 -a "${SEND_PUSHOVER}" != "YES" \
426 -a "${SEND_TELEGRAM}" != "YES" \
427 -a "${SEND_SLACK}" != "YES" \
428 -a "${SEND_TWILIO}" != "YES" \
429 -a "${SEND_PUSHBULLET}" != "YES" \
430 -a "${SEND_KAFKA}" != "YES" \
431 -a "${SEND_PD}" != "YES" \
434 fatal "All notification methods are disabled. Not sending notification to '${role}' for '${name}' = '${value}' of chart '${chart}' for status '${status}'."
437 # -----------------------------------------------------------------------------
438 # find a suitable hostname to use, if netdata did not supply a hostname
440 [ -z "${host}" ] && host="${NETDATA_HOSTNAME}"
441 [ -z "${host}" ] && host="${NETDATA_REGISTRY_HOSTNAME}"
442 [ -z "${host}" ] && host="$(hostname 2>/dev/null)"
444 # -----------------------------------------------------------------------------
445 # get the date the alarm happened
447 date="$(date --date=@${when} 2>/dev/null)"
448 [ -z "${date}" ] && date="$(date 2>/dev/null)"
450 # -----------------------------------------------------------------------------
451 # function to URL encode a string
454 local string="${1}" strlen encoded pos c o
457 for (( pos=0 ; pos<strlen ; pos++ ))
466 printf -v o '%%%02x' "'${c}"
476 # -----------------------------------------------------------------------------
477 # function to convert a duration in seconds, to a human readable duration
478 # using DAYS, MINUTES, SECONDS
481 local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
483 s=$(( s - (d * 86400) ))
485 s=$(( s - (h * 3600) ))
487 s=$(( s - (m * 60) ))
491 [ ${m} -ge 30 ] && h=$(( h + 1 ))
492 [ ${d} -gt 1 ] && ds="days"
493 [ ${h} -gt 1 ] && hs="hours"
496 ret="${d} ${ds} and ${h} ${hs}"
502 [ ${s} -ge 30 ] && m=$(( m + 1 ))
503 [ ${h} -gt 1 ] && hs="hours"
504 [ ${m} -gt 1 ] && ms="minutes"
507 ret="${h} ${hs} and ${m} ${ms}"
513 [ ${m} -gt 1 ] && ms="minutes"
514 [ ${s} -gt 1 ] && ss="seconds"
517 ret="${m} ${ms} and ${s} ${ss}"
522 [ ${s} -gt 1 ] && ss="seconds"
530 # -----------------------------------------------------------------------------
535 if [ "${SEND_EMAIL}" = "YES" ]
543 info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
546 error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
554 # -----------------------------------------------------------------------------
558 local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority
560 if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertokens}" -a ! -z "${title}" -a ! -z "${message}" ]
563 # https://pushover.net/api
566 CLEAR) priority=-1;; # low priority: no sound or vibration
567 WARNING) priotity=0;; # normal priority: respect quiet hours
568 CRITICAL) priority=1;; # high priority: bypass quiet hours
569 *) priority=-2;; # lowest priority: no notification at all
572 for user in ${usertokens}
574 httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
575 --form-string "token=${apptoken}" \
576 --form-string "user=${user}" \
577 --form-string "html=1" \
578 --form-string "title=${title}" \
579 --form-string "message=${message}" \
580 --form-string "timestamp=${when}" \
581 --form-string "url=${url}" \
582 --form-string "url_title=Open netdata dashboard to view the alarm" \
583 --form-string "priority=${priority}" \
584 https://api.pushover.net/1/messages.json)
586 if [ "${httpcode}" == "200" ]
588 info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
591 error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
595 [ ${sent} -gt 0 ] && return 0
601 # -----------------------------------------------------------------------------
605 local userapikey="${1}" recipients="${2}" title="${3}" message="${4}" httpcode sent=0 user
606 if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikey}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
608 #https://docs.pushbullet.com/#create-push
609 for user in ${recipients}
611 httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
612 --header 'Access-Token: '${userapikey}'' \
613 --header 'Content-Type: application/json' \
614 --data-binary @<(cat <<EOF
615 {"title": "${title}",
618 "body": "$( echo -n ${message})"}
620 ) "https://api.pushbullet.com/v2/pushes" -X POST)
622 if [ "${httpcode}" == "200" ]
624 info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
627 error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
631 [ ${sent} -gt 0 ] && return 0
637 # -----------------------------------------------------------------------------
641 local httpcode sent=0
642 if [ "${SEND_KAFKA}" = "YES" ]
644 httpcode=$(${curl} -X POST --write-out %{http_code} --silent --output /dev/null \
645 --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}\"}" \
648 if [ "${httpcode}" == "204" ]
650 info "sent kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}'"
653 error "failed to send kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}' with HTTP error code ${httpcode}."
656 [ ${sent} -gt 0 ] && return 0
662 # -----------------------------------------------------------------------------
663 # pagerduty.com sender
669 WARNING) t='trigger';;
670 CRITICAL) t='trigger';;
673 if [ ${SEND_PD} = "YES" -a ! -z "${t}" ]
675 ${pd_send} -k ${PD_SERVICE_KEY} \
677 -d "${host} ${chart}.${name} is ${status}" \
679 -f 'info'="${info}" \
680 -f 'value'="${value} ${units}" \
681 -f 'when'="${when}" \
682 -f 'duration'="${duration}"
684 if [ ${retval} -eq 0 ]
686 info "sent pagerduty.com notification for: ${host} ${chart}.${name} is ${status}"
689 error "failed to send pagerduty.com notification for: ${host} ${chart}.${name} is ${status} with error code ${retval}."
696 # -----------------------------------------------------------------------------
700 local accountsid="${1}" accounttoken="${2}" twilionumber="${3}" recipients="${4}" title="${5}" message="${6}" httpcode sent=0 user
701 if [ "${SEND_TWILIO}" = "YES" -a ! -z "${accountsid}" -a ! -z "${accounttoken}" -a ! -z "${twilionumber}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
703 #https://www.twilio.com/packages/labs/code/bash/twilio-sms
704 for user in ${recipients}
706 httpcode=$(${curl} -X POST --write-out %{http_code} --silent --output /dev/null \
707 --data-urlencode "From=${twilionumber}" \
708 --data-urlencode "To=${user}" \
709 --data-urlencode "Body=${title} ${message}" \
710 -u "${accountsid}:${accounttoken}" \
711 "https://api.twilio.com/2010-04-01/Accounts/${accountsid}/Messages.json")
713 if [ "${httpcode}" == "201" ]
715 info "sent Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
718 error "failed to send Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
722 [ ${sent} -gt 0 ] && return 0
728 # -----------------------------------------------------------------------------
732 local bottoken="${1}" chatids="${2}" message="${3}" httpcode sent=0 chatid disableNotification=""
734 if [ "${status}" = "CLEAR" ]; then disableNotification="--data-urlencode disable_notification=true"; fi
736 if [ "${SEND_TELEGRAM}" = "YES" -a ! -z "${bottoken}" -a ! -z "${chatids}" -a ! -z "${message}" ];
738 for chatid in ${chatids}
740 # https://core.telegram.org/bots/api#sendmessage
741 httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null ${disableNotification} \
742 --data-urlencode "parse_mode=HTML" \
743 --data-urlencode "disable_web_page_preview=true" \
744 --data-urlencode "text=${message}" \
745 "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatid}")
747 if [ "${httpcode}" == "200" ]
749 info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
751 elif [ "${httpcode}" == "401" ]
753 error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
755 error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
759 [ ${sent} -gt 0 ] && return 0
765 # -----------------------------------------------------------------------------
769 local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
771 [ "${SEND_SLACK}" != "YES" ] && return 1
774 WARNING) color="warning" ;;
775 CRITICAL) color="danger" ;;
776 CLEAR) color="good" ;;
777 *) color="#777777" ;;
780 for channel in ${channels}
784 "channel": "#${channel}",
785 "username": "netdata on ${host}",
786 "icon_url": "${images_base_url}/images/seo-performance-128.png",
787 "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
790 "fallback": "${alarm} - ${chart} (${family}) - ${info}",
793 "title_link": "${goto_url}",
801 "title": "${family}",
805 "thumb_url": "${image}",
806 "footer": "<${goto_url}|${host}>",
814 httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null -X POST --data-urlencode "payload=${payload}" "${webhook}")
815 if [ "${httpcode}" == "200" ]
817 info "sent slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
820 error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
824 [ ${sent} -gt 0 ] && return 0
830 # -----------------------------------------------------------------------------
831 # prepare the content of the notification
833 # the url to send the user on click
834 urlencode "${NETDATA_REGISTRY_HOSTNAME}" >/dev/null; url_host="${REPLY}"
835 urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
836 urlencode "${family}" >/dev/null; url_family="${REPLY}"
837 urlencode "${name}" >/dev/null; url_name="${REPLY}"
838 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}"
840 # the severity of the alarm
843 # the time the alarm was raised
844 duration4human ${duration} >/dev/null; duration_txt="${REPLY}"
845 duration4human ${non_clear_duration} >/dev/null; non_clear_duration_txt="${REPLY}"
846 raised_for="(was ${old_status,,} for ${duration_txt})"
848 # the key status message
849 status_message="status unknown"
851 # the color of the alarm
855 alarm="${name//_/ } = ${value} ${units}"
857 # the image of the alarm
858 image="${images_base_url}/images/seo-performance-128.png"
860 # prepare the title based on status
863 image="${images_base_url}/images/alert-128-red.png"
864 status_message="is critical"
869 image="${images_base_url}/images/alert-128-orange.png"
870 status_message="needs attention"
875 image="${images_base_url}/images/check-mark-2-128-green.png"
876 status_message="recovered"
881 if [ "${status}" = "CLEAR" ]
883 severity="Recovered from ${old_status}"
884 if [ ${non_clear_duration} -gt ${duration} ]
886 raised_for="(alarm was raised for ${non_clear_duration_txt})"
889 # don't show the value when the status is CLEAR
890 # for certain alarms, this value might not have any meaning
891 alarm="${name//_/ } ${raised_for}"
893 elif [ "${old_status}" = "WARNING" -a "${status}" = "CRITICAL" ]
895 severity="Escalated to ${status}"
896 if [ ${non_clear_duration} -gt ${duration} ]
898 raised_for="(alarm is raised for ${non_clear_duration_txt})"
901 elif [ "${old_status}" = "CRITICAL" -a "${status}" = "WARNING" ]
903 severity="Demoted to ${status}"
904 if [ ${non_clear_duration} -gt ${duration} ]
906 raised_for="(alarm is raised for ${non_clear_duration_txt})"
913 # prepare HTML versions of elements
915 [ ! -z "${info}" ] && info_html=" <small><br/>${info}</small>"
918 [ ! -z "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
920 # -----------------------------------------------------------------------------
921 # send the slack notification
923 # slack aggregates posts from the same username
924 # so we use "${host} ${status}" as the bot username, to make them diff
926 send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
929 # -----------------------------------------------------------------------------
930 # send the pushover notification
932 send_pushover "${PUSHOVER_APP_TOKEN}" "${to_pushover}" "${when}" "${goto_url}" "${status}" "${host} ${status_message} - ${name//_/ } - ${chart}" "
933 <font color=\"${color}\"><b>${alarm}</b></font>${info_html}<br/>
934 <small><b>${chart}</b><br/>Chart<br/> </small>
935 <small><b>${family}</b><br/>Family<br/> </small>
936 <small><b>${severity}</b><br/>Severity<br/> </small>
937 <small><b>${date}${raised_for_html}</b><br/>Time<br/> </small>
938 <a href=\"${goto_url}\">View Netdata</a><br/>
939 <small><small>The source of this alarm is line ${src}</small></small>
944 # -----------------------------------------------------------------------------
945 # send the pushbullet notification
947 send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${to_pushbullet}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\n
948 Severity: ${severity}\n
951 To View Netdata go to: ${goto_url}\n
952 The source of this alarm is line ${src}"
956 # -----------------------------------------------------------------------------
957 # send the twilio SMS
959 send_twilio "${TWILIO_ACCOUNT_SID}" "${TWILIO_ACCOUNT_TOKEN}" "${TWILIO_NUMBER}" "${to_twilio}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
960 Severity: ${severity}
967 # -----------------------------------------------------------------------------
968 # send the telegram.org message
970 # https://core.telegram.org/bots/api#formatting-options
971 send_telegram "${TELEGRAM_BOT_TOKEN}" "${to_telegram}" "${host} ${status_message} - <b>${name//_/ }</b>
973 <a href=\"${goto_url}\">${alarm}</a>
979 # -----------------------------------------------------------------------------
980 # send the kafka message
986 # -----------------------------------------------------------------------------
987 # send the pagerduty.com message
993 # -----------------------------------------------------------------------------
998 Subject: ${host} ${status_message} - ${name//_/ } - ${chart}
999 Content-Type: text/html
1001 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1002 <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;">
1003 <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;">
1007 <td style="vertical-align: top;" valign="top"></td>
1008 <td width="700" style="vertical-align: top; display: block !important; max-width: 700px !important; clear: both !important; margin: 0 auto; padding: 0;" valign="top">
1009 <div style="max-width: 700px; display: block; margin: 0 auto; padding: 20px;">
1010 <table width="100%" cellpadding="0" cellspacing="0" style="background: #fff; border: 1px solid #e9e9e9;">
1013 <td bgcolor="#eee" style="padding: 5px 20px 5px 20px; background-color: #eee;">
1014 <div style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 20px; color: #777; font-weight: bold;">netdata notification</div>
1018 <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">
1019 <h1 style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-weight: 400; margin: 0;">${host} ${status_message}</h1>
1023 <td style="vertical-align: top;" valign="top">
1024 <div style="margin: 0; padding: 20px; max-width: 700px;">
1025 <table width="100%" cellpadding="0" cellspacing="0" style="max-width:700px">
1028 <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">
1029 <span>${chart}</span>
1030 <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Chart</span>
1033 <tr style="margin: 0; padding: 0;">
1034 <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">
1035 <span><b>${alarm}</b>${info_html}</span>
1036 <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Alarm</span>
1040 <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">
1041 <span>${family}</span>
1042 <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Family</span>
1045 <tr style="margin: 0; padding: 0;">
1046 <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">
1047 <span>${severity}</span>
1048 <span style="display: block; color: #666666; font-size: 12px; font-weight: 300; line-height: 1; text-transform: uppercase;">Severity</span>
1051 <tr style="margin: 0; padding: 0;">
1052 <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>
1053 <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>
1056 <tr style="margin: 0; padding: 0;">
1057 <td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px;">
1058 <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>
1061 <tr style="text-align: center; margin: 0; padding: 0;">
1062 <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>
1065 <tr style="text-align: center; margin: 0; padding: 0;">
1066 <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
1067 <a href="https://mynetdata.io/" target="_blank">netdata</a>, the real-time performance monitoring.
1088 # -----------------------------------------------------------------------------
1091 if [ ${SENT_EMAIL} -eq 0 \
1092 -o ${SENT_PUSHOVER} -eq 0 \
1093 -o ${SENT_TELEGRAM} -eq 0 \
1094 -o ${SENT_SLACK} -eq 0 \
1095 -o ${SENT_TWILIO} -eq 0 \
1096 -o ${SENT_PUSHBULLET} -eq 0 \
1097 -o ${SENT_KAFKA} -eq 0 \
1098 -o ${SENT_PD} -eq 0 \
1101 # we did send something
1105 # we did not send anything