]> arthur.barton.de Git - netdata.git/commitdiff
Modified the code to be compliant with latest pushbullet API
authorTiago Peralta <tperalta82@gmail.com>
Sat, 8 Oct 2016 03:24:59 +0000 (04:24 +0100)
committerTiago Peralta <tperalta82@gmail.com>
Sat, 8 Oct 2016 03:24:59 +0000 (04:24 +0100)
Added proper line breaks to the pushbullet message
Fixed a typo in the configuration file
Added a script to test alarms

conf.d/health_alarm_notify.conf
plugins.d/Makefile.am
plugins.d/alarm-notify.sh
plugins.d/alarm-test.sh [new file with mode: 0644]

index fba36e85dc2683c5c8e48524657157dcf2504f91..d7209ed77e8912b13174cf9731b38f018c022ff1 100644 (file)
@@ -132,7 +132,7 @@ SEND_PUSHBULLET="YES"
 # to that address instead
 
 # Without an access token, netdata cannot send pushbullet notifications.
-PUSBULLET_ACCESS_TOKEN=""
+PUSHBULLET_ACCESS_TOKEN=""
 DEFAULT_RECIPIENT_PUSHBULLET=""
 
 ###############################################################################
index 4bc0dc4471fe290794c421527ae4f6da8069853c..cba137d7fb9f3d762db78fadb1a76877e09867a7 100644 (file)
@@ -10,6 +10,7 @@ dist_plugins_DATA = \
 dist_plugins_SCRIPTS = \
        alarm-email.sh \
        alarm-notify.sh \
+       alarm-test.sh \
        cgroup-name.sh \
        charts.d.dryrun-helper.sh \
        charts.d.plugin \
index 126c745bb9cf5c88fc2f59fcb95680fb7386783b..ac9b29336e2bb2c4b40454e8790d65e31ebb5ffc 100755 (executable)
@@ -459,20 +459,21 @@ send_pushover() {
 
 send_pushbullet() {
     local userapikey="${1}" recipients="${2}" message="${3}" title="${4}" httpcode sent=0 user
-
     if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikey}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
         then
         #https://docs.pushbullet.com/#create-push
         for user in ${recipients}
         do
             httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
-                 -u "$userapikey": \
-                 -d type="note" \
-                 --data-urlencode email="${user}" \
-                 --data-urlencode body="${message}" \
-                 --data-urlencode title="${title}" \
-                 "https://api.pushbullet.com/v2/pushes"
-                )
+              --header 'Access-Token: '$userapikey'' \
+              --header 'Content-Type: application/json' \
+              --data-binary  @<(cat <<EOF
+                              {"title": "${title}",
+                              "type": "note",
+                              "email": "${user}",
+                              "body": "$( echo -n ${message})"}
+EOF
+               ) "https://api.pushbullet.com/v2/pushes" -X POST)
 
             if [ "${httpcode}" == "200" ]
             then
@@ -489,8 +490,6 @@ send_pushbullet() {
     return 1
 }
 
-
-
 # -----------------------------------------------------------------------------
 # telegram sender
 
@@ -710,12 +709,11 @@ SENT_PUSHOVER=$?
 # -----------------------------------------------------------------------------
 # send the pushbullet notification
 
-pushbullet_message="
-${alarm}
-Severity: ${severity}
-Chart: ${chart}
-Family: ${family}
-To View Netdata go to: ${goto_url}
+pushbullet_message="${alarm} \n
+Severity: ${severity} \n
+Chart: ${chart} \n
+Family: ${family} \n
+To View Netdata go to: ${goto_url} \n
 The source of this alarm is line ${src}"
 pushbullet_title="${status} at ${host} ${status_message} - ${name//_/ } - ${chart}}"
 send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${to_pushbullet}" "$pushbullet_message" "$pushbullet_title"
diff --git a/plugins.d/alarm-test.sh b/plugins.d/alarm-test.sh
new file mode 100644 (file)
index 0000000..b97155d
--- /dev/null
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+$($DIR/alarm-notify.sh 'sysadmin' 'DummyAlarm' '1475604061' '1475604028' '3' '1475604369' '10min_cpu_usage' 'system.cpu' 'cpu' 'WARNING' 'CLEAR' '83' '80' '2@/etc/netdata/health.d/cpu.conf' '360' '0' '%' 'average cpu utilization for the last 45 minutes'})