alarm-notify.sh configuration; alarm-notify.sh support multiple recipients per alarm for pushover
Costa Tsaousis (ktsaou) committed
Sep 9, 2016 at 00:57 UTC
6ed420f3b3bedf9156946d182afc0d0d54139eb7
2 files changed
+82
-32
conf.d/health_alarm_notify.conf
+61
-15
@@ -2,52 +2,98 @@
2
3
# netdata alarms have been categorized to allow different roles to receive
4
# alarms related to their work.
5
+#
6
+# This file defines the addresses for each role.
7
+# This file is a BASH script itself.
8
6
-# this file defines the email addresses for each role. if a role is not
7
-# defined, the email will be sent to root.
9
+###############################################################################
10
+# external commands needed
11
+
12
+# The full path to the sendmail command.
13
+# If empty, the system $PATH will be searched for it.
14
+sendmail=
15
+
16
+# The full path of the curl command.
17
+# If empty, the system $PATH will be searched for it.
18
+curl=
19
+
20
+
21
+###############################################################################
22
+# sending emails
23
+
24
+# note: multiple recipients can be given like this:
25
+# "admin1@example.com, admin2@example.com, ..."
26
+# note it needs a comma!
27
+
28
+# enable/disable sending emails
29
+SEND_EMAIL="YES"
30
+
31
+# if a role recipient is not configured, an email will be send to
32
+DEFAULT_RECIPIENT_EMAIL="root"
33
9
-# you can set multiple addresses for each role, like this:
10
-#
11
-# recipients[sysadmin]="admin1@example.com, admin2@example.com"
12
-#
13
-# it is important to add the comma between email addresses.
34
15
-# This configuration file is a BASH script itself. The 'recipients' variable is
16
-# an associative array. So you can use other variables too, like this one:
35
+###############################################################################
36
+# sending pushover notifications (pushover.com)
37
18
-default_recipient_for_all_roles="root"
38
+# note: multiple recipients can be given like this:
39
+# "USERTOKEN1 USERTOKEN2 USERTOKEN3 ..."
40
41
+# enable/disable sending pushover notifications
42
+SEND_PUSHOVER="YES"
43
+
44
+# Login to pushover.com to get your pushover app token
45
+# You need only one for all your netdata servers.
46
+# Without it, netdata cannot send pushover notifications.
47
+PUSHOVER_APP_TOKEN=
48
+
49
+# if a role recipient is not configured, a notification will be send to
50
+# this pushover user token
51
+DEFAULT_RECIPIENT_PUSHOVER=
52
+
53
+
54
+###############################################################################
55
+# RECIPIENTS PER ROLE
56
57
# -----------------------------------------------------------------------------
58
# generic system alarms
59
# CPU, disks, entropy, etc
60
25
-recipients[sysadmin]="${default_recipient_for_all_roles}"
61
+role_recipients_email[sysadmin]="${DEFAULT_RECIPIENT_EMAIL}"
62
+
63
+role_recipients_pushover[sysadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
64
65
66
# -----------------------------------------------------------------------------
67
# DNS related alarms
68
31
-recipients[domainadmin]="${default_recipient_for_all_roles}"
69
+role_recipients_email[domainadmin]="${DEFAULT_RECIPIENT_EMAIL}"
70
+
71
+role_recipients_pushover[domainadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
72
73
74
# -----------------------------------------------------------------------------
75
# database servers alarms
76
# mysql, redis, memcached, etc
77
38
-recipients[dba]="${default_recipient_for_all_roles}"
78
+role_recipients_email[dba]="${DEFAULT_RECIPIENT_EMAIL}"
79
+
80
+role_recipients_pushover[dba]="${DEFAULT_RECIPIENT_PUSHOVER}"
81
82
83
# -----------------------------------------------------------------------------
84
# web servers alarms
85
# apache, nginx, etc
86
45
-recipients[webmaster]="${default_recipient_for_all_roles}"
87
+role_recipients_email[webmaster]="${DEFAULT_RECIPIENT_EMAIL}"
88
+
89
+role_recipients_pushover[webmaster]="${DEFAULT_RECIPIENT_PUSHOVER}"
90
91
92
# -----------------------------------------------------------------------------
93
# proxy servers alarms
94
# apache, nginx, etc
95
52
-recipients[proxyadmin]="${default_recipient_for_all_roles}"
96
+role_recipients_email[proxyadmin]="${DEFAULT_RECIPIENT_EMAIL}"
97
+
98
+role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
99
plugins.d/alarm-notify.sh
+21
-17
@@ -195,27 +195,31 @@ send_email() {
195
# pushover sender
196
197
send_pushover() {
198
- local apptoken="${1}" usertoken="${2}" title="${3}" message="${4}" httpcode
198
+ local apptoken="${1}" usertoken="${2}" title="${3}" message="${4}" httpcode sent=0 user
199
200
if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertoken}" -a ! -z "${title}" -a ! -z "${message}" ]
201
then
202
203
- httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
204
- --form-string "token=${apptoken}" \
205
- --form-string "user=${usertoken}" \
206
- --form-string "html=1" \
207
- --form-string "title=${title}" \
208
- --form-string "message=${message}" \
209
- https://api.pushover.net/1/messages.json)
210
-
211
- if [ "${httpcode}" == "200" ]
212
- then
213
- echo >&2 "${me}: Sent notification push for ${status} on '${chart}.${name}'"
214
- return 0
215
- else
216
- echo >&2 "${me}: FAILED to send notification push for ${status} on '${chart}.${name}' with HTTP error code ${httpcode}."
217
- return 1
218
- fi
203
+ for user in ${usertoken//,/ }
204
+ do
205
+ httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
206
+ --form-string "token=${apptoken}" \
207
+ --form-string "user=${user}" \
208
+ --form-string "html=1" \
209
+ --form-string "title=${title}" \
210
+ --form-string "message=${message}" \
211
+ https://api.pushover.net/1/messages.json)
212
+
213
+ if [ "${httpcode}" == "200" ]
214
+ then
215
+ echo >&2 "${me}: Sent notification push for ${status} on '${chart}.${name}' to '${user}'"
216
+ sent=$((sent + 1))
217
+ else
218
+ echo >&2 "${me}: FAILED to send notification push for ${status} on '${chart}.${name}' to '${user}' with HTTP error code ${httpcode}."
219
+ fi
220
+ done
221
+
222
+ [ ${sent} -gt 0 ] && return 0
223
fi
224
225
return 1