alarm-test script rewritten - fixes #943; pushbullet notifications follow the format of the others; minor other improvements
Costa Tsaousis (ktsaou) committed
Oct 23, 2016 at 23:07 UTC
072e244f93439abf6e0d0ef109e606bec42350c0
4 files changed
+55
-22
conf.d/health_alarm_notify.conf
+6
-7
@@ -18,8 +18,8 @@
18
###############################################################################
19
# proxy configuration
20
#
21
-# If you need to send curl based notifications (pushover, slack, telegram)
22
-# via a proxy, set these to your proxy address:
21
+# If you need to send curl based notifications (pushover, pushbullet, slack,
22
+# telegram) via a proxy, set these to your proxy address:
23
#export http_proxy="http://10.0.0.1:3128/"
24
#export https_proxy="http://10.0.0.1:3128/"
25
@@ -112,8 +112,6 @@ PUSHOVER_APP_TOKEN=""
112
DEFAULT_RECIPIENT_PUSHOVER=""
113
114
115
-###############################################################################
116
-
115
###############################################################################
116
# pushbullet (pushbullet.com) push notification options
117
@@ -125,16 +123,17 @@ SEND_PUSHBULLET="YES"
123
124
# Signup and Login to pushbullet.com
125
# To get your Access Token, go to https://www.pushbullet.com/#settings/account
128
-# And create a new access token
129
-# Then just set the recipients emails
126
+# Create a new access token and paste it below.
127
+# Then just set the recipients' emails.
128
# Please note that the if the email in the DEFAULT_RECIPIENT_PUSHBULLET does
129
# not have a pushbullet account, the pushbullet service will send an email
132
-# to that address instead
130
+# to that address instead.
131
132
# Without an access token, netdata cannot send pushbullet notifications.
133
PUSHBULLET_ACCESS_TOKEN=""
134
DEFAULT_RECIPIENT_PUSHBULLET=""
135
136
+
137
###############################################################################
138
# telegram (telegram.org) global notification options
139
plugins.d/alarm-notify.sh
+35
-13
@@ -15,12 +15,36 @@
15
#
16
# Supported notification methods:
17
# - emails
18
-# - pushover.net notifications
19
-# - pushbullet.com push notifications
18
# - slack.com notifications
21
-# - telegram.org notifications
19
+# - pushover.net notifications
20
+# - pushbullet.com push notifications by Tiago Peralta @tperalta82 PR #1070
21
+# - telegram.org notifications by @hashworks PR #1002
22
#
23
24
+# -----------------------------------------------------------------------------
25
+# testing notifications
26
+
27
+if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
28
+then
29
+ if [ "${2}" = "test" ]
30
+ then
31
+ recipient="${1}"
32
+ else
33
+ recipient="${2}"
34
+ fi
35
+
36
+ [ -z "${recipient}" ] && recipient="sysadmin"
37
+
38
+ echo >&2 ">> SENDING TEST ALARM TO ROLE: ${recipient} <<"
39
+
40
+ "${0}" "${recipient}" 'test' '1' '1' '1' '1' 'test_alarm' 'test_alarm' 'test' 'CRITICAL' 'CLEAR' '1' '1' "${0}" '1' '1' 'number' 'test alarm to verify notifications work'
41
+ ret=$?
42
+
43
+ [ ${ret} -ne 0 ] && echo >&2 ">> FAILED <<" && exit ${ret}
44
+ echo >&2 ">> OK <<"
45
+ exit $?
46
+fi
47
+
48
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
49
export LC_ALL=C
50
@@ -499,7 +523,7 @@ send_pushover() {
523
# pushbullet sender
524
525
send_pushbullet() {
502
- local userapikey="${1}" recipients="${2}" message="${3}" title="${4}" httpcode sent=0 user
526
+ local userapikey="${1}" recipients="${2}" title="${3}" message="${4}" httpcode sent=0 user
527
if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikey}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
528
then
529
#https://docs.pushbullet.com/#create-push
@@ -518,10 +542,10 @@ EOF
542
543
if [ "${httpcode}" == "200" ]
544
then
521
- echo >&2 "${me}: Sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
545
+ info "sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
546
sent=$((sent + 1))
547
else
524
- echo >&2 "${me}: Failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
548
+ error "failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
549
fi
550
done
551
@@ -750,14 +774,12 @@ SENT_PUSHOVER=$?
774
# -----------------------------------------------------------------------------
775
# send the pushbullet notification
776
753
-pushbullet_message="${alarm} \n
754
-Severity: ${severity} \n
755
-Chart: ${chart} \n
756
-Family: ${family} \n
757
-To View Netdata go to: ${goto_url} \n
777
+send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${to_pushbullet}" "${host} ${status_message} - ${name//_/ } - ${chart}" "${alarm}\n
778
+Severity: ${severity}\n
779
+Chart: ${chart}\n
780
+Family: ${family}\n
781
+To View Netdata go to: ${goto_url}\n
782
The source of this alarm is line ${src}"
759
-pushbullet_title="${status} at ${host} ${status_message} - ${name//_/ } - ${chart}}"
760
-send_pushbullet "${PUSHBULLET_ACCESS_TOKEN}" "${to_pushbullet}" "$pushbullet_message" "$pushbullet_title"
783
784
SENT_PUSHBULLET=$?
785
plugins.d/alarm-test.sh
+11
-2
@@ -1,3 +1,12 @@
1
#!/usr/bin/env bash
2
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3
-$($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'})
2
+
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+# Script to test alarm notifications for netdata
9
+
10
+dir="$(dirname "${0}")"
11
+${dir}/alarm-notify.sh test "${1}"
12
+exit $?
src/common.h
+3
@@ -64,7 +64,10 @@
64
#include <time.h>
65
#include <unistd.h>
66
#include <uuid/uuid.h>
67
+
68
+/*
69
#include <mntent.h>
70
+*/
71
72
#ifdef STORAGE_WITH_MATH
73
#include <math.h>