Allow PushBullet notifications to be sent to PushBullet channels (#11850)
Co-authored-by: Tina Luedtke <kickoke@users.noreply.github.com> Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>
sourcecodes2 committed
Jan 11, 2022 at 10:43 UTC
237c117da6f250ab37af849e7a430ccad3238097
2 files changed
+30
-17
health/notifications/alarm-notify.sh.in
+17
-6
@@ -1012,10 +1012,21 @@ send_pushover() {
1012
# pushbullet sender
1013
1014
send_pushbullet() {
1015
- local userapikey="${1}" source_device="${2}" recipients="${3}" url="${4}" title="${5}" message="${6}" httpcode sent=0 user
1015
+ local userapikey="${1}" source_device="${2}" recipients="${3}" url="${4}" title="${5}" message="${6}" httpcode sent=0 userOrChannelTag
1016
if [ "${SEND_PUSHBULLET}" = "YES" ] && [ -n "${userapikey}" ] && [ -n "${recipients}" ] && [ -n "${message}" ] && [ -n "${title}" ]; then
1017
- #https://docs.pushbullet.com/#create-push
1018
- for user in ${recipients}; do
1017
+
1018
+ # https://docs.pushbullet.com/#create-push
1019
+ # Accept specification of user(s) (PushBullet account email address) and/or channel tag(s), separated by spaces.
1020
+ # If recipient begins with a "#" then send to channel tag, otherwise send to email recipient.
1021
+
1022
+ for userOrChannelTag in ${recipients}; do
1023
+ if [ "${userOrChannelTag::1}" = "#" ]; then
1024
+ userOrChannelTag_type="channel_tag"
1025
+ userOrChannelTag="${userOrChannelTag:1}" # Remove hash from start of channel tag (required by pushbullet API)
1026
+ else
1027
+ userOrChannelTag_type="email"
1028
+ fi
1029
+
1030
httpcode=$(docurl \
1031
--header 'Access-Token: '${userapikey}'' \
1032
--header 'Content-Type: application/json' \
@@ -1023,7 +1034,7 @@ send_pushbullet() {
1034
cat <<EOF
1035
{"title": "${title}",
1036
"type": "link",
1026
- "email": "${user}",
1037
+ "${userOrChannelTag_type}": "${userOrChannelTag}",
1038
"body": "$(echo -n ${message})",
1039
"url": "${url}",
1040
"source_device_iden": "${source_device}"}
@@ -1031,10 +1042,10 @@ EOF
1042
) "https://api.pushbullet.com/v2/pushes" -X POST)
1043
1044
if [ "${httpcode}" = "200" ]; then
1034
- info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
1045
+ info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${userOrChannelTag}'"
1046
sent=$((sent + 1))
1047
else
1037
- error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP response status code ${httpcode}."
1048
+ error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${userOrChannelTag}' with HTTP response status code ${httpcode}."
1049
fi
1050
done
1051
health/notifications/pushbullet/README.md
+13
-11
@@ -14,20 +14,22 @@ And like this on your Android device:
14
15
You will need:
16
17
-1. Signup and Login to pushbullet.com
18
-2. Get your Access Token, go to <https://www.pushbullet.com/#settings/account> and create a new one
19
-3. Fill in the PUSHBULLET_ACCESS_TOKEN with that value
20
-4. Add the recipient emails to DEFAULT_RECIPIENT_PUSHBULLET
21
- !!PLEASE NOTE THAT IF THE RECIPIENT DOES NOT HAVE A PUSHBULLET ACCOUNT, PUSHBULLET SERVICE WILL SEND AN EMAIL!!
17
+1. Sign up and log in to [pushbullet.com](pushbullet.com)
18
+2. Create a new access token in your [account settings](https://www.pushbullet.com/#settings/account).
19
+3. Fill in the `PUSHBULLET_ACCESS_TOKEN` with the newly generated access token.
20
+4. Add the recipient emails or channel tags (each channel tag must be prefixed with #, e.g. #channeltag) to `DEFAULT_RECIPIENT_PUSHBULLET`.
21
+ > 🚨 The pushbullet notification service will send emails to the email recipient, regardless of if they have a pushbullet account.
22
23
-Set them in `/etc/netdata/health_alarm_notify.conf` (to edit it on your system run `/etc/netdata/edit-config health_alarm_notify.conf`), like this:
23
+To add notification channels, run `/etc/netdata/edit-config health_alarm_notify.conf`
24
+
25
+You can change the configuration like this:
26
27
```
28
###############################################################################
29
# pushbullet (pushbullet.com) push notification options
30
29
-# multiple recipients can be given like this:
30
-# "user1@email.com user2@mail.com"
31
+# multiple recipients (a combination of email addresses or channel tags) can be given like this:
32
+# "user1@email.com user2@mail.com #channel1 #channel2"
33
34
# enable/disable sending pushbullet notifications
35
SEND_PUSHBULLET="YES"
@@ -35,14 +37,14 @@ SEND_PUSHBULLET="YES"
37
# Signup and Login to pushbullet.com
38
# To get your Access Token, go to https://www.pushbullet.com/#settings/account
39
# And create a new access token
38
-# Then just set the recipients emails
39
-# Please note that the if the email in the DEFAULT_RECIPIENT_PUSHBULLET does
40
+# Then just set the recipients emails and/or channel tags (channel tags must be prefixed with #)
41
+# Please note that the if an email in the DEFAULT_RECIPIENT_PUSHBULLET does
42
# not have a pushbullet account, the pushbullet service will send an email
43
# to that address instead
44
45
# Without an access token, Netdata cannot send pushbullet notifications.
46
PUSHBULLET_ACCESS_TOKEN="o.Sometokenhere"
45
-DEFAULT_RECIPIENT_PUSHBULLET="admin1@example.com admin3@somemail.com"
47
+DEFAULT_RECIPIENT_PUSHBULLET="admin1@example.com admin3@somemail.com #examplechanneltag #anotherchanneltag"
48
```
49
50
[](<>)