@cryptotaxi247 / netdata-1 / commits / cb17dd530

Added pushbullet notifications support

Tiago Peralta committed Oct 4, 2016 at 19:57 UTC cb17dd530ef596f4e14b55d81b05a5348599d650
2 files changed +101 -3
conf.d/health_alarm_notify.conf
+28 -1
@@ -112,6 +112,24 @@ PUSHOVER_APP_TOKEN=""
112 DEFAULT_RECIPIENT_PUSHOVER=""
113
114
115 +###############################################################################
116 +
117 +###############################################################################
118 +# pushbullet (pushbullet.com) push notification options
119 +
120 +# multiple recipients can be given like this:
121 +# "USERTOKEN1 USERTOKEN2 ..."
122 +
123 +# enable/disable sending pushover notifications
124 +SEND_PUSHBULLET="YES"
125 +
126 +# Login to pushover.net to get your pushover app token.
127 +# You need only one for all your netdata servers (or you can have one for
128 +# each of your netdata - your call).
129 +# Without an app token, netdata cannot send pushover notifications.
130 +
131 +DEFAULT_RECIPIENT_PUSHBULLET=""
132 +
133 ###############################################################################
134 # telegram (telegram.org) global notification options
135
@@ -165,6 +183,8 @@ role_recipients_email[sysadmin]="${DEFAULT_RECIPIENT_EMAIL}"
183
184 role_recipients_pushover[sysadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
185
186 +role_recipients_pushover[sysadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
187 +
188 role_recipients_telegram[sysadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
189
190 role_recipients_slack[sysadmin]="${DEFAULT_RECIPIENT_SLACK}"
@@ -177,6 +197,8 @@ role_recipients_email[domainadmin]="${DEFAULT_RECIPIENT_EMAIL}"
197
198 role_recipients_pushover[domainadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
199
200 +role_recipients_pushover[domainadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
201 +
202 role_recipients_telegram[domainadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
203
204 role_recipients_slack[domainadmin]="${DEFAULT_RECIPIENT_SLACK}"
@@ -190,6 +212,8 @@ role_recipients_email[dba]="${DEFAULT_RECIPIENT_EMAIL}"
212
213 role_recipients_pushover[dba]="${DEFAULT_RECIPIENT_PUSHOVER}"
214
215 +role_recipients_pushover[dba]="${DEFAULT_RECIPIENT_PUSHBULLET}"
216 +
217 role_recipients_telegram[dba]="${DEFAULT_RECIPIENT_TELEGRAM}"
218
219 role_recipients_slack[dba]="${DEFAULT_RECIPIENT_SLACK}"
@@ -203,6 +227,8 @@ role_recipients_email[webmaster]="${DEFAULT_RECIPIENT_EMAIL}"
227
228 role_recipients_pushover[webmaster]="${DEFAULT_RECIPIENT_PUSHOVER}"
229
230 +role_recipients_pushover[webmaster]="${DEFAULT_RECIPIENT_PUSHBULLET}"
231 +
232 role_recipients_telegram[webmaster]="${DEFAULT_RECIPIENT_TELEGRAM}"
233
234 role_recipients_slack[webmaster]="${DEFAULT_RECIPIENT_SLACK}"
@@ -216,7 +242,8 @@ role_recipients_email[proxyadmin]="${DEFAULT_RECIPIENT_EMAIL}"
242
243 role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
244
245 +role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
246 +
247 role_recipients_telegram[proxyadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
248
249 role_recipients_slack[proxyadmin]="${DEFAULT_RECIPIENT_SLACK}"
222 -
plugins.d/alarm-notify.sh
+73 -2
@@ -92,6 +92,7 @@ SEND_SLACK="YES"
92 SEND_PUSHOVER="YES"
93 SEND_TELEGRAM="YES"
94 SEND_EMAIL="YES"
95 +SEND_PUSHBULLET="YES"
96
97 # slack configs
98 SLACK_WEBHOOK_URL=
@@ -103,6 +104,10 @@ PUSHOVER_APP_TOKEN=
104 DEFAULT_RECIPIENT_PUSHOVER=
105 declare -A role_recipients_pushover=()
106
107 +# pushbullet configs
108 +DEFAULT_RECIPIENT_PUSHBULLET=
109 +declare -A role_recipients_pushbullet=()
110 +
111 # telegram configs
112 TELEGRAM_BOT_TOKEN=
113 DEFAULT_RECIPIENT_TELEGRAM=
@@ -164,6 +169,7 @@ filter_recipient_by_criticality() {
169
170 declare -A arr_slack=()
171 declare -A arr_pushover=()
172 +declare -A arr_pushbullet=()
173 declare -A arr_telegram=()
174 declare -A arr_email=()
175
@@ -191,6 +197,14 @@ do
197 [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushover "${r}" && arr_pushover[${r/|*/}]="1"
198 done
199
200 + # pushover
201 + a="${role_recipients_pushbullet[${x}]}"
202 + [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHBULLET}"
203 + for r in ${a//,/ }
204 + do
205 + [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushbullet "${r}" && arr_pushbullet[${r/|*/}]="1"
206 + done
207 +
208 # telegram
209 a="${role_recipients_telegram[${x}]}"
210 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
@@ -216,6 +230,10 @@ to_slack="${!arr_slack[*]}"
230 to_pushover="${!arr_pushover[*]}"
231 [ -z "${to_pushover}" ] && SEND_PUSHOVER="NO"
232
233 +# build the list of pushbulet recipients (user tokens)
234 +to_pushbullet="${!arr_pushbullet[*]}"
235 +[ -z "${to_pushbullet}" ] && SEND_PUSHBULLET="NO"
236 +
237 # check array of telegram recipients (chat ids)
238 to_telegram="${!arr_telegram[*]}"
239 [ -z "${to_telegram}" ] && SEND_TELEGRAM="NO"
@@ -239,15 +257,19 @@ done
257 # check pushover
258 [ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO"
259
260 +# check pushbullet
261 +[ -z "${DEFAULT_RECIPIENT_PUSHBULLET}" ] && SEND_PUSHBULLET="NO"
262 +
263 # check telegram
264 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
265
245 -if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TELEGRAM}" = "YES" \) -a -z "${curl}" ]
266 +if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TELEGRAM}" = "YES" -o "${SEND_PUSHBULLET}" = "YES" \) -a -z "${curl}" ]
267 then
268 curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
269 if [ -z "${curl}" ]
270 then
271 SEND_PUSHOVER="NO"
272 + SEND_PUSHBULLET="NO"
273 SEND_TELEGRAM="NO"
274 SEND_SLACK="NO"
275 fi
@@ -260,7 +282,7 @@ if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
282 fi
283
284 # check that we have at least a method enabled
263 -if [ "${SEND_EMAIL}" != "YES" -a "${SEND_PUSHOVER}" != "YES" -a "${SEND_TELEGRAM}" != "YES" -a "${SEND_SLACK}" != "YES" ]
285 +if [ "${SEND_EMAIL}" != "YES" -a "${SEND_PUSHOVER}" != "YES" -a "${SEND_TELEGRAM}" != "YES" -a "${SEND_SLACK}" != "YES" -a "${SEND_PUSHBULLET}" != "YES" ]
286 then
287 echo >&2 "All notification methods are disabled. Not sending a notification."
288 exit 1
@@ -430,6 +452,40 @@ send_pushover() {
452 return 1
453 }
454
455 +# -----------------------------------------------------------------------------
456 +# pushbullet sender
457 +
458 +send_pushbullet() {
459 + local userapikeys="${1}" message="${2}" title="${3}" httpcode sent=0 user priority
460 +
461 + if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikeys}" -a ! -z "${message}" -a ! -z "${title}" ]
462 + then
463 + #https://docs.pushbullet.com/#create-push priority=-2
464 + for user in ${userapikeys}
465 + do
466 + httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
467 + -u ""$user"": \
468 + -d type="note" \
469 + --data-urlencode body="${message}" \
470 + --data-urlencode title="${title}" \
471 + "https://api.pushbullet.com/v2/pushes"
472 + )
473 + if [ "${httpcode}" == "200" ]
474 + then
475 + echo >&2 "${me}: Sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
476 + sent=$((sent + 1))
477 + else
478 + echo >&2 "${me}: Failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
479 + fi
480 + done
481 +
482 + [ ${sent} -gt 0 ] && return 0
483 + fi
484 +
485 + return 1
486 +}
487 +
488 +
489
490 # -----------------------------------------------------------------------------
491 # telegram sender
@@ -647,6 +703,21 @@ send_pushover "${PUSHOVER_APP_TOKEN}" "${to_pushover}" "${when}" "${goto_url}" "
703
704 SENT_PUSHOVER=$?
705
706 +# -----------------------------------------------------------------------------
707 +# send the pushbullet notification
708 +
709 +pushbullet_message="
710 +${alarm}
711 +Severity: ${severity}
712 +Chart: ${chart}
713 +Family: ${family}
714 +To view NetData: ${goto_url}
715 +The source of this alarm is line ${src}"
716 +pushbullet_title="${status} at ${host} ${status_message} - ${name//_/ } - ${chart}}"
717 +send_pushbullet "${DEFAULT_RECIPIENT_PUSHBULLET}" "$pushbullet_message" "$pushbullet_title"
718 +
719 +SENT_PUSHBULLET=$?
720 +
721 # -----------------------------------------------------------------------------
722 # send the telegram.org message
723