Add sample implementation to custom_sender (#5992)
Chris Akritidis committed
May 13, 2019 at 13:28 UTC
fc74a508be3c28115c46e54b5641722082ea7069
2 files changed
+47
health/notifications/custom/README.md
+30
@@ -5,6 +5,36 @@ To configure custom notifications, you will need to define the `custom_sender()`
5
You can look at the other senders in `/usr/libexec/netdata/plugins.d/alarm-notify.sh` for examples.
6
As with other notifications, you will also need to define the recipient list in `DEFAULT_RECIPIENT_CUSTOM` and/or the `role_recipients_custom` array.
7
8
+The following is a sample `custom_sender` function to send an SMS via an imaginary HTTPS endpoint to the SMS gateway:
9
+```
10
+ custom_sender() {
11
+ # example human readable SMS
12
+ local msg="${host} ${status_message}: ${alarm} ${raised_for}"
13
+
14
+ # limit it to 160 characters and encode it for use in a URL
15
+ urlencode "${msg:0:160}" >/dev/null; msg="${REPLY}"
16
+
17
+ # a space separated list of the recipients to send alarms to
18
+ to="${1}"
19
+
20
+ for phone in ${to}; do
21
+ httpcode=$(docurl -X POST \
22
+ --data-urlencode "From=XXX" \
23
+ --data-urlencode "To=${phone}" \
24
+ --data-urlencode "Body=${msg}" \
25
+ -u "${accountsid}:${accounttoken}" \
26
+ https://domain.website.com/)
27
+
28
+ if [ "${httpcode}" = "200" ]; then
29
+ info "sent custom notification ${msg} to ${phone}"
30
+ sent=$((sent + 1))
31
+ else
32
+ error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}."
33
+ fi
34
+ done
35
+}
36
+```
37
+
38
Variables available to the custom_sender:
39
40
- ${to_custom} the list of recipients for the alarm
health/notifications/health_alarm_notify.conf
+17
@@ -773,6 +773,23 @@ custom_sender() {
773
# a space separated list of the recipients to send alarms to
774
to="${1}"
775
776
+ # Sample send SMS to an imaginary SMS gateway accessible via HTTPS
777
+ #for phone in ${to}; do
778
+ # httpcode=$(docurl -X POST \
779
+ # --data-urlencode "From=XXX" \
780
+ # --data-urlencode "To=${phone}" \
781
+ # --data-urlencode "Body=${msg}" \
782
+ # -u "${accountsid}:${accounttoken}" \
783
+ # https://domain.website.com/)
784
+ #
785
+ # if [ "${httpcode}" = "200" ]; then
786
+ # info "sent custom notification ${msg} to ${phone}"
787
+ # sent=$((sent + 1))
788
+ # else
789
+ # error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}."
790
+ # fi
791
+ #done
792
+
793
info "not sending custom notification to ${to}, for ${status} of '${host}.${chart}.${name}' - custom_sender() is not configured."
794
}
795