]> arthur.barton.de Git - netdata.git/commitdiff
Added pushbullet notifications support
authorTiago Peralta <tiago.peralta@frk-agency.com>
Tue, 4 Oct 2016 18:57:54 +0000 (19:57 +0100)
committerTiago Peralta <tiago.peralta@frk-agency.com>
Tue, 4 Oct 2016 18:57:54 +0000 (19:57 +0100)
conf.d/health_alarm_notify.conf
plugins.d/alarm-notify.sh

index d451cafedcf15919de29ed5a620b496c94611b6e..3ed5e5199e58abbf675be5e705ff4183d4ddd524 100644 (file)
@@ -112,6 +112,24 @@ PUSHOVER_APP_TOKEN=""
 DEFAULT_RECIPIENT_PUSHOVER=""
 
 
+###############################################################################
+
+###############################################################################
+# pushbullet (pushbullet.com) push notification options
+
+# multiple recipients can be given like this:
+#                  "USERTOKEN1 USERTOKEN2 ..."
+
+# enable/disable sending pushover notifications
+SEND_PUSHBULLET="YES"
+
+# Login to pushover.net to get your pushover app token.
+# You need only one for all your netdata servers (or you can have one for
+# each of your netdata - your call).
+# Without an app token, netdata cannot send pushover notifications.
+
+DEFAULT_RECIPIENT_PUSHBULLET=""
+
 ###############################################################################
 # telegram (telegram.org) global notification options
 
