fix for alarms with multiple roles; more comments; fixed typos
Costa Tsaousis (ktsaou) committed
Sep 28, 2016 at 23:31 UTC
1d4eab937f2caf51efae1fd0e2b9ce613e9747e0
2 files changed
+42
-27
conf.d/health_alarm_notify.conf
+15
-2
@@ -18,14 +18,26 @@
18
###############################################################################
19
# proxy configuration
20
#
21
-# if you need to send curl based notifications (pushover, slack, telegram)
21
+# If you need to send curl based notifications (pushover, slack, telegram)
22
# 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
26
27
###############################################################################
28
-# external commands needed
28
+# notifications images
29
+#
30
+# Images in notifications need to be downloaded from an Internet facing site.
31
+# To allow notification providers fetch the icons/images, by default we set
32
+# the URL of the global public netdata registry.
33
+# If you have an Internet facing netdata (or you have copied the images/ folder
34
+# of netdata to your web server), set its URL here, to fetch the notification
35
+# images from it.
36
+#images_base_url="http://my.public.netdata.server:19999"
37
+
38
+
39
+###############################################################################
40
+# external commands
41
42
# The full path to the sendmail command.
43
# If empty, the system $PATH will be searched for it.
@@ -207,3 +219,4 @@ role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
219
role_recipients_telegram[proxyadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
220
221
role_recipients_slack[proxyadmin]="${DEFAULT_RECIPIENT_SLACK}"
222
+
plugins.d/alarm-notify.sh
+27
-25
@@ -26,22 +26,22 @@ NETDATA_CACHE_DIR="${NETDATA_CACHE_DIR-/var/cache/netdata}"
26
# -----------------------------------------------------------------------------
27
# parse command line parameters
28
29
-recipient="${1}" # the recepient of the email
30
-host="${2}" # the host this event refers to
29
+roles="${1}" # the roles that should be notified for this event
30
+host="${2}" # the host generated this event
31
unique_id="${3}" # the unique id of this event
32
alarm_id="${4}" # the unique id of the alarm that generated this event
33
-event_id="${5}" # the incremental id of the event, for this alarm
34
-when="${6}" # the timestamp this event occured
33
+event_id="${5}" # the incremental id of the event, for this alarm id
34
+when="${6}" # the timestamp this event occurred
35
name="${7}" # the name of the alarm, as given in netdata health.d entries
36
chart="${8}" # the name of the chart (type.id)
37
family="${9}" # the family of the chart
38
status="${10}" # the current status : REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
39
old_status="${11}" # the previous status: REMOVED, UNITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
40
-value="${12}" # the current value
41
-old_value="${13}" # the previous value
40
+value="${12}" # the current value of the alarm
41
+old_value="${13}" # the previous value of the alarm
42
src="${14}" # the line number and file the alarm has been configured
43
-duration="${15}" # the duration in seconds the previous state took
44
-non_clear_duration="${16}" # the total duration in seconds this is non-clear
43
+duration="${15}" # the duration in seconds of the previous alarm state
44
+non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
45
units="${17}" # the units of the value
46
info="${18}" # a short description of the alarm
47
@@ -65,9 +65,10 @@ fi
65
# -----------------------------------------------------------------------------
66
# load configuration
67
68
-# this is defined here so that private registries
69
-# can setup their own
70
-# images_base_url="${NETDATA_REGISTRY_URL}"
68
+# By default fetch images from the global public registry.
69
+# This is required by default, since all notification methods need to download
70
+# images via the Internet, and private registries might not be reachable.
71
+# This can be overwritten at the configuration file.
72
images_base_url="https://registry.my-netdata.io"
73
74
# needed commands
@@ -108,14 +109,14 @@ if [ -f "${NETDATA_CONFIG_DIR}/health_alarm_notify.conf" ]
109
fi
110
111
# -----------------------------------------------------------------------------
111
-# filter recipients based on the criticality of each
112
+# filter a recipient based on alarm event severity
113
114
filter_recipient_by_criticality() {
115
local method="${1}" x="${2}" r s
116
shift
117
117
- r="${x/|*/}"
118
- s="${x/*|/}"
118
+ r="${x/|*/}" # the recipient
119
+ s="${x/*|/}" # the severity required for notifying this recipient
120
121
# no severity filtering for this person
122
[ "${r}" = "${s}" ] && return 0
@@ -148,22 +149,23 @@ filter_recipient_by_criticality() {
149
}
150
151
# -----------------------------------------------------------------------------
151
-# find the recipient's addresses per method
152
+# find the recipients' addresses per method
153
154
declare -A arr_slack=()
155
declare -A arr_pushover=()
156
declare -A arr_telegram=()
157
declare -A arr_email=()
158
158
-# netdata may call us with multiple recipients
159
-# so, here we find the unique ones
160
-for x in ${recipient//,/ }
159
+# netdata may call us with multiple roles, and roles may have multiple but
160
+# overlapping recipients - so, here we find the unique recipients.
161
+for x in ${roles//,/ }
162
do
162
- # the recipient 'silent' means, don't send a notification for this event
163
- [ "${x}" = "silent" ] && continue
163
+ # the roles 'silent' and 'disabled' mean:
164
+ # don't send a notification for this role
165
+ [ "${x}" = "silent" -o "${x}" = "disabled" ] && continue
166
167
# email
166
- a="${role_recipients_email[${recipient}]}"
168
+ a="${role_recipients_email[${x}]}"
169
[ -z "${a}" ] && a="${DEFAULT_RECIPIENT_EMAIL}"
170
for r in ${a//,/ }
171
do
@@ -171,7 +173,7 @@ do
173
done
174
175
# pushover
174
- a="${role_recipients_pushover[${recipient}]}"
176
+ a="${role_recipients_pushover[${x}]}"
177
[ -z "${a}" ] && a="${DEFAULT_RECIPIENT_PUSHOVER}"
178
for r in ${a//,/ }
179
do
@@ -179,7 +181,7 @@ do
181
done
182
183
# telegram
182
- a="${role_recipients_telegram[${recipient}]}"
184
+ a="${role_recipients_telegram[${x}]}"
185
[ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TELEGRAM}"
186
for r in ${a//,/ }
187
do
@@ -187,7 +189,7 @@ do
189
done
190
191
# slack
190
- a="${role_recipients_slack[${recipient}]}"
192
+ a="${role_recipients_slack[${x}]}"
193
[ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SLACK}"
194
for r in ${a//,/ }
195
do
@@ -747,7 +749,7 @@ SENT_EMAIL=$?
749
# -----------------------------------------------------------------------------
750
# let netdata know
751
750
-# we did send somehting
752
+# we did send something
753
[ ${SENT_EMAIL} -eq 0 -o ${SENT_PUSHOVER} -eq 0 -o ${SENT_TELEGRAM} -eq 0 -o ${SENT_SLACK} -eq 0 ] && exit 0
754
755
# we did not send anything