@cryptotaxi247 / netdata-1 / commits / 68f8fb8cd

Update alarm-notify.sh

Added messagebird.com SMS provider

tech-no-logical committed Jan 10, 2017 at 16:25 UTC 68f8fb8cd1e223130a60da199b19cf3edf4b47bf
1 file changed +88 -17
plugins.d/alarm-notify.sh
+88 -17
@@ -22,6 +22,7 @@
22 # - twilio.com notifications by Levi Blaney @shadycuz PR #1211
23 # - kafka notifications
24 # - pagerduty.com notifications by Jim Cooley @jimcooley PR #1373
25 +# - messagebird.com notifications by @tech_no_logical
26
27 # -----------------------------------------------------------------------------
28 # testing notifications
@@ -172,6 +173,7 @@ sendmail=
173 SEND_SLACK="YES"
174 SEND_PUSHOVER="YES"
175 SEND_TWILIO="YES"
176 +SEND_MESSAGEBIRD="YES"
177 SEND_TELEGRAM="YES"
178 SEND_EMAIL="YES"
179 SEND_PUSHBULLET="YES"
@@ -200,6 +202,12 @@ TWILIO_NUMBER=
202 DEFAULT_RECIPIENT_TWILIO=
203 declare -A role_recipients_twilio=()
204
205 +# messagebird configs
206 +MESSAGEBIRD_ACCESS_KEY=
207 +MESSAGEBIRD_NUMBER=
208 +DEFAULT_RECIPIENT_MESSAGEBIRD=
209 +declare -A role_recipients_messagebird=()
210 +
211 # telegram configs
212 TELEGRAM_BOT_TOKEN=
213 DEFAULT_RECIPIENT_TELEGRAM=
@@ -315,6 +323,14 @@ do
323 [ "${r}" != "disabled" ] && filter_recipient_by_criticality twilio "${r}" && arr_twilio[${r/|*/}]="1"
324 done
325
326 + # messagebird
327 + a="${role_recipients_messagebird[${x}]}"
328 + [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_MESSAGEBIRD}"
329 + for r in ${a//,/ }
330 + do
331 + [ "${r}" != "disabled" ] && filter_recipient_by_criticality messagebird "${r}" && arr_messagebird[${r/|*/}]="1"
332 + done
333 +
334 # telegram
335 a="${role_recipients_telegram[${x}]}"
336 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
@@ -356,6 +372,10 @@ to_pushbullet="${!arr_pushbullet[*]}"
372 to_twilio="${!arr_twilio[*]}"
373 [ -z "${to_twilio}" ] && SEND_TWILIO="NO"
374
375 +# build the list of messagebird recipients (phone numbers)
376 +to_messagebird="${!arr_messagebird[*]}"
377 +[ -z "${to_messagebird}" ] && SEND_MESSAGEBIRD="NO"
378 +
379 # check array of telegram recipients (chat ids)
380 to_telegram="${!arr_telegram[*]}"
381 [ -z "${to_telegram}" ] && SEND_TELEGRAM="NO"
@@ -389,6 +409,9 @@ done
409 # check twilio
410 [ -z "${TWILIO_ACCOUNT_TOKEN}" -o -z "${TWILIO_ACCOUNT_SID}" -o -z "${TWILIO_NUMBER}" ] && SEND_TWILIO="NO"
411
412 +# check messagebird
413 +[ -z "${MESSAGEBIRD_ACCESS_KEY}" -o -z "${MESSAGEBIRD_NUMBER}" ] && SEND_MESSAGEBIRD="NO"
414 +
415 # check telegram
416 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
417
@@ -410,7 +433,7 @@ if [ "${SEND_PD}" = "YES" ]
433 fi
434
435 # if we need curl, check for the curl command
413 -if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TWILIO}" = "YES" -o "${SEND_TELEGRAM}" = "YES" -o "${SEND_PUSHBULLET}" = "YES" -o "${SEND_KAFKA}" = "YES" \) -a -z "${curl}" ]
436 +if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TWILIO}" = "YES" -o "${SEND_MESSAGEBIRD}" = "YES" -o "${SEND_TELEGRAM}" = "YES" -o "${SEND_PUSHBULLET}" = "YES" -o "${SEND_KAFKA}" = "YES" \) -a -z "${curl}" ]
437 then
438 curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
439 if [ -z "${curl}" ]
@@ -422,6 +445,7 @@ if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TWILIO}
445 SEND_TELEGRAM="NO"
446 SEND_SLACK="NO"
447 SEND_TWILIO="NO"
448 + SEND_MESSAGEBIRD="NO"
449 SEND_KAFKA="NO"
450 fi
451 fi
@@ -434,14 +458,15 @@ if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
458 fi
459
460 # check that we have at least a method enabled
437 -if [ "${SEND_EMAIL}" != "YES" \
438 - -a "${SEND_PUSHOVER}" != "YES" \
439 - -a "${SEND_TELEGRAM}" != "YES" \
440 - -a "${SEND_SLACK}" != "YES" \
441 - -a "${SEND_TWILIO}" != "YES" \
442 - -a "${SEND_PUSHBULLET}" != "YES" \
443 - -a "${SEND_KAFKA}" != "YES" \
444 - -a "${SEND_PD}" != "YES" \
461 +if [ "${SEND_EMAIL}" != "YES" \
462 + -a "${SEND_PUSHOVER}" != "YES" \
463 + -a "${SEND_TELEGRAM}" != "YES" \
464 + -a "${SEND_SLACK}" != "YES" \
465 + -a "${SEND_TWILIO}" != "YES" \
466 + -a "${SEND_MESSAGEBIRD}" != "YES" \
467 + -a "${SEND_PUSHBULLET}" != "YES" \
468 + -a "${SEND_KAFKA}" != "YES" \
469 + -a "${SEND_PD}" != "YES" \
470 ]
471 then
472 fatal "All notification methods are disabled. Not sending notification to '${roles}' for '${name}' = '${value}' of chart '${chart}' for status '${status}'."
@@ -760,6 +785,39 @@ send_twilio() {
785 return 1
786 }
787
788 +# -----------------------------------------------------------------------------
789 +# messagebird sender
790 +
791 +send_messagebird() {
792 + local accesskey="${1}" messagebirdnumber="${2}" recipients="${3}" title="${4}" message="${5}" httpcode sent=0 user
793 + if [ "${SEND_MESSAGEBIRD}" = "YES" -a ! -z "${accesskey}" -a ! -z "${messagebirdnumber}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
794 + then
795 + #https://developers.messagebird.com/docs/messaging
796 + for user in ${recipients}
797 + do
798 + httpcode=$(${curl} -X POST --write-out %{http_code} --silent --output /dev/null \
799 + --data-urlencode "originator=${messagebirdnumber}" \
800 + --data-urlencode "recipients=${user}" \
801 + --data-urlencode "body=${title} ${message}" \
802 + --data-urlencode "datacoding=auto" \
803 + -H "Authorization: AccessKey ${accesskey}" \
804 + "https://rest.messagebird.com/messages")
805 +
806 + if [ "${httpcode}" == "201" ]
807 + then
808 + info "sent Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}'"
809 + sent=$((sent + 1))
810 + else
811 + error "failed to send Messagebird SMS for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
812 + fi
813 + done
814 +
815 + [ ${sent} -gt 0 ] && return 0
816 + fi
817 +
818 + return 1
819 +}
820 +
821 # -----------------------------------------------------------------------------
822 # telegram sender
823
@@ -999,6 +1057,18 @@ ${info}"
1057
1058 SENT_TWILIO=$?
1059
1060 +# -----------------------------------------------------------------------------
1061 +# send the messagebird SMS
1062 +
1063 +send_messagebird "${MESSAGEBIRD_ACCESS_KEY}" "${MESSAGEBIRD_NUMBER}" "${to_messagebird}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}
1064 +Severity: ${severity}
1065 +Chart: ${chart}
1066 +Family: ${family}
1067 +${info}"
1068 +
1069 +SENT_MESSAGEBIRD=$?
1070 +
1071 +
1072 # -----------------------------------------------------------------------------
1073 # send the telegram.org message
1074
@@ -1123,14 +1193,15 @@ SENT_EMAIL=$?
1193 # -----------------------------------------------------------------------------
1194 # let netdata know
1195
1126 -if [ ${SENT_EMAIL} -eq 0 \
1127 - -o ${SENT_PUSHOVER} -eq 0 \
1128 - -o ${SENT_TELEGRAM} -eq 0 \
1129 - -o ${SENT_SLACK} -eq 0 \
1130 - -o ${SENT_TWILIO} -eq 0 \
1131 - -o ${SENT_PUSHBULLET} -eq 0 \
1132 - -o ${SENT_KAFKA} -eq 0 \
1133 - -o ${SENT_PD} -eq 0 \
1196 +if [ ${SENT_EMAIL} -eq 0 \
1197 + -o ${SENT_PUSHOVER} -eq 0 \
1198 + -o ${SENT_TELEGRAM} -eq 0 \
1199 + -o ${SENT_SLACK} -eq 0 \
1200 + -o ${SENT_TWILIO} -eq 0 \
1201 + -o ${SENT_MESSAGEBIRD} -eq 0 \
1202 + -o ${SENT_PUSHBULLET} -eq 0 \
1203 + -o ${SENT_KAFKA} -eq 0 \
1204 + -o ${SENT_PD} -eq 0 \
1205 ]
1206 then
1207 # we did send something