@@ -165,6 +183,8 @@ role_recipients_email[sysadmin]="${DEFAULT_RECIPIENT_EMAIL}"
 
 role_recipients_pushover[sysadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
+role_recipients_pushover[sysadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
+
 role_recipients_telegram[sysadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
 
 role_recipients_slack[sysadmin]="${DEFAULT_RECIPIENT_SLACK}"
@@ -177,6 +197,8 @@ role_recipients_email[domainadmin]="${DEFAULT_RECIPIENT_EMAIL}"
 
 role_recipients_pushover[domainadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
+role_recipients_pushover[domainadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
+
 role_recipients_telegram[domainadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
 
 role_recipients_slack[domainadmin]="${DEFAULT_RECIPIENT_SLACK}"
@@ -190,6 +212,8 @@ role_recipients_email[dba]="${DEFAULT_RECIPIENT_EMAIL}"
 
 role_recipients_pushover[dba]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
+role_recipients_pushover[dba]="${DEFAULT_RECIPIENT_PUSHBULLET}"
+
 role_recipients_telegram[dba]="${DEFAULT_RECIPIENT_TELEGRAM}"
 
 role_recipients_slack[dba]="${DEFAULT_RECIPIENT_SLACK}"
@@ -203,6 +227,8 @@ role_recipients_email[webmaster]="${DEFAULT_RECIPIENT_EMAIL}"
 
 role_recipients_pushover[webmaster]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
+role_recipients_pushover[webmaster]="${DEFAULT_RECIPIENT_PUSHBULLET}"
+
 role_recipients_telegram[webmaster]="${DEFAULT_RECIPIENT_TELEGRAM}"
 
 role_recipients_slack[webmaster]="${DEFAULT_RECIPIENT_SLACK}"
@@ -216,7 +242,8 @@ role_recipients_email[proxyadmin]="${DEFAULT_RECIPIENT_EMAIL}"
 
 role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
+role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
+
 role_recipients_telegram[proxyadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
 
 role_recipients_slack[proxyadmin]="${DEFAULT_RECIPIENT_SLACK}"
-
index feec6ceae0718a116ccdcb3781161838f26441ad..b836eaedecc76d85aec7995cb2aa8f71951267fc 100755 (executable)
@@ -92,6 +92,7 @@ SEND_SLACK="YES"
 SEND_PUSHOVER="YES"
 SEND_TELEGRAM="YES"
 SEND_EMAIL="YES"
+SEND_PUSHBULLET="YES"
 
 # slack configs
 SLACK_WEBHOOK_URL=
@@ -103,6 +104,10 @@ PUSHOVER_APP_TOKEN=
 DEFAULT_RECIPIENT_PUSHOVER=
 declare -A role_recipients_pushover=()
 
+# pushbullet configs
+DEFAULT_RECIPIENT_PUSHBULLET=
+declare -A role_recipients_pushbullet=()
+
 # telegram configs
 TELEGRAM_BOT_TOKEN=
 DEFAULT_RECIPIENT_TELEGRAM=
@@ -164,6 +169,7 @@ filter_recipient_by_criticality() {
 
 declare -A arr_slack=()
 declare -A arr_pushover=()
+declare -A arr_pushbullet=()
 declare -A arr_telegram=()
 declare -A arr_email=()
 
@@ -191,6 +197,14 @@ do
         [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushover "${r}" && arr_pushover[${r/|*/}]="1"
     done
 
+    # pushover
+    a="${role_recipients_pushbullet[${x}]}"
+    [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHBULLET}"
+    for r in ${a//,/ }
+    do
+        [ "${r}" != "disabled" ] && filter_recipient_by_criticality pushbullet "${r}" && arr_pushbullet[${r/|*/}]="1"
+    done
+
     # telegram
     a="${role_recipients_telegram[${x}]}"
     [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
@@ -216,6 +230,10 @@ to_slack="${!arr_slack[*]}"
 to_pushover="${!arr_pushover[*]}"
 [ -z "${to_pushover}" ] && SEND_PUSHOVER="NO"
 
+# build the list of pushbulet recipients (user tokens)
+to_pushbullet="${!arr_pushbullet[*]}"
+[ -z "${to_pushbullet}" ] && SEND_PUSHBULLET="NO"
+
 # check array of telegram recipients (chat ids)
 to_telegram="${!arr_telegram[*]}"
 [ -z "${to_telegram}" ] && SEND_TELEGRAM="NO"
@@ -239,15 +257,19 @@ done
 # check pushover
 [ -z "${PUSHOVER_APP_TOKEN}" ] && SEND_PUSHOVER="NO"
 
+# check pushbullet
+[ -z "${DEFAULT_RECIPIENT_PUSHBULLET}" ] && SEND_PUSHBULLET="NO"
+
 # check telegram
 [ -z "${TELEGRAM_BOT_TOKEN}" ] && SEND_TELEGRAM="NO"
 
-if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TELEGRAM}" = "YES" \) -a -z "${curl}" ]
+if [ \( "${SEND_PUSHOVER}" = "YES" -o "${SEND_SLACK}" = "YES" -o "${SEND_TELEGRAM}" = "YES" -o "${SEND_PUSHBULLET}" = "YES" \) -a -z "${curl}" ]
     then
     curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
     if [ -z "${curl}" ]
         then
         SEND_PUSHOVER="NO"
+        SEND_PUSHBULLET="NO"
         SEND_TELEGRAM="NO"
         SEND_SLACK="NO"
     fi
@@ -260,7 +282,7 @@ if [ "${SEND_EMAIL}" = "YES" -a -z "${sendmail}" ]
 fi
 
 # check that we have at least a method enabled
-if [ "${SEND_EMAIL}" != "YES" -a "${SEND_PUSHOVER}" != "YES" -a "${SEND_TELEGRAM}" != "YES" -a "${SEND_SLACK}" != "YES" ]
+if [ "${SEND_EMAIL}" != "YES" -a "${SEND_PUSHOVER}" != "YES" -a "${SEND_TELEGRAM}" != "YES" -a "${SEND_SLACK}" != "YES" -a "${SEND_PUSHBULLET}" != "YES" ]
     then
     echo >&2 "All notification methods are disabled. Not sending a notification."
     exit 1
@@ -430,6 +452,40 @@ send_pushover() {
     return 1
 }
 
+# -----------------------------------------------------------------------------
+# pushbullet sender
+
+send_pushbullet() {
+    local userapikeys="${1}" message="${2}" title="${3}"  httpcode sent=0 user priority
+
+    if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikeys}" -a ! -z "${message}" -a ! -z "${title}" ]
+        then
+        #https://docs.pushbullet.com/#create-push        priority=-2
+        for user in ${userapikeys}
+        do
+            httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
+                 -u ""$user"": \
+                 -d type="note" \
+                 --data-urlencode body="${message}" \
+                 --data-urlencode title="${title}" \
+                 "https://api.pushbullet.com/v2/pushes"
+                )
+            if [ "${httpcode}" == "200" ]
+            then
+                echo >&2 "${me}: Sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
+                sent=$((sent + 1))
+            else
+                echo >&2 "${me}: Failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
+            fi
+        done
+
+        [ ${sent} -gt 0 ] && return 0
+    fi
+
+    return 1
+}
+
+
 
 # -----------------------------------------------------------------------------
 # telegram sender
@@ -647,6 +703,21 @@ send_pushover "${PUSHOVER_APP_TOKEN}" "${to_pushover}" "${when}" "${goto_url}" "
 
 SENT_PUSHOVER=$?
 
+# -----------------------------------------------------------------------------
+# send the pushbullet notification
+
+pushbullet_message="
+${alarm}
+Severity: ${severity}
+Chart: ${chart}
+Family: ${family}
+To view NetData: ${goto_url}
+The source of this alarm is line ${src}"
+pushbullet_title="${status} at ${host} ${status_message} - ${name//_/ } - ${chart}}"
+send_pushbullet "${DEFAULT_RECIPIENT_PUSHBULLET}" "$pushbullet_message" "$pushbullet_title"
+
+SENT_PUSHBULLET=$?
+
 # -----------------------------------------------------------------------------
 # send the telegram.org message