@cryptotaxi247 / netdata-1 / commits / 1509e4970

Lint alarm notify (#5164)

* manually lint alarm-notify.sh code * run automatic bash formatter (shfmt) * bring back unused variable

Paweł Krupa committed Feb 12, 2019 at 11:45 UTC 1509e497018fef3e3c4bc8e1afdbd33eada0fcdf
1 file changed +1134 -1222
health/notifications/alarm-notify.sh.in
+1134 -1222
@@ -1,4 +1,5 @@
1 #!/usr/bin/env bash
2 +#shellcheck source=/dev/null disable=SC2086,SC2154
3
4 # netdata
5 # real-time performance and health monitoring, done right!
@@ -35,40 +36,36 @@
36 # -----------------------------------------------------------------------------
37 # testing notifications
38
38 -
39 -if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
40 -then
41 - if [ "${2}" = "test" ]
42 - then
43 - recipient="${1}"
44 - else
45 - recipient="${2}"
46 - fi
47 -
48 - [ -z "${recipient}" ] && recipient="sysadmin"
49 -
50 - id=1
51 - last="CLEAR"
52 - test_res=0
53 - for x in "WARNING" "CRITICAL" "CLEAR"
54 - do
55 - echo >&2
56 - echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
57 -
58 - "${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" "evaluated expression" "expression variable values" 0 0
59 - if [ $? -ne 0 ]
60 - then
61 - echo >&2 "# FAILED"
62 - test_res=1
63 - else
64 - echo >&2 "# OK"
65 - fi
66 -
67 - last="${x}"
68 - id=$((id + 1))
69 - done
70 -
71 - exit $test_res
39 +if { [ "${1}" = "test" ] || [ "${2}" = "test" ]; } && [ "${#}" -le 2 ]; then
40 + if [ "${2}" = "test" ]; then
41 + recipient="${1}"
42 + else
43 + recipient="${2}"
44 + fi
45 +
46 + [ -z "${recipient}" ] && recipient="sysadmin"
47 +
48 + id=1
49 + last="CLEAR"
50 + test_res=0
51 + for x in "WARNING" "CRITICAL" "CLEAR"; do
52 + echo >&2
53 + echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
54 +
55 + "${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" "evaluated expression" "expression variable values" 0 0
56 + #shellcheck disable=SC2181
57 + if [ $? -ne 0 ]; then
58 + echo >&2 "# FAILED"
59 + test_res=1
60 + else
61 + echo >&2 "# OK"
62 + fi
63 +
64 + last="${x}"
65 + id=$((id + 1))
66 + done
67 +
68 + exit $test_res
69 fi
70
71 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
@@ -79,68 +76,67 @@ export LC_ALL=C
76 PROGRAM_NAME="$(basename "${0}")"
77
78 logdate() {
82 - date "+%Y-%m-%d %H:%M:%S"
79 + date "+%Y-%m-%d %H:%M:%S"
80 }
81
82 log() {
86 - local status="${1}"
87 - shift
83 + local status="${1}"
84 + shift
85
89 - echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
86 + echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
87
88 }
89
90 warning() {
94 - log WARNING "${@}"
91 + log WARNING "${@}"
92 }
93
94 error() {
98 - log ERROR "${@}"
95 + log ERROR "${@}"
96 }
97
98 info() {
102 - log INFO "${@}"
99 + log INFO "${@}"
100 }
101
102 fatal() {
106 - log FATAL "${@}"
107 - exit 1
103 + log FATAL "${@}"
104 + exit 1
105 }
106
107 debug=${NETDATA_ALARM_NOTIFY_DEBUG-0}
108 debug() {
112 - [ "${debug}" = "1" ] && log DEBUG "${@}"
109 + [ "${debug}" = "1" ] && log DEBUG "${@}"
110 }
111
112 docurl() {
116 - if [ -z "${curl}" ]
117 - then
118 - error "\${curl} is unset."
119 - return 1
120 - fi
121 -
122 - if [ "${debug}" = "1" ]
123 - then
124 - echo >&2 "--- BEGIN curl command ---"
125 - printf >&2 "%q " ${curl} "${@}"
126 - echo >&2
127 - echo >&2 "--- END curl command ---"
128 -
129 - local out=$(mktemp /tmp/netdata-health-alarm-notify-XXXXXXXX)
130 - local code=$(${curl} ${curl_options} --write-out %{http_code} --output "${out}" --silent --show-error "${@}")
131 - local ret=$?
132 - echo >&2 "--- BEGIN received response ---"
133 - cat >&2 "${out}"
134 - echo >&2
135 - echo >&2 "--- END received response ---"
136 - echo >&2 "RECEIVED HTTP RESPONSE CODE: ${code}"
137 - rm "${out}"
138 - echo "${code}"
139 - return ${ret}
140 - fi
141 -
142 - ${curl} ${curl_options} --write-out %{http_code} --output /dev/null --silent --show-error "${@}"
143 - return $?
113 + if [ -z "${curl}" ]; then
114 + error '${curl} is unset.'
115 + return 1
116 + fi
117 +
118 + if [ "${debug}" = "1" ]; then
119 + echo >&2 "--- BEGIN curl command ---"
120 + printf >&2 "%q " ${curl} "${@}"
121 + echo >&2
122 + echo >&2 "--- END curl command ---"
123 +
124 + local out code ret
125 + out=$(mktemp /tmp/netdata-health-alarm-notify-XXXXXXXX)
126 + code=$(${curl} ${curl_options} --write-out "%{http_code}" --output "${out}" --silent --show-error "${@}")
127 + ret=$?
128 + echo >&2 "--- BEGIN received response ---"
129 + cat >&2 "${out}"
130 + echo >&2
131 + echo >&2 "--- END received response ---"
132 + echo >&2 "RECEIVED HTTP RESPONSE CODE: ${code}"
133 + rm "${out}"
134 + echo "${code}"
135 + return ${ret}
136 + fi
137 +
138 + ${curl} ${curl_options} --write-out "%{http_code}" --output /dev/null --silent --show-error "${@}"
139 + return $?
140 }
141
142 # -----------------------------------------------------------------------------
@@ -166,94 +162,92 @@ custom
162 msteam
163 kavenegar
164 prowl
165 +awssns
166 "
167
168 # -----------------------------------------------------------------------------
169 # this is to be overwritten by the config file
170
171 custom_sender() {
175 - info "not sending custom notification for ${status} of '${host}.${chart}.${name}'"
172 + info "not sending custom notification for ${status} of '${host}.${chart}.${name}'"
173 }
174
178 -
175 # -----------------------------------------------------------------------------
176
177 # check for BASH v4+ (required for associative arrays)
182 -[ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && \
183 - fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
178 +if [ ${BASH_VERSINFO[0]} -lt 4 ]; then
179 + fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
180 +fi
181
182 # -----------------------------------------------------------------------------
183 # defaults to allow running this script by hand
184
188 -[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
185 +[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
186 [ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
190 -[ -z "${NETDATA_CACHE_DIR}" ] && NETDATA_CACHE_DIR="@cachedir_POST@"
191 -[ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
187 +[ -z "${NETDATA_CACHE_DIR}" ] && NETDATA_CACHE_DIR="@cachedir_POST@"
188 +[ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
189
190 # -----------------------------------------------------------------------------
191 # parse command line parameters
192
196 -if [ ${1} = "unittest" ] ; then
197 - unittest=1 # enable unit testing mode
198 - roles="${2}" # the role that should be used for unit testing
199 - cfgfile="${3}" # the location of the config file to use for unit testing
200 - status="${4}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
201 - old_status="${5}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
193 +if [ ${1} = "unittest" ]; then
194 + unittest=1 # enable unit testing mode
195 + roles="${2}" # the role that should be used for unit testing
196 + cfgfile="${3}" # the location of the config file to use for unit testing
197 + status="${4}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
198 + old_status="${5}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
199 else
203 - roles="${1}" # the roles that should be notified for this event
204 - args_host="${2}" # the host generated this event
205 - unique_id="${3}" # the unique id of this event
206 - alarm_id="${4}" # the unique id of the alarm that generated this event
207 - event_id="${5}" # the incremental id of the event, for this alarm id
208 - when="${6}" # the timestamp this event occurred
209 - name="${7}" # the name of the alarm, as given in netdata health.d entries
210 - chart="${8}" # the name of the chart (type.id)
211 - family="${9}" # the family of the chart
212 - status="${10}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
213 - old_status="${11}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
214 - value="${12}" # the current value of the alarm
215 - old_value="${13}" # the previous value of the alarm
216 - src="${14}" # the line number and file the alarm has been configured
217 - duration="${15}" # the duration in seconds of the previous alarm state
218 - non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
219 - units="${17}" # the units of the value
220 - info="${18}" # a short description of the alarm
221 - value_string="${19}" # friendly value (with units)
222 - old_value_string="${20}" # friendly old value (with units)
223 - calc_expression="${21}" # contains the expression that was evaluated to trigger the alarm
224 - calc_param_values="${22}" # the values of the parameters in the expression, at the time of the evaluation
225 - total_warnings="${23}" # Total number of alarms in WARNING state
226 - total_critical="${24}" # Total number of alarms in CRITICAL state
200 + roles="${1}" # the roles that should be notified for this event
201 + args_host="${2}" # the host generated this event
202 + unique_id="${3}" # the unique id of this event
203 + alarm_id="${4}" # the unique id of the alarm that generated this event
204 + event_id="${5}" # the incremental id of the event, for this alarm id
205 + when="${6}" # the timestamp this event occurred
206 + name="${7}" # the name of the alarm, as given in netdata health.d entries
207 + chart="${8}" # the name of the chart (type.id)
208 + family="${9}" # the family of the chart
209 + status="${10}" # the current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
210 + old_status="${11}" # the previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
211 + value="${12}" # the current value of the alarm
212 + old_value="${13}" # the previous value of the alarm
213 + src="${14}" # the line number and file the alarm has been configured
214 + duration="${15}" # the duration in seconds of the previous alarm state
215 + non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
216 + units="${17}" # the units of the value
217 + info="${18}" # a short description of the alarm
218 + value_string="${19}" # friendly value (with units)
219 + # shellcheck disable=SC2034 variable is unused, but https://github.com/netdata/netdata/pull/5164#discussion_r255572947
220 + old_value_string="${20}" # friendly old value (with units), previously named "old_value_string"
221 + calc_expression="${21}" # contains the expression that was evaluated to trigger the alarm
222 + calc_param_values="${22}" # the values of the parameters in the expression, at the time of the evaluation
223 + total_warnings="${23}" # Total number of alarms in WARNING state
224 + total_critical="${24}" # Total number of alarms in CRITICAL state
225 fi
226
229 -
227 # -----------------------------------------------------------------------------
228 # find a suitable hostname to use, if netdata did not supply a hostname
229
233 -if [ -z ${args_host} ]
234 - then
235 - this_host=$(hostname -s 2>/dev/null)
236 - host="${this_host}"
237 - args_host="${this_host}"
230 +if [ -z ${args_host} ]; then
231 + this_host=$(hostname -s 2>/dev/null)
232 + host="${this_host}"
233 + args_host="${this_host}"
234 else
239 - host="${args_host}"
235 + host="${args_host}"
236 fi
237
238 # -----------------------------------------------------------------------------
239 # screen statuses we don't need to send a notification
240
241 # don't do anything if this is not WARNING, CRITICAL or CLEAR
246 -if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
247 -then
248 - info "not sending notification for ${status} of '${host}.${chart}.${name}'"
249 - exit 1
242 +if [ "${status}" != "WARNING" ] && [ "${status}" != "CRITICAL" ] && [ "${status}" != "CLEAR" ]; then
243 + info "not sending notification for ${status} of '${host}.${chart}.${name}'"
244 + exit 1
245 fi
246
247 # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
253 -if [ "${clear_alarm_always}" != "YES" -a "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
254 -then
255 - info "not sending notification for ${status} of '${host}.${chart}.${name}' (last status was ${old_status})"
256 - exit 1
248 +if [ "${clear_alarm_always}" != "YES" ] && [ "${old_status}" != "WARNING" ] && [ "${old_status}" != "CRITICAL" ] && [ "${status}" = "CLEAR" ]; then
249 + info "not sending notification for ${status} of '${host}.${chart}.${name}' (last status was ${old_status})"
250 + exit 1
251 fi
252
253 # -----------------------------------------------------------------------------
@@ -277,13 +271,13 @@ curl=
271 sendmail=
272
273 # enable / disable features
280 -for method_name in ${method_names^^} ; do
281 - declare SEND_${method_name}="YES"
282 - declare DEFAULT_RECIPIENT_${method_name}
274 +for method_name in ${method_names^^}; do
275 + declare SEND_${method_name}="YES"
276 + declare DEFAULT_RECIPIENT_${method_name}
277 done
278
285 -for method_name in ${method_names} ; do
286 - declare -A role_recipients_${method_name}
279 +for method_name in ${method_names}; do
280 + declare -A role_recipients_${method_name}
281 done
282
283 # slack configs
@@ -344,9 +338,7 @@ PD_SERVICE_KEY=
338 FLEEP_SENDER="${host}"
339
340 # Amazon SNS configs
347 -DEFAULT_RECIPIENT_AWSSNS=
341 AWSSNS_MESSAGE_FORMAT=
349 -declare -A role_recipients_awssns=()
342
343 # syslog configs
344 SYSLOG_FACILITY=
@@ -355,7 +347,6 @@ SYSLOG_FACILITY=
347 EMAIL_SENDER=
348 EMAIL_CHARSET=$(locale charmap 2>/dev/null)
349 EMAIL_THREADING=
358 -DEFAULT_RECIPIENT_EMAIL="root"
350
351 # irc configs
352 IRC_NICKNAME=
@@ -365,95 +356,88 @@ IRC_NETWORK=
356 # load the stock and user configuration files
357 # these will overwrite the variables above
358
368 -if [ ${unittest} ] ;
369 - then
370 - source "${cfgfile}"
371 - [ $? -ne 0 ] && error "Failed to load requested config file." && exit 1
359 +if [ ${unittest} ]; then
360 + if source "${cfgfile}"; then
361 + error "Failed to load requested config file."
362 + exit 1
363 + fi
364 else
373 - for CONFIG in "${NETDATA_STOCK_CONFIG_DIR}/health_alarm_notify.conf" "${NETDATA_USER_CONFIG_DIR}/health_alarm_notify.conf"
374 - do
375 - if [ -f "${CONFIG}" ]
376 - then
377 - debug "Loading config file '${CONFIG}'..."
378 - source "${CONFIG}"
379 - [ $? -ne 0 ] && error "Failed to load config file '${CONFIG}'."
380 - else
381 - warning "Cannot find file '${CONFIG}'."
382 - fi
383 - done
365 + for CONFIG in "${NETDATA_STOCK_CONFIG_DIR}/health_alarm_notify.conf" "${NETDATA_USER_CONFIG_DIR}/health_alarm_notify.conf"; do
366 + if [ -f "${CONFIG}" ]; then
367 + debug "Loading config file '${CONFIG}'..."
368 + source "${CONFIG}" || error "Failed to load config file '${CONFIG}'."
369 + else
370 + warning "Cannot find file '${CONFIG}'."
371 + fi
372 + done
373 fi
374
375 # If we didn't autodetect the character set for e-mail and it wasn't
376 # set by the user, we need to set it to a reasonable default. UTF-8
377 # should be correct for almost all modern UNIX systems.
389 -if [ -z ${EMAIL_CHARSET} ]
390 - then
391 - EMAIL_CHARSET="UTF-8"
378 +if [ -z ${EMAIL_CHARSET} ]; then
379 + EMAIL_CHARSET="UTF-8"
380 fi
381
382 # If we've been asked to use FQDN's for the URL's in the alarm, do so,
383 # unless we're sending an alarm for a slave system which we can't get the
384 # FQDN of easily.
397 -if [ "${use_fqdn}" = "YES" -a "${host}" = "$(hostname -s 2>/dev/null)" ]
398 - then
399 - host="$(hostname -f 2>/dev/null)"
385 +if [ "${use_fqdn}" = "YES" ] && [ "${host}" = "$(hostname -s 2>/dev/null)" ]; then
386 + host="$(hostname -f 2>/dev/null)"
387 fi
388
389 # -----------------------------------------------------------------------------
390 # filter a recipient based on alarm event severity
391
392 filter_recipient_by_criticality() {
406 - local method="${1}" x="${2}" r s
407 - shift
408 -
409 - r="${x/|*/}" # the recipient
410 - s="${x/*|/}" # the severity required for notifying this recipient
411 -
412 - # no severity filtering for this person
413 - [ "${r}" = "${s}" ] && return 0
414 -
415 - # the severity is invalid
416 - s="${s^^}"
417 - if [ "${s}" != "CRITICAL" ]
418 - then
419 - error "SEVERITY FILTERING for ${x} VIA ${method}: invalid severity '${s,,}', only 'critical' is supported."
420 - return 0
421 - fi
422 -
423 - # create the status tracking directory for this user
424 - [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] && \
425 - mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
426 -
427 - case "${status}" in
428 - CRITICAL)
429 - # make sure he will get future notifications for this alarm too
430 - touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
431 - debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: the alarm is CRITICAL (will now receive next status change)"
432 - return 0
433 - ;;
434 -
435 - WARNING)
436 - if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]
437 - then
438 - # we do not remove the file, so that he will get future notifications of this alarm
439 - debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm in the past (will still receive next status change)"
440 - return 0
441 - fi
442 - ;;
443 -
444 - *)
445 - if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]
446 - then
447 - # remove the file, so that he will only receive notifications for CRITICAL states for this alarm
448 - rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
449 - debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm (will only receive CRITICAL notifications from now on)"
450 - return 0
451 - fi
452 - ;;
453 - esac
454 -
455 - debug "SEVERITY FILTERING for ${x} VIA ${method}: BLOCK: recipient should not receive this notification"
456 - return 1
393 + local method="${1}" x="${2}" r s
394 + shift
395 +
396 + r="${x/|*/}" # the recipient
397 + s="${x/*|/}" # the severity required for notifying this recipient
398 +
399 + # no severity filtering for this person
400 + [ "${r}" = "${s}" ] && return 0
401 +
402 + # the severity is invalid
403 + s="${s^^}"
404 + if [ "${s}" != "CRITICAL" ]; then
405 + error "SEVERITY FILTERING for ${x} VIA ${method}: invalid severity '${s,,}', only 'critical' is supported."
406 + return 0
407 + fi
408 +
409 + # create the status tracking directory for this user
410 + [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] &&
411 + mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
412 +
413 + case "${status}" in
414 + CRITICAL)
415 + # make sure he will get future notifications for this alarm too
416 + touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
417 + debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: the alarm is CRITICAL (will now receive next status change)"
418 + return 0
419 + ;;
420 +
421 + WARNING)
422 + if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]; then
423 + # we do not remove the file, so that he will get future notifications of this alarm
424 + debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm in the past (will still receive next status change)"
425 + return 0
426 + fi
427 + ;;
428 +
429 + *)
430 + if [ -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]; then
431 + # remove the file, so that he will only receive notifications for CRITICAL states for this alarm
432 + rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
433 + debug "SEVERITY FILTERING for ${x} VIA ${method}: ALLOW: recipient has been notified for this alarm (will only receive CRITICAL notifications from now on)"
434 + return 0
435 + fi
436 + ;;
437 + esac
438 +
439 + debug "SEVERITY FILTERING for ${x} VIA ${method}: BLOCK: recipient should not receive this notification"
440 + return 1
441 }
442
443 # -----------------------------------------------------------------------------
@@ -481,107 +465,100 @@ filter_recipient_by_criticality() {
465 [ -z "${PUSHBULLET_ACCESS_TOKEN}" ] && SEND_PUSHBULLET="NO"
466
467 # check twilio
484 -[ -z "${TWILIO_ACCOUNT_TOKEN}" -o -z "${TWILIO_ACCOUNT_SID}" -o -z "${TWILIO_NUMBER}" ] && SEND_TWILIO="NO"
468 +{ [ -z "${TWILIO_ACCOUNT_TOKEN}" ] || [ -z "${TWILIO_ACCOUNT_SID}" ] || [ -z "${TWILIO_NUMBER}" ]; } && SEND_TWILIO="NO"
469
470 # check hipchat
471 [ -z "${HIPCHAT_AUTH_TOKEN}" ] && SEND_HIPCHAT="NO"
472
473 # check messagebird
490 -[ -z "${MESSAGEBIRD_ACCESS_KEY}" -o -z "${MESSAGEBIRD_NUMBER}" ] && SEND_MESSAGEBIRD="NO"
474 +{ [ -z "${MESSAGEBIRD_ACCESS_KEY}" ] || [ -z "${MESSAGEBIRD_NUMBER}" ]; } && SEND_MESSAGEBIRD="NO"
475
476 # check kavenegar
493 -[ -z "${KAVENEGAR_API_KEY}" -o -z "${KAVENEGAR_SENDER}" ] && SEND_KAVENEGAR="NO"
477 +{ [ -z "${KAVENEGAR_API_KEY}" ] || [ -z "${KAVENEGAR_SENDER}" ]; } && SEND_KAVENEGAR="NO"
478
479 # check telegram
480 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
481
482 # check kafka
499 -[ -z "${KAFKA_URL}" -o -z "${KAFKA_SENDER_IP}" ] && SEND_KAFKA="NO"
483 +{ [ -z "${KAFKA_URL}" ] || [ -z "${KAFKA_SENDER_IP}" ]; } && SEND_KAFKA="NO"
484
485 # check irc
486 [ -z "${IRC_NETWORK}" ] && SEND_IRC="NO"
487
488 # check fleep
505 -[ -z "${FLEEP_SERVER}" -o -z "${FLEEP_SENDER}" ] && SEND_FLEEP="NO"
506 -
507 -# if we need curl, check for the curl command
508 -if [ \( \
509 - "${SEND_PUSHOVER}" = "YES" \
510 - -o "${SEND_SLACK}" = "YES" \
511 - -o "${SEND_ROCKETCHAT}" = "YES" \
512 - -o "${SEND_ALERTA}" = "YES" \
513 - -o "${SEND_PD}" = "YES" \
514 - -o "${SEND_FLOCK}" = "YES" \
515 - -o "${SEND_DISCORD}" = "YES" \
516 - -o "${SEND_HIPCHAT}" = "YES" \
517 - -o "${SEND_TWILIO}" = "YES" \
518 - -o "${SEND_MESSAGEBIRD}" = "YES" \
519 - -o "${SEND_KAVENEGAR}" = "YES" \
520 - -o "${SEND_TELEGRAM}" = "YES" \
521 - -o "${SEND_PUSHBULLET}" = "YES" \
522 - -o "${SEND_KAFKA}" = "YES" \
523 - -o "${SEND_FLEEP}" = "YES" \
524 - -o "${SEND_PROWL}" = "YES" \
525 - -o "${SEND_CUSTOM}" = "YES" \
526 - -o "${SEND_MSTEAM}" = "YES" \
527 - \) -a -z "${curl}" ]
528 - then
529 - curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
530 - if [ -z "${curl}" ]
531 - then
532 - error "Cannot find curl command in the system path. Disabling all curl based notifications."
533 - SEND_PUSHOVER="NO"
534 - SEND_PUSHBULLET="NO"
535 - SEND_TELEGRAM="NO"
536 - SEND_SLACK="NO"
537 - SEND_MSTEAM="NO"
538 - SEND_ROCKETCHAT="NO"
539 - SEND_ALERTA="NO"
540 - SEND_PD="NO"
541 - SEND_FLOCK="NO"
542 - SEND_DISCORD="NO"
543 - SEND_TWILIO="NO"
544 - SEND_HIPCHAT="NO"
545 - SEND_MESSAGEBIRD="NO"
546 - SEND_KAVENEGAR="NO"
547 - SEND_KAFKA="NO"
548 - SEND_FLEEP="NO"
549 - SEND_PROWL="NO"
550 - SEND_CUSTOM="NO"
551 - fi
489 +#shellcheck disable=SC2153
490 +{ [ -z "${FLEEP_SERVER}" ] || [ -z "${FLEEP_SENDER}" ]; } && SEND_FLEEP="NO"
491 +
492 +if [ "${SEND_PUSHOVER}" = "YES" ] ||
493 + [ "${SEND_SLACK}" = "YES" ] ||
494 + [ "${SEND_ROCKETCHAT}" = "YES" ] ||
495 + [ "${SEND_ALERTA}" = "YES" ] ||
496 + [ "${SEND_PD}" = "YES" ] ||
497 + [ "${SEND_FLOCK}" = "YES" ] ||
498 + [ "${SEND_DISCORD}" = "YES" ] ||
499 + [ "${SEND_HIPCHAT}" = "YES" ] ||
500 + [ "${SEND_TWILIO}" = "YES" ] ||
501 + [ "${SEND_MESSAGEBIRD}" = "YES" ] ||
502 + [ "${SEND_KAVENEGAR}" = "YES" ] ||
503 + [ "${SEND_TELEGRAM}" = "YES" ] ||
504 + [ "${SEND_PUSHBULLET}" = "YES" ] ||
505 + [ "${SEND_KAFKA}" = "YES" ] ||
506 + [ "${SEND_FLEEP}" = "YES" ] ||
507 + [ "${SEND_PROWL}" = "YES" ] ||
508 + [ "${SEND_CUSTOM}" = "YES" ] ||
509 + [ "${SEND_MSTEAM}" = "YES" ]; then
510 + # if we need curl, check for the curl command
511 + if [ -z "${curl}" ]; then
512 + curl="$(command -v curl 2>/dev/null)"
513 + fi
514 + if [ -z "${curl}" ]; then
515 + error "Cannot find curl command in the system path. Disabling all curl based notifications."
516 + SEND_PUSHOVER="NO"
517 + SEND_PUSHBULLET="NO"
518 + SEND_TELEGRAM="NO"
519 + SEND_SLACK="NO"
520 + SEND_MSTEAM="NO"
521 + SEND_ROCKETCHAT="NO"
522 + SEND_ALERTA="NO"
523 + SEND_PD="NO"
524 + SEND_FLOCK="NO"
525 + SEND_DISCORD="NO"
526 + SEND_TWILIO="NO"
527 + SEND_HIPCHAT="NO"
528 + SEND_MESSAGEBIRD="NO"
529 + SEND_KAVENEGAR="NO"
530 + SEND_KAFKA="NO"
531 + SEND_FLEEP="NO"
532 + SEND_PROWL="NO"
533 + SEND_CUSTOM="NO"
534 + fi
535 fi
536
537 # if we need sendmail, check for the sendmail command
555 -if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
556 - then
557 - sendmail="$(which sendmail 2>/dev/null || command -v sendmail 2>/dev/null)"
558 - if [ -z "${sendmail}" ]
559 - then
560 - debug "Cannot find sendmail command in the system path. Disabling email notifications."
561 - SEND_EMAIL="NO"
562 - fi
538 +if [ "${SEND_EMAIL}" = "YES" ] && [ -z "${sendmail}" ]; then
539 + sendmail="$(command -v sendmail 2>/dev/null)"
540 + if [ -z "${sendmail}" ]; then
541 + debug "Cannot find sendmail command in the system path. Disabling email notifications."
542 + SEND_EMAIL="NO"
543 + fi
544 fi
545
546 # if we need logger, check for the logger command
566 -if [ "${SEND_SYSLOG}" = "YES" -a -z "${logger}" ]
567 - then
568 - logger="$(which logger 2>/dev/null || command -v logger 2>/dev/null)"
569 - if [ -z "${logger}" ]
570 - then
571 - debug "Cannot find logger command in the system path. Disabling syslog notifications."
572 - SEND_SYSLOG="NO"
573 - fi
547 +if [ "${SEND_SYSLOG}" = "YES" ] && [ -z "${logger}" ]; then
548 + logger="$(command -v logger 2>/dev/null)"
549 + if [ -z "${logger}" ]; then
550 + debug "Cannot find logger command in the system path. Disabling syslog notifications."
551 + SEND_SYSLOG="NO"
552 + fi
553 fi
554
555 # if we need aws, check for the aws command
577 -if [ "${SEND_AWSSNS}" = "YES" -a -z "${aws}" ]
578 - then
579 - aws="$(which aws 2>/dev/null || command -v aws 2>/dev/null)"
580 - if [ -z "${aws}" ]
581 - then
582 - debug "Cannot find aws command in the system path. Disabling Amazon SNS notifications."
583 - SEND_AWSSNS="NO"
584 - fi
556 +if [ "${SEND_AWSSNS}" = "YES" ] && [ -z "${aws}" ]; then
557 + aws="$(command -v aws 2>/dev/null)"
558 + if [ -z "${aws}" ]; then
559 + debug "Cannot find aws command in the system path. Disabling Amazon SNS notifications."
560 + SEND_AWSSNS="NO"
561 + fi
562 fi
563
564 # -----------------------------------------------------------------------------
@@ -589,47 +566,48 @@ fi
566
567 # netdata may call us with multiple roles, and roles may have multiple but
568 # overlapping recipients - so, here we find the unique recipients.
592 -for method_name in ${method_names} ; do
593 - send_var="SEND_${method_name^^}"
594 - if [ ${!send_var} = "NO" ] ; then
595 - continue
596 - fi
597 -
598 - declare -A arr_var=()
599 -
600 - for x in ${roles//,/ } ; do
601 - # the roles 'silent' and 'disabled' mean:
602 - # don't send a notification for this role
603 - [ "${x}" = "silent" -o "${x}" = "disabled" ] && continue
604 -
605 - role_recipients="role_recipients_${method_name}[$x]"
606 - default_recipient_var="DEFAULT_RECIPIENT_${method_name^^}"
607 -
608 - a="${!role_recipients}"
609 - [ -z "${a}" ] && a="${!default_recipient_var}"
610 - for r in ${a//,/ } ; do
611 - [ "${r}" != "disabled" ] && filter_recipient_by_criticality ${method_name} "${r}" && arr_var[${r/|*/}]="1"
612 - done
613 - done
614 -
615 - # build the list of recipients
616 - to_var="to_${method_name}"
617 - declare to_${method_name}="${!arr_var[*]}"
618 -
619 - [ -z "${!to_var}" ] && declare ${send_var}="NO"
569 +for method_name in ${method_names}; do
570 + send_var="SEND_${method_name^^}"
571 + if [ "${!send_var}" = "NO" ]; then
572 + continue
573 + fi
574 +
575 + declare -A arr_var=()
576 +
577 + for x in ${roles//,/ }; do
578 + # the roles 'silent' and 'disabled' mean:
579 + # don't send a notification for this role
580 + if [ "${x}" = "silent" ] || [ "${x}" = "disabled" ]; then
581 + continue
582 + fi
583 +
584 + role_recipients="role_recipients_${method_name}[$x]"
585 + default_recipient_var="DEFAULT_RECIPIENT_${method_name^^}"
586 +
587 + a="${!role_recipients}"
588 + [ -z "${a}" ] && a="${!default_recipient_var}"
589 + for r in ${a//,/ }; do
590 + [ "${r}" != "disabled" ] && filter_recipient_by_criticality ${method_name} "${r}" && arr_var[${r/|*/}]="1"
591 + done
592 + done
593 +
594 + # build the list of recipients
595 + to_var="to_${method_name}"
596 + declare to_${method_name}="${!arr_var[*]}"
597 +
598 + [ -z "${!to_var}" ] && declare ${send_var}="NO"
599 done
600
601 # -----------------------------------------------------------------------------
602 # handle fixup of the email recipient list.
603
604 fix_to_email() {
626 - to_email=
627 - while [ ! -z "${1}" ]
628 - do
629 - [ ! -z "${to_email}" ] && to_email="${to_email}, "
630 - to_email="${to_email}${1}"
631 - shift 1
632 - done
605 + to_email=
606 + while [ -n "${1}" ]; do
607 + [ -n "${to_email}" ] && to_email="${to_email}, "
608 + to_email="${to_email}${1}"
609 + shift 1
610 + done
611 }
612
613 # ${to_email} without quotes here
@@ -637,41 +615,45 @@ fix_to_email ${to_email}
615
616 # -----------------------------------------------------------------------------
617 # handle output if we're running in unit test mode
640 -if [ ${unittest} ] ; then
641 - for method_name in ${method_names} ; do
642 - to_var="to_${method_name}"
643 - echo "results: ${method_name}: ${!to_var}"
644 - done
645 - exit 0
618 +if [ ${unittest} ]; then
619 + for method_name in ${method_names}; do
620 + to_var="to_${method_name}"
621 + echo "results: ${method_name}: ${!to_var}"
622 + done
623 + exit 0
624 fi
625
626 # -----------------------------------------------------------------------------
627 # check that we have at least a method enabled
650 -if [ "${SEND_EMAIL}" != "YES" \
651 - -a "${SEND_PUSHOVER}" != "YES" \
652 - -a "${SEND_TELEGRAM}" != "YES" \
653 - -a "${SEND_SLACK}" != "YES" \
654 - -a "${SEND_ROCKETCHAT}" != "YES" \
655 - -a "${SEND_ALERTA}" != "YES" \
656 - -a "${SEND_FLOCK}" != "YES" \
657 - -a "${SEND_DISCORD}" != "YES" \
658 - -a "${SEND_TWILIO}" != "YES" \
659 - -a "${SEND_HIPCHAT}" != "YES" \
660 - -a "${SEND_MESSAGEBIRD}" != "YES" \
661 - -a "${SEND_KAVENEGAR}" != "YES" \
662 - -a "${SEND_PUSHBULLET}" != "YES" \
663 - -a "${SEND_KAFKA}" != "YES" \
664 - -a "${SEND_PD}" != "YES" \
665 - -a "${SEND_FLEEP}" != "YES" \
666 - -a "${SEND_CUSTOM}" != "YES" \
667 - -a "${SEND_IRC}" != "YES" \
668 - -a "${SEND_AWSSNS}" != "YES" \
669 - -a "${SEND_PROWL}" != "YES" \
670 - -a "${SEND_SYSLOG}" != "YES" \
671 - -a "${SEND_MSTEAM}" != "YES" \
672 - ]
673 - then
674 - fatal "All notification methods are disabled. Not sending notification for host '${host}', chart '${chart}' to '${roles}' for '${name}' = '${value}' for status '${status}'."
628 +proceed=0
629 +for method in "${SEND_EMAIL}" \
630 + "${SEND_PUSHOVER}" \
631 + "${SEND_TELEGRAM}" \
632 + "${SEND_SLACK}" \
633 + "${SEND_ROCKETCHAT}" \
634 + "${SEND_ALERTA}" \
635 + "${SEND_FLOCK}" \
636 + "${SEND_DISCORD}" \
637 + "${SEND_TWILIO}" \
638 + "${SEND_HIPCHAT}" \
639 + "${SEND_MESSAGEBIRD}" \
640 + "${SEND_KAVENEGAR}" \
641 + "${SEND_PUSHBULLET}" \
642 + "${SEND_KAFKA}" \
643 + "${SEND_PD}" \
644 + "${SEND_FLEEP}" \
645 + "${SEND_CUSTOM}" \
646 + "${SEND_IRC}" \
647 + "${SEND_AWSSNS}" \
648 + "${SEND_SYSLOG}" \
649 + "${SEND_MSTEAM}"; do
650 + if [ "${method}" == "YES" ]; then
651 + proceed=1
652 + break
653 + fi
654 +done
655 +if [ "$proceed" -eq 0 ]; then
656 + fatal "All notification methods are disabled. Not sending notification for host '${host}', chart '${chart}' to '${roles}' for '${name}' = '${value}' for status '${status}'."
657 fi
658
659 # -----------------------------------------------------------------------------
@@ -684,36 +666,35 @@ date=$(date --date=@${when} "${date_format}" 2>/dev/null)
666
667 # ----------------------------------------------------------------------------
668 # prepare some extra headers if we've been asked to thread e-mails
687 -if [ "${SEND_EMAIL}" == "YES" -a "${EMAIL_THREADING}" != "NO" ] ; then
688 - email_thread_headers="In-Reply-To: <${chart}-${name}@${host}>\nReferences: <${chart}-${name}@${host}>"
669 +if [ "${SEND_EMAIL}" == "YES" ] && [ "${EMAIL_THREADING}" != "NO" ]; then
670 + email_thread_headers="In-Reply-To: <${chart}-${name}@${host}>\\nReferences: <${chart}-${name}@${host}>"
671 else
690 - email_thread_headers=
672 + email_thread_headers=
673 fi
674
675 # -----------------------------------------------------------------------------
676 # function to URL encode a string
677
678 urlencode() {
697 - local string="${1}" strlen encoded pos c o
698 -
699 - strlen=${#string}
700 - for (( pos=0 ; pos<strlen ; pos++ ))
701 - do
702 - c=${string:${pos}:1}
703 - case "${c}" in
704 - [-_.~a-zA-Z0-9])
705 - o="${c}"
706 - ;;
707 -
708 - *)
709 - printf -v o '%%%02x' "'${c}"
710 - ;;
711 - esac
712 - encoded+="${o}"
713 - done
714 -
715 - REPLY="${encoded}"
716 - echo "${REPLY}"
679 + local string="${1}" strlen encoded pos c o
680 +
681 + strlen=${#string}
682 + for ((pos = 0; pos < strlen; pos++)); do
683 + c=${string:pos:1}
684 + case "${c}" in
685 + [-_.~a-zA-Z0-9])
686 + o="${c}"
687 + ;;
688 +
689 + *)
690 + printf -v o '%%%02x' "'${c}"
691 + ;;
692 + esac
693 + encoded+="${o}"
694 + done
695 +
696 + REPLY="${encoded}"
697 + echo "${REPLY}"
698 }
699
700 # -----------------------------------------------------------------------------
@@ -721,238 +702,217 @@ urlencode() {
702 # using DAYS, MINUTES, SECONDS
703
704 duration4human() {
724 - local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
725 - d=$(( s / 86400 ))
726 - s=$(( s - (d * 86400) ))
727 - h=$(( s / 3600 ))
728 - s=$(( s - (h * 3600) ))
729 - m=$(( s / 60 ))
730 - s=$(( s - (m * 60) ))
731 -
732 - if [ ${d} -gt 0 ]
733 - then
734 - [ ${m} -ge 30 ] && h=$(( h + 1 ))
735 - [ ${d} -gt 1 ] && ds="days"
736 - [ ${h} -gt 1 ] && hs="hours"
737 - if [ ${h} -gt 0 ]
738 - then
739 - ret="${d} ${ds} and ${h} ${hs}"
740 - else
741 - ret="${d} ${ds}"
742 - fi
743 - elif [ ${h} -gt 0 ]
744 - then
745 - [ ${s} -ge 30 ] && m=$(( m + 1 ))
746 - [ ${h} -gt 1 ] && hs="hours"
747 - [ ${m} -gt 1 ] && ms="minutes"
748 - if [ ${m} -gt 0 ]
749 - then
750 - ret="${h} ${hs} and ${m} ${ms}"
751 - else
752 - ret="${h} ${hs}"
753 - fi
754 - elif [ ${m} -gt 0 ]
755 - then
756 - [ ${m} -gt 1 ] && ms="minutes"
757 - [ ${s} -gt 1 ] && ss="seconds"
758 - if [ ${s} -gt 0 ]
759 - then
760 - ret="${m} ${ms} and ${s} ${ss}"
761 - else
762 - ret="${m} ${ms}"
763 - fi
764 - else
765 - [ ${s} -gt 1 ] && ss="seconds"
766 - ret="${s} ${ss}"
767 - fi
768 -
769 - REPLY="${ret}"
770 - echo "${REPLY}"
705 + local s="${1}" d=0 h=0 m=0 ds="day" hs="hour" ms="minute" ss="second" ret
706 + d=$((s / 86400))
707 + s=$((s - (d * 86400)))
708 + h=$((s / 3600))
709 + s=$((s - (h * 3600)))
710 + m=$((s / 60))
711 + s=$((s - (m * 60)))
712 +
713 + if [ ${d} -gt 0 ]; then
714 + [ ${m} -ge 30 ] && h=$((h + 1))
715 + [ ${d} -gt 1 ] && ds="days"
716 + [ ${h} -gt 1 ] && hs="hours"
717 + if [ ${h} -gt 0 ]; then
718 + ret="${d} ${ds} and ${h} ${hs}"
719 + else
720 + ret="${d} ${ds}"
721 + fi
722 + elif [ ${h} -gt 0 ]; then
723 + [ ${s} -ge 30 ] && m=$((m + 1))
724 + [ ${h} -gt 1 ] && hs="hours"
725 + [ ${m} -gt 1 ] && ms="minutes"
726 + if [ ${m} -gt 0 ]; then
727 + ret="${h} ${hs} and ${m} ${ms}"
728 + else
729 + ret="${h} ${hs}"
730 + fi
731 + elif [ ${m} -gt 0 ]; then
732 + [ ${m} -gt 1 ] && ms="minutes"
733 + [ ${s} -gt 1 ] && ss="seconds"
734 + if [ ${s} -gt 0 ]; then
735 + ret="${m} ${ms} and ${s} ${ss}"
736 + else
737 + ret="${m} ${ms}"
738 + fi
739 + else
740 + [ ${s} -gt 1 ] && ss="seconds"
741 + ret="${s} ${ss}"
742 + fi
743 +
744 + REPLY="${ret}"
745 + echo "${REPLY}"
746 }
747
748 # -----------------------------------------------------------------------------
749 # email sender
750
751 send_email() {
777 - local ret= opts=() sender_email="${EMAIL_SENDER}" sender_name=
778 - if [ "${SEND_EMAIL}" = "YES" ]
779 - then
780 -
781 - if [ ! -z "${EMAIL_SENDER}" ]
782 - then
783 - if [[ "${EMAIL_SENDER}" =~ ^\".*\"\ \<.*\>$ ]]
784 - then
785 - # the name includes double quotes
786 - sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
787 - sender_name="$(echo "${EMAIL_SENDER}" | cut -d '"' -f 2)"
788 - elif [[ "${EMAIL_SENDER}" =~ ^\'.*\'\ \<.*\>$ ]]
789 - then
790 - # the name includes single quotes
791 - sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
792 - sender_name="$(echo "${EMAIL_SENDER}" | cut -d "'" -f 2)"
793 - elif [[ "${EMAIL_SENDER}" =~ ^.*\ \<.*\>$ ]]
794 - then
795 - # the name does not have any quotes
796 - sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
797 - sender_name="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
798 - fi
799 - fi
800 -
801 - [ ! -z "${sender_email}" ] && opts+=(-f "${sender_email}")
802 - [ ! -z "${sender_name}" ] && opts+=(-F "${sender_name}")
803 -
804 - if [ "${debug}" = "1" ]
805 - then
806 - echo >&2 "--- BEGIN sendmail command ---"
807 - printf >&2 "%q " "${sendmail}" -t "${opts[@]}"
808 - echo >&2
809 - echo >&2 "--- END sendmail command ---"
810 - fi
811 -
812 - "${sendmail}" -t "${opts[@]}"
813 - ret=$?
814 -
815 - if [ ${ret} -eq 0 ]
816 - then
817 - info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
818 - return 0
819 - else
820 - error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
821 - return 1
822 - fi
823 - fi
824 -
825 - return 1
752 + local ret opts=() sender_email="${EMAIL_SENDER}" sender_name=
753 + if [ "${SEND_EMAIL}" = "YES" ]; then
754 +
755 + if [ -n "${EMAIL_SENDER}" ]; then
756 + if [[ ${EMAIL_SENDER} =~ ^\".*\"\ \<.*\>$ ]]; then
757 + # the name includes double quotes
758 + sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
759 + sender_name="$(echo "${EMAIL_SENDER}" | cut -d '"' -f 2)"
760 + elif [[ ${EMAIL_SENDER} =~ ^\'.*\'\ \<.*\>$ ]]; then
761 + # the name includes single quotes
762 + sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
763 + sender_name="$(echo "${EMAIL_SENDER}" | cut -d "'" -f 2)"
764 + elif [[ ${EMAIL_SENDER} =~ ^.*\ \<.*\>$ ]]; then
765 + # the name does not have any quotes
766 + sender_email="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 2 | cut -d '>' -f 1)"
767 + sender_name="$(echo "${EMAIL_SENDER}" | cut -d '<' -f 1)"
768 + fi
769 + fi
770 +
771 + [ -n "${sender_email}" ] && opts+=(-f "${sender_email}")
772 + [ -n "${sender_name}" ] && opts+=(-F "${sender_name}")
773 +
774 + if [ "${debug}" = "1" ]; then
775 + echo >&2 "--- BEGIN sendmail command ---"
776 + printf >&2 "%q " "${sendmail}" -t "${opts[@]}"
777 + echo >&2
778 + echo >&2 "--- END sendmail command ---"
779 + fi
780 +
781 + "${sendmail}" -t "${opts[@]}"
782 + ret=$?
783 +
784 + if [ ${ret} -eq 0 ]; then
785 + info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
786 + return 0
787 + else
788 + error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
789 + return 1
790 + fi
791 + fi
792 +
793 + return 1
794 }
795
796 # -----------------------------------------------------------------------------
797 # pushover sender
798
799 send_pushover() {
832 - local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority
833 -
834 - if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertokens}" -a ! -z "${title}" -a ! -z "${message}" ]
835 - then
836 -
837 - # https://pushover.net/api
838 - priority=-2
839 - case "${status}" in
840 - CLEAR) priority=-1;; # low priority: no sound or vibration
841 - WARNING) priority=0;; # normal priority: respect quiet hours
842 - CRITICAL) priority=1;; # high priority: bypass quiet hours
843 - *) priority=-2;; # lowest priority: no notification at all
844 - esac
845 -
846 - for user in ${usertokens}
847 - do
848 - httpcode=$(docurl \
849 - --form-string "token=${apptoken}" \
850 - --form-string "user=${user}" \
851 - --form-string "html=1" \
852 - --form-string "title=${title}" \
853 - --form-string "message=${message}" \
854 - --form-string "timestamp=${when}" \
855 - --form-string "url=${url}" \
856 - --form-string "url_title=Open netdata dashboard to view the alarm" \
857 - --form-string "priority=${priority}" \
858 - https://api.pushover.net/1/messages.json)
859 -
860 - if [ "${httpcode}" = "200" ]
861 - then
862 - info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
863 - sent=$((sent + 1))
864 - else
865 - error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
866 - fi
867 - done
868 -
869 - [ ${sent} -gt 0 ] && return 0
870 - fi
871 -
872 - return 1
800 + local apptoken="${1}" usertokens="${2}" when="${3}" url="${4}" status="${5}" title="${6}" message="${7}" httpcode sent=0 user priority
801 +
802 + if [ "${SEND_PUSHOVER}" = "YES" ] && [ -n "${apptoken}" ] && [ -n "${usertokens}" ] && [ -n "${title}" ] && [ -n "${message}" ]; then
803 +
804 + # https://pushover.net/api
805 + priority=-2
806 + case "${status}" in
807 + CLEAR) priority=-1 ;; # low priority: no sound or vibration
808 + WARNING) priority=0 ;; # normal priority: respect quiet hours
809 + CRITICAL) priority=1 ;; # high priority: bypass quiet hours
810 + *) priority=-2 ;; # lowest priority: no notification at all
811 + esac
812 +
813 + for user in ${usertokens}; do
814 + httpcode=$(docurl \
815 + --form-string "token=${apptoken}" \
816 + --form-string "user=${user}" \
817 + --form-string "html=1" \
818 + --form-string "title=${title}" \
819 + --form-string "message=${message}" \
820 + --form-string "timestamp=${when}" \
821 + --form-string "url=${url}" \
822 + --form-string "url_title=Open netdata dashboard to view the alarm" \
823 + --form-string "priority=${priority}" \
824 + https://api.pushover.net/1/messages.json)
825 +
826 + if [ "${httpcode}" = "200" ]; then
827 + info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
828 + sent=$((sent + 1))
829 + else
830 + error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
831 + fi
832 + done
833 +
834 + [ ${sent} -gt 0 ] && return 0
835 + fi
836 +
837 + return 1
838 }
839
840 # -----------------------------------------------------------------------------
841 # pushbullet sender
842
843 send_pushbullet() {
879 - local userapikey="${1}" source_device="${2}" recipients="${3}" url="${4}" title="${5}" message="${6}" httpcode sent=0 user
880 - if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikey}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
881 - then
882 - #https://docs.pushbullet.com/#create-push
883 - for user in ${recipients}
884 - do
885 - httpcode=$(docurl \
886 - --header 'Access-Token: '${userapikey}'' \
887 - --header 'Content-Type: application/json' \
888 - --data-binary @<(cat <<EOF
844 + local userapikey="${1}" source_device="${2}" recipients="${3}" url="${4}" title="${5}" message="${6}" httpcode sent=0 user
845 + if [ "${SEND_PUSHBULLET}" = "YES" ] && [ -n "${userapikey}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
846 + #https://docs.pushbullet.com/#create-push
847 + for user in ${recipients}; do
848 + httpcode=$(docurl \
849 + --header 'Access-Token: '${userapikey}'' \
850 + --header 'Content-Type: application/json' \
851 + --data-binary @<(
852 + cat <<EOF
853 {"title": "${title}",
854 "type": "link",
855 "email": "${user}",
892 - "body": "$( echo -n ${message})",
856 + "body": "$(echo -n ${message})",
857 "url": "${url}",
858 "source_device_iden": "${source_device}"}
859 EOF
896 - ) "https://api.pushbullet.com/v2/pushes" -X POST)
860 + ) "https://api.pushbullet.com/v2/pushes" -X POST)
861
898 - if [ "${httpcode}" = "200" ]
899 - then
900 - info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
901 - sent=$((sent + 1))
902 - else
903 - error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
904 - fi
905 - done
862 + if [ "${httpcode}" = "200" ]; then
863 + info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
864 + sent=$((sent + 1))
865 + else
866 + error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
867 + fi
868 + done
869
907 - [ ${sent} -gt 0 ] && return 0
908 - fi
870 + [ ${sent} -gt 0 ] && return 0
871 + fi
872
910 - return 1
873 + return 1
874 }
875
876 # -----------------------------------------------------------------------------
877 # kafka sender
878
879 send_kafka() {
917 - local httpcode sent=0
918 - if [ "${SEND_KAFKA}" = "YES" ]
919 - then
920 - httpcode=$(docurl -X POST \
921 - --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}\"}" \
922 - "${KAFKA_URL}")
923 -
924 - if [ "${httpcode}" = "204" ]
925 - then
926 - info "sent kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}'"
927 - sent=$((sent + 1))
928 - else
929 - error "failed to send kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}' with HTTP error code ${httpcode}."
930 - fi
931 -
932 - [ ${sent} -gt 0 ] && return 0
933 - fi
934 -
935 - return 1
880 + local httpcode sent=0
881 + if [ "${SEND_KAFKA}" = "YES" ]; then
882 + httpcode=$(docurl -X POST \
883 + --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}\"}" \
884 + "${KAFKA_URL}")
885 +
886 + if [ "${httpcode}" = "204" ]; then
887 + info "sent kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}'"
888 + sent=$((sent + 1))
889 + else
890 + error "failed to send kafka data for: ${host} ${chart}.${name} is ${status} and ip '${KAFKA_SENDER_IP}' with HTTP error code ${httpcode}."
891 + fi
892 +
893 + [ ${sent} -gt 0 ] && return 0
894 + fi
895 +
896 + return 1
897 }
898
899 # -----------------------------------------------------------------------------
900 # pagerduty.com sender
901
902 send_pd() {
942 - local recipients="${1}" sent=0
943 - unset t
944 - case ${status} in
945 - CLEAR) t='resolve';;
946 - WARNING) t='trigger';;
947 - CRITICAL) t='trigger';;
948 - esac
949 -
950 - if [ ${SEND_PD} = "YES" -a ! -z "${t}" ]
951 - then
952 - for PD_SERVICE_KEY in ${recipients}
953 - do
954 - d="${status} ${name} = ${value_string} - ${host}, ${family}"
955 - payload="$(cat << EOF
903 + local recipients="${1}" sent=0
904 + unset t
905 + case ${status} in
906 + CLEAR) t='resolve' ;;
907 + WARNING) t='trigger' ;;
908 + CRITICAL) t='trigger' ;;
909 + esac
910 +
911 + if [ ${SEND_PD} = "YES" ] && [ -n "${t}" ]; then
912 + for PD_SERVICE_KEY in ${recipients}; do
913 + d="${status} ${name} = ${value_string} - ${host}, ${family}"
914 + payload="$(
915 + cat <<EOF
916 {
917 "service_key": "${PD_SERVICE_KEY}",
918 "event_type": "${t}",
@@ -978,218 +938,195 @@ send_pd() {
938 }
939 }
940 EOF
981 - )"
982 - httpcode=$(docurl -X POST --data "${payload}" "https://events.pagerduty.com/generic/2010-04-15/create_event.json")
983 - if [ "${httpcode}" = "200" ]
984 - then
985 - info "sent pagerduty notification for: ${host} ${chart}.${name} is ${status}'"
986 - sent=$((sent + 1))
987 - else
988 - error "failed to send pagerduty notification for: ${host} ${chart}.${name} is ${status}, with HTTP error code ${httpcode}."
989 - fi
990 - done
991 -
992 - [ ${sent} -gt 0 ] && return 0
993 - fi
994 -
995 - return 1
941 + )"
942 + httpcode=$(docurl -X POST --data "${payload}" "https://events.pagerduty.com/generic/2010-04-15/create_event.json")
943 + if [ "${httpcode}" = "200" ]; then
944 + info "sent pagerduty notification for: ${host} ${chart}.${name} is ${status}'"
945 + sent=$((sent + 1))
946 + else
947 + error "failed to send pagerduty notification for: ${host} ${chart}.${name} is ${status}, with HTTP error code ${httpcode}."
948 + fi
949 + done
950 +
951 + [ ${sent} -gt 0 ] && return 0
952 + fi
953 +
954 + return 1
955 }
956
957 # -----------------------------------------------------------------------------
958 # twilio sender
959
960 send_twilio() {
1002 - local accountsid="${1}" accounttoken="${2}" twilionumber="${3}" recipients="${4}" title="${5}" message="${6}" httpcode sent=0 user
1003 - if [ "${SEND_TWILIO}" = "YES" -a ! -z "${accountsid}" -a ! -z "${accounttoken}" -a ! -z "${twilionumber}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
1004 - then
1005 - #https://www.twilio.com/packages/labs/code/bash/twilio-sms
1006 - for user in ${recipients}
1007 - do
1008 - httpcode=$(docurl -X POST \
1009 - --data-urlencode "From=${twilionumber}" \
1010 - --data-urlencode "To=${user}" \
1011 - --data-urlencode "Body=${title} ${message}" \
1012 - -u "${accountsid}:${accounttoken}" \
1013 - "https://api.twilio.com/2010-04-01/Accounts/${accountsid}/Messages.json")
1014 -
1015 - if [ "${httpcode}" = "201" ]
1016 - then
1017 - info "sent Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
1018 - sent=$((sent + 1))
1019 - else
1020 - error "failed to send Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
1021 - fi
1022 - done
1023 -
1024 - [ ${sent} -gt 0 ] && return 0
1025 - fi
1026 -
1027 - return 1
961 + local accountsid="${1}" accounttoken="${2}" twilionumber="${3}" recipients="${4}" title="${5}" message="${6}" httpcode sent=0 user
962 + if [ "${SEND_TWILIO}" = "YES" ] && [ -n "${accountsid}" ] && [ -n "${accounttoken}" ] && [ -n "${twilionumber}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
963 + #https://www.twilio.com/packages/labs/code/bash/twilio-sms
964 + for user in ${recipients}; do
965 + httpcode=$(docurl -X POST \
966 + --data-urlencode "From=${twilionumber}" \
967 + --data-urlencode "To=${user}" \
968 + --data-urlencode "Body=${title} ${message}" \
969 + -u "${accountsid}:${accounttoken}" \
970 + "https://api.twilio.com/2010-04-01/Accounts/${accountsid}/Messages.json")
971 +
972 + if [ "${httpcode}" = "201" ]; then
973 + info "sent Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
974 + sent=$((sent + 1))
975 + else
976 + error "failed to send Twilio SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
977 + fi
978 + done
979 +
980 + [ ${sent} -gt 0 ] && return 0
981 + fi
982 +
983 + return 1
984 }
985
1030 -
986 # -----------------------------------------------------------------------------
987 # hipchat sender
988
989 send_hipchat() {
1035 - local authtoken="${1}" recipients="${2}" message="${3}" httpcode sent=0 room color sender msg_format notify
1036 -
1037 - # remove <small></small> from the message
1038 - message="${message//<small>/}"
1039 - message="${message//<\/small>/}"
1040 -
1041 - if [ "${SEND_HIPCHAT}" = "YES" -a ! -z "${HIPCHAT_SERVER}" -a ! -z "${authtoken}" -a ! -z "${recipients}" -a ! -z "${message}" ]
1042 - then
1043 - # A label to be shown in addition to the sender's name
1044 - # Valid length range: 0 - 64.
1045 - sender="netdata"
1046 -
1047 - # Valid values: html, text.
1048 - # Defaults to 'html'.
1049 - msg_format="html"
1050 -
1051 - # Background color for message. Valid values: yellow, green, red, purple, gray, random. Defaults to 'yellow'.
1052 - case "${status}" in
1053 - WARNING) color="yellow" ;;
1054 - CRITICAL) color="red" ;;
1055 - CLEAR) color="green" ;;
1056 - *) color="gray" ;;
1057 - esac
1058 -
1059 - # Whether this message should trigger a user notification (change the tab color, play a sound, notify mobile phones, etc).
1060 - # Each recipient's notification preferences are taken into account.
1061 - # Defaults to false.
1062 - notify="true"
1063 -
1064 - for room in ${recipients}
1065 - do
1066 - httpcode=$(docurl -X POST \
1067 - -H "Content-type: application/json" \
1068 - -H "Authorization: Bearer ${authtoken}" \
1069 - -d "{\"color\": \"${color}\", \"from\": \"${host}\", \"message_format\": \"${msg_format}\", \"message\": \"${message}\", \"notify\": \"${notify}\"}" \
1070 - "https://${HIPCHAT_SERVER}/v2/room/${room}/notification")
1071 -
1072 - if [ "${httpcode}" = "204" ]
1073 - then
1074 - info "sent HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}'"
1075 - sent=$((sent + 1))
1076 - else
1077 - error "failed to send HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}' with HTTP error code ${httpcode}."
1078 - fi
1079 - done
1080 -
1081 - [ ${sent} -gt 0 ] && return 0
1082 - fi
1083 -
1084 - return 1
990 + local authtoken="${1}" recipients="${2}" message="${3}" httpcode sent=0 room color msg_format notify
991 +
992 + # remove <small></small> from the message
993 + message="${message//<small>/}"
994 + message="${message//<\/small>/}"
995 +
996 + if [ "${SEND_HIPCHAT}" = "YES" ] && [ -n "${HIPCHAT_SERVER}" ] && [ -n "${authtoken}" ] && [ -n "${recipients}" ] && [ -n "${message}" ]; then
997 + # Valid values: html, text.
998 + # Defaults to 'html'.
999 + msg_format="html"
1000 +
1001 + # Background color for message. Valid values: yellow, green, red, purple, gray, random. Defaults to 'yellow'.
1002 + case "${status}" in
1003 + WARNING) color="yellow" ;;
1004 + CRITICAL) color="red" ;;
1005 + CLEAR) color="green" ;;
1006 + *) color="gray" ;;
1007 + esac
1008 +
1009 + # Whether this message should trigger a user notification (change the tab color, play a sound, notify mobile phones, etc).
1010 + # Each recipient's notification preferences are taken into account.
1011 + # Defaults to false.
1012 + notify="true"
1013 +
1014 + for room in ${recipients}; do
1015 + httpcode=$(docurl -X POST \
1016 + -H "Content-type: application/json" \
1017 + -H "Authorization: Bearer ${authtoken}" \
1018 + -d "{\"color\": \"${color}\", \"from\": \"${host}\", \"message_format\": \"${msg_format}\", \"message\": \"${message}\", \"notify\": \"${notify}\"}" \
1019 + "https://${HIPCHAT_SERVER}/v2/room/${room}/notification")
1020 +
1021 + if [ "${httpcode}" = "204" ]; then
1022 + info "sent HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}'"
1023 + sent=$((sent + 1))
1024 + else
1025 + error "failed to send HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}' with HTTP error code ${httpcode}."
1026 + fi
1027 + done
1028 +
1029 + [ ${sent} -gt 0 ] && return 0
1030 + fi
1031 +
1032 + return 1
1033 }
1034
1087 -
1035 # -----------------------------------------------------------------------------
1036 # messagebird sender
1037
1038 send_messagebird() {
1092 - local accesskey="${1}" messagebirdnumber="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
1093 - if [ "${SEND_MESSAGEBIRD}" = "YES" -a ! -z "${accesskey}" -a ! -z "${messagebirdnumber}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
1094 - then
1095 - #https://developers.messagebird.com/docs/messaging
1096 - for user in ${recipients}
1097 - do
1098 - httpcode=$(docurl -X POST \
1099 - --data-urlencode "originator=${messagebirdnumber}" \
1100 - --data-urlencode "recipients=${user}" \
1101 - --data-urlencode "body=${title} ${message}" \
1102 - --data-urlencode "datacoding=auto" \
1103 - -H "Authorization: AccessKey ${accesskey}" \
1104 - "https://rest.messagebird.com/messages")
1105 -
1106 - if [ "${httpcode}" = "201" ]
1107 - then
1108 - info "sent Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
1109 - sent=$((sent + 1))
1110 - else
1111 - error "failed to send Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
1112 - fi
1113 - done
1114 -
1115 - [ ${sent} -gt 0 ] && return 0
1116 - fi
1117 -
1118 - return 1
1039 + local accesskey="${1}" messagebirdnumber="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
1040 + if [ "${SEND_MESSAGEBIRD}" = "YES" ] && [ -n "${accesskey}" ] && [ -n "${messagebirdnumber}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
1041 + #https://developers.messagebird.com/docs/messaging
1042 + for user in ${recipients}; do
1043 + httpcode=$(docurl -X POST \
1044 + --data-urlencode "originator=${messagebirdnumber}" \
1045 + --data-urlencode "recipients=${user}" \
1046 + --data-urlencode "body=${title} ${message}" \
1047 + --data-urlencode "datacoding=auto" \
1048 + -H "Authorization: AccessKey ${accesskey}" \
1049 + "https://rest.messagebird.com/messages")
1050 +
1051 + if [ "${httpcode}" = "201" ]; then
1052 + info "sent Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
1053 + sent=$((sent + 1))
1054 + else
1055 + error "failed to send Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
1056 + fi
1057 + done
1058 +
1059 + [ ${sent} -gt 0 ] && return 0
1060 + fi
1061 +
1062 + return 1
1063 }
1064
1065 # -----------------------------------------------------------------------------
1066 # kavenegar sender
1067
1068 send_kavenegar() {
1125 - local API_KEY="${1}" kavenegarsender="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
1126 - if [ "${SEND_KAVENEGAR}" = "YES" -a ! -z "${API_KEY}" -a ! -z "${kavenegarsender}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
1127 - then
1128 - # http://api.kavenegar.com/v1/{API-KEY}/sms/send.json
1129 - for user in ${recipients}
1130 - do
1131 - httpcode=$(docurl -X POST http://api.kavenegar.com/v1/${API_KEY}/sms/send.json \
1132 - --data-urlencode "sender=${kavenegarsender}" \
1133 - --data-urlencode "receptor=${user}" \
1134 - --data-urlencode "message=${title} ${message}")
1135 -
1136 - if [ "${httpcode}" = "200" ]
1137 - then
1138 - info "sent Kavenegar SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
1139 - sent=$((sent + 1))
1140 - else
1141 - error "failed to send Kavenegar SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
1142 - fi
1143 - done
1144 -
1145 - [ ${sent} -gt 0 ] && return 0
1146 - fi
1147 -
1148 - return 1
1069 + local API_KEY="${1}" kavenegarsender="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
1070 + if [ "${SEND_KAVENEGAR}" = "YES" ] && [ -n "${API_KEY}" ] && [ -n "${kavenegarsender}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
1071 + # http://api.kavenegar.com/v1/{API-KEY}/sms/send.json
1072 + for user in ${recipients}; do
1073 + httpcode=$(docurl -X POST http://api.kavenegar.com/v1/${API_KEY}/sms/send.json \
1074 + --data-urlencode "sender=${kavenegarsender}" \
1075 + --data-urlencode "receptor=${user}" \
1076 + --data-urlencode "message=${title} ${message}")
1077 +
1078 + if [ "${httpcode}" = "200" ]; then
1079 + info "sent Kavenegar SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
1080 + sent=$((sent + 1))
1081 + else
1082 + error "failed to send Kavenegar SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
1083 + fi
1084 + done
1085 +
1086 + [ ${sent} -gt 0 ] && return 0
1087 + fi
1088 +
1089 + return 1
1090 }
1091
1092 # -----------------------------------------------------------------------------
1093 # telegram sender
1094
1095 send_telegram() {
1155 - local bottoken="${1}" chatids="${2}" message="${3}" httpcode sent=0 chatid emoji disableNotification=""
1156 -
1157 - if [ "${status}" = "CLEAR" ]; then disableNotification="--data-urlencode disable_notification=true"; fi
1158 -
1159 - case "${status}" in
1160 - WARNING) emoji="⚠️" ;;
1161 - CRITICAL) emoji="🔴" ;;
1162 - CLEAR) emoji="✅" ;;
1163 - *) emoji="⚪️" ;;
1164 - esac
1165 -
1166 - if [ "${SEND_TELEGRAM}" = "YES" -a ! -z "${bottoken}" -a ! -z "${chatids}" -a ! -z "${message}" ];
1167 - then
1168 - for chatid in ${chatids}
1169 - do
1170 - # https://core.telegram.org/bots/api#sendmessage
1171 - httpcode=$(docurl ${disableNotification} \
1172 - --data-urlencode "parse_mode=HTML" \
1173 - --data-urlencode "disable_web_page_preview=true" \
1174 - --data-urlencode "text=${emoji} ${message}" \
1175 - "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatid}")
1176 -
1177 - if [ "${httpcode}" = "200" ]
1178 - then
1179 - info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
1180 - sent=$((sent + 1))
1181 - elif [ "${httpcode}" = "401" ]
1182 - then
1183 - error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
1184 - else
1185 - error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
1186 - fi
1187 - done
1188 -
1189 - [ ${sent} -gt 0 ] && return 0
1190 - fi
1191 -
1192 - return 1
1096 + local bottoken="${1}" chatids="${2}" message="${3}" httpcode sent=0 chatid emoji disableNotification=""
1097 +
1098 + if [ "${status}" = "CLEAR" ]; then disableNotification="--data-urlencode disable_notification=true"; fi
1099 +
1100 + case "${status}" in
1101 + WARNING) emoji="⚠️" ;;
1102 + CRITICAL) emoji="🔴" ;;
1103 + CLEAR) emoji="✅" ;;
1104 + *) emoji="⚪️" ;;
1105 + esac
1106 +
1107 + if [ "${SEND_TELEGRAM}" = "YES" ] && [ -n "${bottoken}" ] && [ -n "${chatids}" ] && [ -n "${message}" ]; then
1108 + for chatid in ${chatids}; do
1109 + # https://core.telegram.org/bots/api#sendmessage
1110 + httpcode=$(docurl ${disableNotification} \
1111 + --data-urlencode "parse_mode=HTML" \
1112 + --data-urlencode "disable_web_page_preview=true" \
1113 + --data-urlencode "text=${emoji} ${message}" \
1114 + "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatid}")
1115 +
1116 + if [ "${httpcode}" = "200" ]; then
1117 + info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
1118 + sent=$((sent + 1))
1119 + elif [ "${httpcode}" = "401" ]; then
1120 + error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
1121 + else
1122 + error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
1123 + fi
1124 + done
1125 +
1126 + [ ${sent} -gt 0 ] && return 0
1127 + fi
1128 +
1129 + return 1
1130 }
1131
1132 # -----------------------------------------------------------------------------
@@ -1197,22 +1134,22 @@ send_telegram() {
1134
1135 send_msteam() {
1136
1200 - local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1137 + local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1138
1202 - [ "${SEND_MSTEAM}" != "YES" ] && return 1
1139 + [ "${SEND_MSTEAM}" != "YES" ] && return 1
1140
1204 - case "${status}" in
1205 - WARNING) icon="${MSTEAM_ICON_WARNING}" && color="${MSTEAM_COLOR_WARNING}";;
1206 - CRITICAL) icon="${MSTEAM_ICON_CRITICAL}" && color="${MSTEAM_COLOR_CRITICAL}";;
1207 - CLEAR) icon="${MSTEAM_ICON_CLEAR}" && color="${MSTEAM_COLOR_CLEAR}";;
1208 - *) icon="${MSTEAM_ICON_DEFAULT}" && color="${MSTEAM_COLOR_DEFAULT}";;
1209 - esac
1141 + case "${status}" in
1142 + WARNING) icon="${MSTEAM_ICON_WARNING}" && color="${MSTEAM_COLOR_WARNING}" ;;
1143 + CRITICAL) icon="${MSTEAM_ICON_CRITICAL}" && color="${MSTEAM_COLOR_CRITICAL}" ;;
1144 + CLEAR) icon="${MSTEAM_ICON_CLEAR}" && color="${MSTEAM_COLOR_CLEAR}" ;;
1145 + *) icon="${MSTEAM_ICON_DEFAULT}" && color="${MSTEAM_COLOR_DEFAULT}" ;;
1146 + esac
1147
1211 - for channel in ${channels}
1212 - do
1213 - ## More details are available here regarding the payload syntax options : https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
1214 - ## Online designer : https://acdesignerbeta.azurewebsites.net/
1215 - payload="$(cat <<EOF
1148 + for channel in ${channels}; do
1149 + ## More details are available here regarding the payload syntax options : https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
1150 + ## Online designer : https://acdesignerbeta.azurewebsites.net/
1151 + payload="$(
1152 + cat <<EOF
1153 {
1154 "@context": "http://schema.org/extensions",
1155 "@type": "MessageCard",
@@ -1230,57 +1167,55 @@ send_msteam() {
1167 ]
1168 }
1169 EOF
1233 - )"
1170 + )"
1171
1235 - # Replacing in the webhook CHANNEL string by the MS Teams channel name from conf file.
1236 - webhook="${webhook//CHANNEL/${channel}}"
1172 + # Replacing in the webhook CHANNEL string by the MS Teams channel name from conf file.
1173 + webhook="${webhook//CHANNEL/${channel}}"
1174
1238 - httpcode=$(docurl -H "Content-Type: application/json" -d "${payload}" "${webhook}")
1175 + httpcode=$(docurl -H "Content-Type: application/json" -d "${payload}" "${webhook}")
1176
1240 - if [ "${httpcode}" = "200" ]
1241 - then
1242 - info "sent Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}'"
1243 - sent=$((sent + 1))
1244 - else
1245 - error "failed to send Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}', with HTTP error code ${httpcode}."
1246 - fi
1247 - done
1177 + if [ "${httpcode}" = "200" ]; then
1178 + info "sent Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}'"
1179 + sent=$((sent + 1))
1180 + else
1181 + error "failed to send Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}', with HTTP error code ${httpcode}."
1182 + fi
1183 + done
1184
1249 - [ ${sent} -gt 0 ] && return 0
1185 + [ ${sent} -gt 0 ] && return 0
1186
1251 - return 1
1187 + return 1
1188 }
1189
1254 -
1190 # slack sender
1191
1192 send_slack() {
1258 - local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1259 -
1260 - [ "${SEND_SLACK}" != "YES" ] && return 1
1261 -
1262 - case "${status}" in
1263 - WARNING) color="warning" ;;
1264 - CRITICAL) color="danger" ;;
1265 - CLEAR) color="good" ;;
1266 - *) color="#777777" ;;
1267 - esac
1268 -
1269 - for channel in ${channels}
1270 - do
1271 - # Default entry in the recipient is without a hash in front (backwards-compatible). Accept specification of channel or user.
1272 - if [ "${channel::1}" != "#" ] && [ "${channel::1}" != "@" ] ; then channel="#$channel"; fi
1273 -
1274 - # If channel is equal to "#" then do not send the channel attribute at all. Slack also defines channels and users in webhooks.
1275 - if [ "${channel}" = "#" ] ; then
1276 - ch=""
1277 - chstr="without specifying a channel"
1278 - else
1279 - ch="\"channel\": \"${channel}\","
1280 - chstr="to '${channel}'"
1281 - fi
1282 -
1283 - payload="$(cat <<EOF
1193 + local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1194 +
1195 + [ "${SEND_SLACK}" != "YES" ] && return 1
1196 +
1197 + case "${status}" in
1198 + WARNING) color="warning" ;;
1199 + CRITICAL) color="danger" ;;
1200 + CLEAR) color="good" ;;
1201 + *) color="#777777" ;;
1202 + esac
1203 +
1204 + for channel in ${channels}; do
1205 + # Default entry in the recipient is without a hash in front (backwards-compatible). Accept specification of channel or user.
1206 + if [ "${channel::1}" != "#" ] && [ "${channel::1}" != "@" ]; then channel="#$channel"; fi
1207 +
1208 + # If channel is equal to "#" then do not send the channel attribute at all. Slack also defines channels and users in webhooks.
1209 + if [ "${channel}" = "#" ]; then
1210 + ch=""
1211 + chstr="without specifying a channel"
1212 + else
1213 + ch="\"channel\": \"${channel}\","
1214 + chstr="to '${channel}'"
1215 + fi
1216 +
1217 + payload="$(
1218 + cat <<EOF
1219 {
1220 $ch
1221 "username": "netdata on ${host}",
@@ -1310,42 +1245,40 @@ send_slack() {
1245 ]
1246 }
1247 EOF
1313 - )"
1248 + )"
1249
1315 - httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
1316 - if [ "${httpcode}" = "200" ]
1317 - then
1318 - info "sent slack notification for: ${host} ${chart}.${name} is ${status} ${chstr}"
1319 - sent=$((sent + 1))
1320 - else
1321 - error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} ${chstr}, with HTTP error code ${httpcode}."
1322 - fi
1323 - done
1250 + httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
1251 + if [ "${httpcode}" = "200" ]; then
1252 + info "sent slack notification for: ${host} ${chart}.${name} is ${status} ${chstr}"
1253 + sent=$((sent + 1))
1254 + else
1255 + error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} ${chstr}, with HTTP error code ${httpcode}."
1256 + fi
1257 + done
1258
1325 - [ ${sent} -gt 0 ] && return 0
1259 + [ ${sent} -gt 0 ] && return 0
1260
1327 - return 1
1261 + return 1
1262 }
1263
1330 -
1264 # -----------------------------------------------------------------------------
1265 # rocketchat sender
1266
1267 send_rocketchat() {
1335 - local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1268 + local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1269
1337 - [ "${SEND_ROCKETCHAT}" != "YES" ] && return 1
1270 + [ "${SEND_ROCKETCHAT}" != "YES" ] && return 1
1271
1339 - case "${status}" in
1340 - WARNING) color="warning" ;;
1341 - CRITICAL) color="danger" ;;
1342 - CLEAR) color="good" ;;
1343 - *) color="#777777" ;;
1344 - esac
1272 + case "${status}" in
1273 + WARNING) color="warning" ;;
1274 + CRITICAL) color="danger" ;;
1275 + CLEAR) color="good" ;;
1276 + *) color="#777777" ;;
1277 + esac
1278
1346 - for channel in ${channels}
1347 - do
1348 - payload="$(cat <<EOF
1279 + for channel in ${channels}; do
1280 + payload="$(
1281 + cat <<EOF
1282 {
1283 "channel": "#${channel}",
1284 "alias": "netdata on ${host}",
@@ -1375,50 +1308,48 @@ send_rocketchat() {
1308 ]
1309 }
1310 EOF
1378 - )"
1311 + )"
1312
1380 - httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
1381 - if [ "${httpcode}" = "200" ]
1382 - then
1383 - info "sent rocketchat notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1384 - sent=$((sent + 1))
1385 - else
1386 - error "failed to send rocketchat notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1387 - fi
1388 - done
1313 + httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
1314 + if [ "${httpcode}" = "200" ]; then
1315 + info "sent rocketchat notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1316 + sent=$((sent + 1))
1317 + else
1318 + error "failed to send rocketchat notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1319 + fi
1320 + done
1321
1390 - [ ${sent} -gt 0 ] && return 0
1322 + [ ${sent} -gt 0 ] && return 0
1323
1392 - return 1
1324 + return 1
1325 }
1326
1327 # -----------------------------------------------------------------------------
1328 # alerta sender
1329
1330 send_alerta() {
1399 - local webhook="${1}" channels="${2}" httpcode sent=0 channel severity resource event payload auth
1400 -
1401 - [ "${SEND_ALERTA}" != "YES" ] && return 1
1402 -
1403 - case "${status}" in
1404 - CRITICAL) severity="critical" ;;
1405 - WARNING) severity="warning" ;;
1406 - CLEAR) severity="cleared" ;;
1407 - *) severity="indeterminate" ;;
1408 - esac
1409 -
1410 - if [[ "${chart}" == httpcheck* ]]
1411 - then
1412 - resource=$chart
1413 - event=$name
1414 - else
1415 - resource="${host}:${family}"
1416 - event="${chart}.${name}"
1417 - fi
1418 -
1419 - for channel in ${channels}
1420 - do
1421 - payload="$(cat <<EOF
1331 + local webhook="${1}" channels="${2}" httpcode sent=0 channel severity resource event payload auth
1332 +
1333 + [ "${SEND_ALERTA}" != "YES" ] && return 1
1334 +
1335 + case "${status}" in
1336 + CRITICAL) severity="critical" ;;
1337 + WARNING) severity="warning" ;;
1338 + CLEAR) severity="cleared" ;;
1339 + *) severity="indeterminate" ;;
1340 + esac
1341 +
1342 + if [[ ${chart} == httpcheck* ]]; then
1343 + resource=$chart
1344 + event=$name
1345 + else
1346 + resource="${host}:${family}"
1347 + event="${chart}.${name}"
1348 + fi
1349 +
1350 + for channel in ${channels}; do
1351 + payload="$(
1352 + cat <<EOF
1353 {
1354 "resource": "${resource}",
1355 "event": "${event}",
@@ -1442,50 +1373,46 @@ send_alerta() {
1373 "rawData": "${BASH_ARGV[@]}"
1374 }
1375 EOF
1445 - )"
1446 -
1447 - if [[ -n "${ALERTA_API_KEY}" ]]
1448 - then
1449 - auth="Key ${ALERTA_API_KEY}"
1450 - fi
1451 -
1452 - httpcode=$(docurl -X POST "${webhook}/alert" -H "Content-Type: application/json" -H "Authorization: $auth" --data "${payload}")
1453 -
1454 - if [[ "${httpcode}" = "200" || "${httpcode}" = "201" ]]
1455 - then
1456 - info "sent alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1457 - sent=$((sent + 1))
1458 - elif [[ "${httpcode}" = "202" ]]
1459 - then
1460 - info "suppressed alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1461 - else
1462 - error "failed to send alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1463 - fi
1464 - done
1465 -
1466 - [ ${sent} -gt 0 ] && return 0
1467 -
1468 - return 1
1376 + )"
1377 +
1378 + if [ -n "${ALERTA_API_KEY}" ]; then
1379 + auth="Key ${ALERTA_API_KEY}"
1380 + fi
1381 +
1382 + httpcode=$(docurl -X POST "${webhook}/alert" -H "Content-Type: application/json" -H "Authorization: $auth" --data "${payload}")
1383 +
1384 + if [ "${httpcode}" = "200" ] || [ "${httpcode}" = "201" ]; then
1385 + info "sent alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1386 + sent=$((sent + 1))
1387 + elif [ "${httpcode}" = "202" ]; then
1388 + info "suppressed alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1389 + else
1390 + error "failed to send alerta notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1391 + fi
1392 + done
1393 +
1394 + [ ${sent} -gt 0 ] && return 0
1395 +
1396 + return 1
1397 }
1398
1399 # -----------------------------------------------------------------------------
1400 # flock sender
1401
1402 send_flock() {
1475 - local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1403 + local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1404
1477 - [ "${SEND_FLOCK}" != "YES" ] && return 1
1405 + [ "${SEND_FLOCK}" != "YES" ] && return 1
1406
1479 - case "${status}" in
1480 - WARNING) color="warning" ;;
1481 - CRITICAL) color="danger" ;;
1482 - CLEAR) color="good" ;;
1483 - *) color="#777777" ;;
1484 - esac
1407 + case "${status}" in
1408 + WARNING) color="warning" ;;
1409 + CRITICAL) color="danger" ;;
1410 + CLEAR) color="good" ;;
1411 + *) color="#777777" ;;
1412 + esac
1413
1486 - for channel in ${channels}
1487 - do
1488 - httpcode=$(docurl -X POST "${webhook}" -H "Content-Type: application/json" -d "{
1414 + for channel in ${channels}; do
1415 + httpcode=$(docurl -X POST "${webhook}" -H "Content-Type: application/json" -d "{
1416 \"sendAs\": {
1417 \"name\" : \"netdata on ${host}\",
1418 \"profileImage\" : \"${images_base_url}/images/banner-icon-144x144.png\"
@@ -1508,42 +1435,41 @@ send_flock() {
1435 }
1436 }
1437 ]
1511 - }" )
1512 - if [ "${httpcode}" = "200" ]
1513 - then
1514 - info "sent flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1515 - sent=$((sent + 1))
1516 - else
1517 - error "failed to send flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1518 - fi
1519 - done
1520 -
1521 - [ ${sent} -gt 0 ] && return 0
1522 -
1523 - return 1
1438 + }")
1439 + if [ "${httpcode}" = "200" ]; then
1440 + info "sent flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1441 + sent=$((sent + 1))
1442 + else
1443 + error "failed to send flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1444 + fi
1445 + done
1446 +
1447 + [ ${sent} -gt 0 ] && return 0
1448 +
1449 + return 1
1450 }
1451
1452 # -----------------------------------------------------------------------------
1453 # discord sender
1454
1455 send_discord() {
1530 - local webhook="${1}/slack" channels="${2}" httpcode sent=0 channel color payload username
1456 + local webhook="${1}/slack" channels="${2}" httpcode sent=0 channel color payload username
1457
1532 - [ "${SEND_DISCORD}" != "YES" ] && return 1
1458 + [ "${SEND_DISCORD}" != "YES" ] && return 1
1459
1534 - case "${status}" in
1535 - WARNING) color="warning" ;;
1536 - CRITICAL) color="danger" ;;
1537 - CLEAR) color="good" ;;
1538 - *) color="#777777" ;;
1539 - esac
1460 + case "${status}" in
1461 + WARNING) color="warning" ;;
1462 + CRITICAL) color="danger" ;;
1463 + CLEAR) color="good" ;;
1464 + *) color="#777777" ;;
1465 + esac
1466
1541 - for channel in ${channels}
1542 - do
1543 - username="netdata on ${host}"
1544 - [ ${#username} -gt 32 ] && username="${username:0:29}..."
1467 + for channel in ${channels}; do
1468 + username="netdata on ${host}"
1469 + [ ${#username} -gt 32 ] && username="${username:0:29}..."
1470
1546 - payload="$(cat <<EOF
1471 + payload="$(
1472 + cat <<EOF
1473 {
1474 "channel": "#${channel}",
1475 "username": "${username}",
@@ -1569,262 +1495,262 @@ send_discord() {
1495 ]
1496 }
1497 EOF
1572 - )"
1498 + )"
1499
1574 - httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
1575 - if [ "${httpcode}" = "200" ]
1576 - then
1577 - info "sent discord notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1578 - sent=$((sent + 1))
1579 - else
1580 - error "failed to send discord notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1581 - fi
1582 - done
1500 + httpcode=$(docurl -X POST --data-urlencode "payload=${payload}" "${webhook}")
1501 + if [ "${httpcode}" = "200" ]; then
1502 + info "sent discord notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1503 + sent=$((sent + 1))
1504 + else
1505 + error "failed to send discord notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1506 + fi
1507 + done
1508
1584 - [ ${sent} -gt 0 ] && return 0
1509 + [ ${sent} -gt 0 ] && return 0
1510
1586 - return 1
1511 + return 1
1512 }
1513
1514 # -----------------------------------------------------------------------------
1515 # fleep sender
1516
1517 send_fleep() {
1593 - local httpcode sent=0 webhooks="${1}" data message
1594 - if [ "${SEND_FLEEP}" = "YES" ] ; then
1595 - message="${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}"
1596 -
1597 - for hook in "${webhooks}" ; do
1598 - data="{ "
1599 - data="${data} 'message': '${message}', "
1600 - data="${data} 'user': '${FLEEP_SENDER}' "
1601 - data="${data} }"
1602 -
1603 - httpcode=$(docurl -X POST --data "${data}" "https://fleep.io/hook/${hook}")
1604 -
1605 - if [ "${httpcode}" = "200" ] ; then
1606 - info "sent fleep data for: ${host} ${chart}.${name} is ${status} and user '${FLEEP_SENDER}'"
1607 - sent=$((sent + 1))
1608 - else
1609 - error "failed to send fleep data for: ${host} ${chart}.${name} is ${status} and user '${FLEEP_SENDER}' with HTTP error code ${httpcode}."
1610 - fi
1611 - done
1612 -
1613 - [ ${sent} -gt 0 ] && return 0
1614 - fi
1615 -
1616 - return 1
1518 + local httpcode sent=0 webhooks="${1}" data message
1519 + if [ "${SEND_FLEEP}" = "YES" ]; then
1520 + message="${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}"
1521 +
1522 + for hook in ${webhooks}; do
1523 + data="{ "
1524 + data="${data} 'message': '${message}', "
1525 + data="${data} 'user': '${FLEEP_SENDER}' "
1526 + data="${data} }"
1527 +
1528 + httpcode=$(docurl -X POST --data "${data}" "https://fleep.io/hook/${hook}")
1529 +
1530 + if [ "${httpcode}" = "200" ]; then
1531 + info "sent fleep data for: ${host} ${chart}.${name} is ${status} and user '${FLEEP_SENDER}'"
1532 + sent=$((sent + 1))
1533 + else
1534 + error "failed to send fleep data for: ${host} ${chart}.${name} is ${status} and user '${FLEEP_SENDER}' with HTTP error code ${httpcode}."
1535 + fi
1536 + done
1537 +
1538 + [ ${sent} -gt 0 ] && return 0
1539 + fi
1540 +
1541 + return 1
1542 }
1543
1544 # -----------------------------------------------------------------------------
1545 # Prowl sender
1546
1547 send_prowl() {
1623 - local httpcode sent=0 data message keys prio=0 alarm_url event
1624 - if [ "${SEND_PROWL}" = "YES" ] ; then
1625 - message="$(urlencode "${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}")"
1626 - message="description=${message}"
1627 - keys="$(urlencode "$(echo "${1}" | tr ' ' ,)")"
1628 - keys="apikey=${keys}"
1629 - app="application=Netdata"
1630 -
1631 - case "${status}" in
1632 - CRITICAL)
1633 - prio=2
1634 - ;;
1635 - WARNING)
1636 - prio=1
1637 - ;;
1638 - esac
1639 - pri="priority=${pri}"
1640 -
1641 - alarm_url="$(urlencode ${goto_url})"
1642 - alarm_url="url=${alarm_url}"
1643 - event="$(urlencode "${host} ${status_message}")"
1644 - event="event=${event}"
1645 -
1646 - data="${keys}&${pri}&${alarm_url}&${app}&${event}&${message}"
1647 -
1648 - httpcode=$(docurl -X POST --data "${data}" "https://api.prowlapp.com/publicapi/add")
1649 -
1650 - if [ "${httpcode}" = "200" ] ; then
1651 - info "sent prowl data for: ${host} ${chart}.${name} is ${status}"
1652 - sent=1
1653 - else
1654 - error "failed to send prowl data for: ${host} ${chart}.${name} is ${status} with with error code ${httpcode}."
1655 - fi
1656 -
1657 - [ ${sent} -gt 0 ] && return 0
1658 - fi
1659 -
1660 - return 1
1548 + local httpcode sent=0 data message keys prio=0 alarm_url event
1549 + if [ "${SEND_PROWL}" = "YES" ]; then
1550 + message="$(urlencode "${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}")"
1551 + message="description=${message}"
1552 + keys="$(urlencode "$(echo "${1}" | tr ' ' ,)")"
1553 + keys="apikey=${keys}"
1554 + app="application=Netdata"
1555 +
1556 + case "${status}" in
1557 + CRITICAL)
1558 + prio=2
1559 + ;;
1560 + WARNING)
1561 + prio=1
1562 + ;;
1563 + esac
1564 + prio="priority=${prio}"
1565 +
1566 + alarm_url="$(urlencode ${goto_url})"
1567 + alarm_url="url=${alarm_url}"
1568 + event="$(urlencode "${host} ${status_message}")"
1569 + event="event=${event}"
1570 +
1571 + data="${keys}&${prio}&${alarm_url}&${app}&${event}&${message}"
1572 +
1573 + httpcode=$(docurl -X POST --data "${data}" "https://api.prowlapp.com/publicapi/add")
1574 +
1575 + if [ "${httpcode}" = "200" ]; then
1576 + info "sent prowl data for: ${host} ${chart}.${name} is ${status}"
1577 + sent=1
1578 + else
1579 + error "failed to send prowl data for: ${host} ${chart}.${name} is ${status} with with error code ${httpcode}."
1580 + fi
1581 +
1582 + [ ${sent} -gt 0 ] && return 0
1583 + fi
1584 +
1585 + return 1
1586 }
1587
1588 # -----------------------------------------------------------------------------
1589 # irc sender
1590
1591 send_irc() {
1667 - local NICKNAME="${1}" REALNAME="${2}" CHANNELS="${3}" NETWORK="${4}" SERVERNAME="${5}" MESSAGE="${6}" sent=0 channel color send_alarm reply_codes error
1668 -
1669 - if [ "${SEND_IRC}" = "YES" -a ! -z "${NICKNAME}" -a ! -z "${REALNAME}" -a ! -z "${CHANNELS}" -a ! -z "${NETWORK}" -a ! -z "${SERVERNAME}" ]
1670 - then
1671 - case "${status}" in
1672 - WARNING) color="warning" ;;
1673 - CRITICAL) color="danger" ;;
1674 - CLEAR) color="good" ;;
1675 - *) color="#777777" ;;
1676 - esac
1677 -
1678 - for CHANNEL in ${CHANNELS}
1679 - do
1680 - error=0
1681 - send_alarm=$(echo -e "USER ${NICKNAME} guest ${REALNAME} ${SERVERNAME}\nNICK ${NICKNAME}\nJOIN ${CHANNEL}\nPRIVMSG ${CHANNEL} :${MESSAGE}\nQUIT\n" \ | nc ${NETWORK} 6667)
1682 - reply_codes=$(echo ${send_alarm} | cut -d ' ' -f 2 | grep -o '[0-9]*')
1683 - for code in ${reply_codes}
1684 - do
1685 - [ "${code}" -ge 400 -a "${code}" -le 599 ] && error=1 && break
1686 - done
1687 -
1688 - if [ "${error}" -eq 0 ]
1689 - then
1690 - info "sent irc notification for: ${host} ${chart}.${name} is ${status} to '${CHANNEL}'"
1691 - sent=$((sent + 1))
1692 - else
1693 - error "failed to send irc notification for: ${host} ${chart}.${name} is ${status} to '${CHANNEL}', with error code ${code}."
1694 - fi
1695 - done
1696 - fi
1697 -
1698 - [ ${sent} -gt 0 ] && return 0
1699 -
1700 - return 1
1592 + local NICKNAME="${1}" REALNAME="${2}" CHANNELS="${3}" NETWORK="${4}" SERVERNAME="${5}" MESSAGE="${6}" sent=0 channel color send_alarm reply_codes error
1593 +
1594 + if [ "${SEND_IRC}" = "YES" ] && [ -n "${NICKNAME}" ] && [ -n "${REALNAME}" ] && [ -n "${CHANNELS}" ] && [ -n "${NETWORK}" ] && [ -n "${SERVERNAME}" ]; then
1595 + case "${status}" in
1596 + WARNING) color="warning" ;;
1597 + CRITICAL) color="danger" ;;
1598 + CLEAR) color="good" ;;
1599 + *) color="#777777" ;;
1600 + esac
1601 +
1602 + for CHANNEL in ${CHANNELS}; do
1603 + error=0
1604 + send_alarm=$(echo -e "USER ${NICKNAME} guest ${REALNAME} ${SERVERNAME}\\nNICK ${NICKNAME}\\nJOIN ${CHANNEL}\\nPRIVMSG ${CHANNEL} :${MESSAGE}\\nQUIT\\n" \ | nc "${NETWORK}" 6667)
1605 + reply_codes=$(echo "${send_alarm}" | cut -d ' ' -f 2 | grep -o '[0-9]*')
1606 + for code in ${reply_codes}; do
1607 + if [ "${code}" -ge 400 ] && [ "${code}" -le 599 ]; then
1608 + error=1
1609 + break
1610 + fi
1611 + done
1612 +
1613 + if [ "${error}" -eq 0 ]; then
1614 + info "sent irc notification for: ${host} ${chart}.${name} is ${status} to '${CHANNEL}'"
1615 + sent=$((sent + 1))
1616 + else
1617 + error "failed to send irc notification for: ${host} ${chart}.${name} is ${status} to '${CHANNEL}', with error code ${code}."
1618 + fi
1619 + done
1620 + fi
1621 +
1622 + [ ${sent} -gt 0 ] && return 0
1623 +
1624 + return 1
1625 }
1626
1627 # -----------------------------------------------------------------------------
1628 # Amazon SNS sender
1629
1630 send_awssns() {
1707 - local targets="${1}" message='' sent=0 region=''
1708 - local default_format="${status} on ${host} at ${date}: ${chart} ${value_string}"
1631 + local targets="${1}" message='' sent=0 region=''
1632 + local default_format="${status} on ${host} at ${date}: ${chart} ${value_string}"
1633
1710 - [ "${SEND_AWSSNS}" = "YES" ] || return 1
1634 + [ "${SEND_AWSSNS}" = "YES" ] || return 1
1635
1712 - message=${AWSSNS_MESSAGE_FORMAT:-${default_format}}
1636 + message=${AWSSNS_MESSAGE_FORMAT:-${default_format}}
1637
1714 - for target in ${targets} ; do
1715 - # Extract the region from the target ARN. We need to explicitly specify the region so that it matches up correctly.
1716 - region="$(echo ${target} | cut -f 4 -d ':')"
1717 - ${aws} sns publish --region "${region}" --subject "${host} ${status_message} - ${name//_/ } - ${chart}" --message "${message}" --target-arn ${target} &>/dev/null
1718 - if [ $? = 0 ]; then
1719 - info "sent Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
1720 - sent=$((sent + 1))
1721 - else
1722 - error "failed to send Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
1723 - fi
1724 - done
1638 + for target in ${targets}; do
1639 + # Extract the region from the target ARN. We need to explicitly specify the region so that it matches up correctly.
1640 + region="$(echo ${target} | cut -f 4 -d ':')"
1641 + if ${aws} sns publish --region "${region}" --subject "${host} ${status_message} - ${name//_/ } - ${chart}" --message "${message}" --target-arn ${target} &>/dev/null; then
1642 + info "sent Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
1643 + sent=$((sent + 1))
1644 + else
1645 + error "failed to send Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
1646 + fi
1647 + done
1648
1726 - [ ${sent} -gt 0 ] && return 0
1649 + [ ${sent} -gt 0 ] && return 0
1650
1728 - return 1
1651 + return 1
1652 }
1653
1654 # -----------------------------------------------------------------------------
1655 # syslog sender
1656
1657 send_syslog() {
1735 - local facility=${SYSLOG_FACILITY:-"local6"} level='info' targets="${1}"
1736 - local priority='' message='' host='' port='' prefix=''
1737 - local temp1='' temp2=''
1738 -
1739 - [ "${SEND_SYSLOG}" = "YES" ] || return 1
1740 -
1741 - if [ "${status}" = "CRITICAL" ] ; then
1742 - level='crit'
1743 - elif [ "${status}" = "WARNING" ] ; then
1744 - level='warning'
1745 - fi
1746 -
1747 - for target in ${targets} ; do
1748 - priority="${facility}.${level}"
1749 - message=''
1750 - host=''
1751 - port=''
1752 - prefix=''
1753 - temp1=''
1754 - temp2=''
1755 -
1756 - prefix=$(echo ${target} | cut -d '/' -f 2)
1757 - temp1=$(echo ${target} | cut -d '/' -f 1)
1758 -
1759 - if [ ${prefix} != ${temp1} ] ; then
1760 - if (echo ${temp1} | grep -q '@' ) ; then
1761 - temp2=$(echo ${temp1} | cut -d '@' -f 1)
1762 - host=$(echo ${temp1} | cut -d '@' -f 2)
1763 -
1764 - if [ ${temp2} != ${host} ] ; then
1765 - priority=${temp2}
1766 - fi
1767 -
1768 - port=$(echo ${host} | rev | cut -d ':' -f 1 | rev)
1769 -
1770 - if ( echo ${host} | grep -E -q '\[.*\]' ) ; then
1771 - if ( echo ${port} | grep -q ']' ) ; then
1772 - port=''
1773 - else
1774 - host=$(echo ${host} | rev | cut -d ':' -f 2- | rev)
1775 - fi
1776 - else
1777 - if [ ${port} = ${host} ] ; then
1778 - port=''
1779 - else
1780 - host=$(echo ${host} | cut -d ':' -f 1)
1781 - fi
1782 - fi
1783 - else
1784 - priority=${temp1}
1785 - fi
1786 - fi
1787 -
1788 - message="${prefix} ${status} on ${host} at ${date}: ${chart} ${value_string}"
1789 -
1790 - if [ ${host} ] ; then
1791 - logger_options="${logger_options} -n ${host}"
1792 - if [ ${port} ] ; then
1793 - logger_options="${logger_options} -P ${port}"
1794 - fi
1795 - fi
1796 -
1797 - ${logger} -p ${priority} ${logger_options} "${message}"
1798 - done
1799 -
1800 - return $?
1658 + local facility=${SYSLOG_FACILITY:-"local6"} level='info' targets="${1}"
1659 + local priority='' message='' host='' port='' prefix=''
1660 + local temp1='' temp2=''
1661 +
1662 + [ "${SEND_SYSLOG}" = "YES" ] || return 1
1663 +
1664 + if [ "${status}" = "CRITICAL" ]; then
1665 + level='crit'
1666 + elif [ "${status}" = "WARNING" ]; then
1667 + level='warning'
1668 + fi
1669 +
1670 + for target in ${targets}; do
1671 + priority="${facility}.${level}"
1672 + message=''
1673 + host=''
1674 + port=''
1675 + prefix=''
1676 + temp1=''
1677 + temp2=''
1678 +
1679 + prefix=$(echo ${target} | cut -d '/' -f 2)
1680 + temp1=$(echo ${target} | cut -d '/' -f 1)
1681 +
1682 + if [ ${prefix} != ${temp1} ]; then
1683 + if (echo ${temp1} | grep -q '@'); then
1684 + temp2=$(echo ${temp1} | cut -d '@' -f 1)
1685 + host=$(echo ${temp1} | cut -d '@' -f 2)
1686 +
1687 + if [ ${temp2} != ${host} ]; then
1688 + priority=${temp2}
1689 + fi
1690 +
1691 + port=$(echo ${host} | rev | cut -d ':' -f 1 | rev)
1692 +
1693 + if (echo ${host} | grep -E -q '\[.*\]'); then
1694 + if (echo ${port} | grep -q ']'); then
1695 + port=''
1696 + else
1697 + host=$(echo ${host} | rev | cut -d ':' -f 2- | rev)
1698 + fi
1699 + else
1700 + if [ ${port} = ${host} ]; then
1701 + port=''
1702 + else
1703 + host=$(echo ${host} | cut -d ':' -f 1)
1704 + fi
1705 + fi
1706 + else
1707 + priority=${temp1}
1708 + fi
1709 + fi
1710 +
1711 + message="${prefix} ${status} on ${host} at ${date}: ${chart} ${value_string}"
1712 +
1713 + if [ ${host} ]; then
1714 + logger_options="${logger_options} -n ${host}"
1715 + if [ ${port} ]; then
1716 + logger_options="${logger_options} -P ${port}"
1717 + fi
1718 + fi
1719 +
1720 + ${logger} -p ${priority} ${logger_options} "${message}"
1721 + done
1722 +
1723 + return $?
1724 }
1725
1803 -
1726 # -----------------------------------------------------------------------------
1727 # prepare the content of the notification
1728
1729 # the url to send the user on click
1808 -urlencode "${args_host}" >/dev/null; url_host="${REPLY}"
1809 -urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
1810 -urlencode "${family}" >/dev/null; url_family="${REPLY}"
1811 -urlencode "${name}" >/dev/null; url_name="${REPLY}"
1730 +urlencode "${args_host}" >/dev/null
1731 +url_host="${REPLY}"
1732 +urlencode "${chart}" >/dev/null
1733 +url_chart="${REPLY}"
1734 +urlencode "${family}" >/dev/null
1735 +url_family="${REPLY}"
1736 +urlencode "${name}" >/dev/null
1737 +url_name="${REPLY}"
1738
1739 redirect_params="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}"
1740 GOTOCLOUD=0
1741
1816 -if [ "${NETDATA_REGISTRY_URL}" == "https://registry.my-netdata.io" ] ; then
1817 - if [ -z "${NETDATA_REGISTRY_UNIQUE_ID}" ] ; then
1818 - if [ -f "@registrydir_POST@/netdata.public.unique.id" ]; then
1819 - NETDATA_REGISTRY_UNIQUE_ID="$(cat "@registrydir_POST@/netdata.public.unique.id")"
1820 - fi
1821 - fi
1822 - if [ ! -z "${NETDATA_REGISTRY_UNIQUE_ID}" ] ; then
1823 - GOTOCLOUD=1
1824 - fi
1742 +if [ "${NETDATA_REGISTRY_URL}" == "https://registry.my-netdata.io" ]; then
1743 + if [ -z "${NETDATA_REGISTRY_UNIQUE_ID}" ]; then
1744 + if [ -f "@registrydir_POST@/netdata.public.unique.id" ]; then
1745 + NETDATA_REGISTRY_UNIQUE_ID="$(cat "@registrydir_POST@/netdata.public.unique.id")"
1746 + fi
1747 + fi
1748 + if [ ! -z "${NETDATA_REGISTRY_UNIQUE_ID}" ]; then
1749 + GOTOCLOUD=1
1750 + fi
1751 fi
1752
1827 -if [ ${GOTOCLOUD} -eq 0 ] ; then
1753 +if [ ${GOTOCLOUD} -eq 0 ]; then
1754 goto_url="${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html?${redirect_params}"
1755 else
1756 goto_url="https://netdata.cloud/alarms/redirect?agentID=${NETDATA_REGISTRY_UNIQUE_ID}&${redirect_params}"
@@ -1834,8 +1760,10 @@ fi
1760 severity="${status}"
1761
1762 # the time the alarm was raised
1837 -duration4human ${duration} >/dev/null; duration_txt="${REPLY}"
1838 -duration4human ${non_clear_duration} >/dev/null; non_clear_duration_txt="${REPLY}"
1763 +duration4human ${duration} >/dev/null
1764 +duration_txt="${REPLY}"
1765 +duration4human ${non_clear_duration} >/dev/null
1766 +non_clear_duration_txt="${REPLY}"
1767 raised_for="(was ${old_status,,} for ${duration_txt})"
1768
1769 # the key status message
@@ -1852,63 +1780,57 @@ image="${images_base_url}/images/banner-icon-144x144.png"
1780
1781 # prepare the title based on status
1782 case "${status}" in
1855 - CRITICAL)
1856 - image="${images_base_url}/images/alert-128-red.png"
1857 - status_message="is critical"
1858 - color="#ca414b"
1859 - ;;
1860 -
1861 - WARNING)
1862 - image="${images_base_url}/images/alert-128-orange.png"
1863 - status_message="needs attention"
1864 - color="#ffc107"
1865 - ;;
1866 -
1867 - CLEAR)
1868 - image="${images_base_url}/images/check-mark-2-128-green.png"
1869 - status_message="recovered"
1870 - color="#77ca6d"
1871 - ;;
1783 +CRITICAL)
1784 + image="${images_base_url}/images/alert-128-red.png"
1785 + status_message="is critical"
1786 + color="#ca414b"
1787 + ;;
1788 +
1789 +WARNING)
1790 + image="${images_base_url}/images/alert-128-orange.png"
1791 + status_message="needs attention"
1792 + color="#ffc107"
1793 + ;;
1794 +
1795 +CLEAR)
1796 + image="${images_base_url}/images/check-mark-2-128-green.png"
1797 + status_message="recovered"
1798 + color="#77ca6d"
1799 + ;;
1800 esac
1801
1874 -if [ "${status}" = "CLEAR" ]
1875 -then
1876 - severity="Recovered from ${old_status}"
1877 - if [ ${non_clear_duration} -gt ${duration} ]
1878 - then
1879 - raised_for="(alarm was raised for ${non_clear_duration_txt})"
1880 - fi
1881 -
1882 - # don't show the value when the status is CLEAR
1883 - # for certain alarms, this value might not have any meaning
1884 - alarm="${name//_/ } ${raised_for}"
1885 -
1886 -elif [ "${old_status}" = "WARNING" -a "${status}" = "CRITICAL" ]
1887 -then
1888 - severity="Escalated to ${status}"
1889 - if [ ${non_clear_duration} -gt ${duration} ]
1890 - then
1891 - raised_for="(alarm is raised for ${non_clear_duration_txt})"
1892 - fi
1893 -
1894 -elif [ "${old_status}" = "CRITICAL" -a "${status}" = "WARNING" ]
1895 -then
1896 - severity="Demoted to ${status}"
1897 - if [ ${non_clear_duration} -gt ${duration} ]
1898 - then
1899 - raised_for="(alarm is raised for ${non_clear_duration_txt})"
1900 - fi
1802 +if [ "${status}" = "CLEAR" ]; then
1803 + severity="Recovered from ${old_status}"
1804 + if [ ${non_clear_duration} -gt ${duration} ]; then
1805 + raised_for="(alarm was raised for ${non_clear_duration_txt})"
1806 + fi
1807 +
1808 + # don't show the value when the status is CLEAR
1809 + # for certain alarms, this value might not have any meaning
1810 + alarm="${name//_/ } ${raised_for}"
1811 +
1812 +elif { [ "${old_status}" = "WARNING" ] && [ "${status}" = "CRITICAL" ]; }; then
1813 + severity="Escalated to ${status}"
1814 + if [ ${non_clear_duration} -gt ${duration} ]; then
1815 + raised_for="(alarm is raised for ${non_clear_duration_txt})"
1816 + fi
1817 +
1818 +elif { [ "${old_status}" = "CRITICAL" ] && [ "${status}" = "WARNING" ]; }; then
1819 + severity="Demoted to ${status}"
1820 + if [ ${non_clear_duration} -gt ${duration} ]; then
1821 + raised_for="(alarm is raised for ${non_clear_duration_txt})"
1822 + fi
1823
1824 else
1903 - raised_for=
1825 + raised_for=
1826 fi
1827
1828 # prepare HTML versions of elements
1829 info_html=
1908 -[ ! -z "${info}" ] && info_html=" <small><br/>${info}</small>"
1830 +[ -n "${info}" ] && info_html=" <small><br/>${info}</small>"
1831
1832 raised_for_html=
1911 -[ ! -z "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
1833 +[ -n "${raised_for}" ] && raised_for_html="<br/><small>${raised_for}</small>"
1834
1835 # -----------------------------------------------------------------------------
1836 # send the slack notification
@@ -1982,11 +1904,11 @@ SENT_PUSHOVER=$?
1904 # -----------------------------------------------------------------------------
1905 # send the pushbullet notification
1906
1985 -send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${PUSHBULLET_SOURCE_DEVICE}" "${to_pushbullet}" "${goto_url}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\n
1986 -Severity: ${severity}\n
1987 -Chart: ${chart}\n
1988 -Family: ${family}\n
1989 -$(date -d @${when})\n
1907 +send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${PUSHBULLET_SOURCE_DEVICE}" "${to_pushbullet}" "${goto_url}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\\n
1908 +Severity: ${severity}\\n
1909 +Chart: ${chart}\\n
1910 +Family: ${family}\\n
1911 +$(date -d @${when})\\n
1912 The source of this alarm is line ${src}"
1913
1914 SENT_PUSHBULLET=$?
@@ -2013,7 +1935,6 @@ ${info}"
1935
1936 SENT_MESSAGEBIRD=$?
1937
2016 -
1938 # -----------------------------------------------------------------------------
1939 # send the kavenegar SMS
1940
@@ -2025,7 +1946,6 @@ ${info}"
1946
1947 SENT_KAVENEGAR=$?
1948
2028 -
1949 # -----------------------------------------------------------------------------
1950 # send the telegram.org message
1951
@@ -2037,14 +1957,12 @@ ${chart} (${family})
1957
1958 SENT_TELEGRAM=$?
1959
2040 -
1960 # -----------------------------------------------------------------------------
1961 # send the kafka message
1962
1963 send_kafka
1964 SENT_KAFKA=$?
1965
2047 -
1966 # -----------------------------------------------------------------------------
1967 # send the pagerduty.com message
1968
@@ -2078,20 +1996,19 @@ SENT_IRC=$?
1996 # send the custom message
1997
1998 send_custom() {
2081 - # is it enabled?
2082 - [ "${SEND_CUSTOM}" != "YES" ] && return 1
1999 + # is it enabled?
2000 + [ "${SEND_CUSTOM}" != "YES" ] && return 1
2001
2084 - # do we have any sender?
2085 - [ -z "${1}" ] && return 1
2002 + # do we have any sender?
2003 + [ -z "${1}" ] && return 1
2004
2087 - # call the custom_sender function
2088 - custom_sender "${@}"
2005 + # call the custom_sender function
2006 + custom_sender "${@}"
2007 }
2008
2009 send_custom "${to_custom}"
2010 SENT_CUSTOM=$?
2011
2094 -
2012 # -----------------------------------------------------------------------------
2013 # send hipchat message
2014
@@ -2106,23 +2023,20 @@ ${host} ${status_message}<br/> \
2023
2024 SENT_HIPCHAT=$?
2025
2109 -
2026 # -----------------------------------------------------------------------------
2027 # send the Amazon SNS message
2028
2113 -send_awssns ${to_awssns}
2029 +send_awssns "${to_awssns}"
2030
2031 SENT_AWSSNS=$?
2032
2117 -
2033 # -----------------------------------------------------------------------------
2034 # send the syslog message
2035
2121 -send_syslog ${to_syslog}
2036 +send_syslog "${to_syslog}"
2037
2038 SENT_SYSLOG=$?
2039
2125 -
2040 # -----------------------------------------------------------------------------
2041 # send the email
2042
@@ -2271,34 +2185,32 @@ SENT_EMAIL=$?
2185
2186 # -----------------------------------------------------------------------------
2187 # let netdata know
2274 -
2275 -if [ ${SENT_EMAIL} -eq 0 \
2276 - -o ${SENT_PUSHOVER} -eq 0 \
2277 - -o ${SENT_TELEGRAM} -eq 0 \
2278 - -o ${SENT_SLACK} -eq 0 \
2279 - -o ${SENT_MSTEAM} -eq 0 \
2280 - -o ${SENT_ROCKETCHAT} -eq 0 \
2281 - -o ${SENT_ALERTA} -eq 0 \
2282 - -o ${SENT_FLOCK} -eq 0 \
2283 - -o ${SENT_DISCORD} -eq 0 \
2284 - -o ${SENT_TWILIO} -eq 0 \
2285 - -o ${SENT_HIPCHAT} -eq 0 \
2286 - -o ${SENT_MESSAGEBIRD} -eq 0 \
2287 - -o ${SENT_KAVENEGAR} -eq 0 \
2288 - -o ${SENT_PUSHBULLET} -eq 0 \
2289 - -o ${SENT_KAFKA} -eq 0 \
2290 - -o ${SENT_PD} -eq 0 \
2291 - -o ${SENT_FLEEP} -eq 0 \
2292 - -o ${SENT_PROWL} -eq 0 \
2293 - -o ${SENT_IRC} -eq 0 \
2294 - -o ${SENT_AWSSNS} -eq 0 \
2295 - -o ${SENT_CUSTOM} -eq 0 \
2296 - -o ${SENT_SYSLOG} -eq 0 \
2297 - ]
2298 - then
2299 - # we did send something
2300 - exit 0
2301 -fi
2302 -
2188 +for state in "${SENT_EMAIL}" \
2189 + "${SENT_PUSHOVER}" \
2190 + "${SENT_TELEGRAM}" \
2191 + "${SENT_SLACK}" \
2192 + "${SENT_ROCKETCHAT}" \
2193 + "${SENT_ALERTA}" \
2194 + "${SENT_FLOCK}" \
2195 + "${SENT_DISCORD}" \
2196 + "${SENT_TWILIO}" \
2197 + "${SENT_HIPCHAT}" \
2198 + "${SENT_MESSAGEBIRD}" \
2199 + "${SENT_KAVENEGAR}" \
2200 + "${SENT_PUSHBULLET}" \
2201 + "${SENT_KAFKA}" \
2202 + "${SENT_PD}" \
2203 + "${SENT_FLEEP}" \
2204 + "${SENT_PROWL}" \
2205 + "${SENT_CUSTOM}" \
2206 + "${SENT_IRC}" \
2207 + "${SENT_AWSSNS}" \
2208 + "${SENT_SYSLOG}" \
2209 + "${SENT_MSTEAM}"; do
2210 + if [ "${state}" -eq 0 ]; then
2211 + # we sent something
2212 + exit 0
2213 + fi
2214 +done
2215 # we did not send anything
2216 exit 1