master
md 183 lines 5.45 KB
Rendered Raw
1 <!--startmeta
2 custom_edit_url: "https://github.com/netdata/netdata/edit/master/src/health/notifications/custom/README.md"
3 meta_yaml: "https://github.com/netdata/netdata/edit/master/src/health/notifications/custom/metadata.yaml"
4 sidebar_label: "Custom"
5 learn_status: "Published"
6 learn_rel_path: "Alerts & Notifications/Notifications/Agent Dispatched Notifications"
7 keywords: ['custom']
8 message: "DO NOT EDIT THIS FILE DIRECTLY, IT IS GENERATED BY THE NOTIFICATION'S metadata.yaml FILE"
9 endmeta-->
10
11 # Custom
12
13
14 <img src="https://netdata.cloud/img/custom.png" width="150"/>
15
16
17 Netdata Agent's alert notification feature allows you to send custom notifications to any endpoint you choose.
18
19
20 <img src="https://img.shields.io/badge/maintained%20by-Netdata-%2300ab44" />
21
22 ## Setup
23
24
25 ### Prerequisites
26
27 ####
28
29 - Access to the terminal where Netdata Agent is running
30
31
32
33 ### Configuration
34
35 #### Options
36
37 The following options can be defined for this notification
38
39 <details open><summary>Config Options</summary>
40
41
42
43 | Option | Description | Default | Required |
44 |:-----|:------------|:--------|:---------:|
45 | SEND_CUSTOM | Set `SEND_CUSTOM` to YES | YES | yes |
46 | [DEFAULT_RECIPIENT_CUSTOM](#option-default-recipient-custom) | This value is dependent on how you handle the `${to}` variable inside the `custom_sender()` function. | | yes |
47 | [custom_sender()](#option-custom-sender) | You can look at the other senders in `/usr/libexec/netdata/plugins.d/alarm-notify.sh` for examples of how to modify the function in this configuration file. | | no |
48
49 <a id="option-default-recipient-custom"></a>
50 ##### DEFAULT_RECIPIENT_CUSTOM
51
52 All roles will default to this variable if left unconfigured. You can edit `DEFAULT_RECIPIENT_CUSTOM` with the variable you want, in the following entries at the bottom of the same file:
53 ```
54 role_recipients_custom[sysadmin]="systems"
55 role_recipients_custom[domainadmin]="domains"
56 role_recipients_custom[dba]="databases systems"
57 role_recipients_custom[webmaster]="marketing development"
58 role_recipients_custom[proxyadmin]="proxy-admin"
59 role_recipients_custom[sitemgr]="sites"
60 ```
61
62
63 <a id="option-custom-sender"></a>
64 ##### custom_sender()
65
66 The following is a sample custom_sender() function in health_alarm_notify.conf, to send an SMS via an imaginary HTTPS endpoint to the SMS gateway:
67 ```
68 custom_sender() {
69 # example human readable SMS
70 local msg="${host} ${status_message}: ${alarm} ${raised_for}"
71
72 # limit it to 160 characters and encode it for use in a URL
73 urlencode "${msg:0:160}" >/dev/null; msg="${REPLY}"
74
75 # a space separated list of the recipients to send alarms to
76 to="${1}"
77
78 for phone in ${to}; do
79 httpcode=$(docurl -X POST \
80 --data-urlencode "From=XXX" \
81 --data-urlencode "To=${phone}" \
82 --data-urlencode "Body=${msg}" \
83 -u "${accountsid}:${accounttoken}" \
84 https://domain.website.com/)
85
86 if [ "${httpcode}" = "200" ]; then
87 info "sent custom notification ${msg} to ${phone}"
88 sent=$((sent + 1))
89 else
90 error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}."
91 fi
92 done
93 }
94 ```
95
96 For the complete list of supported notification variables, see the [Alert Notification Variables](../../REFERENCE.md#alert-notification-variables) section in the Health Reference.
97
98
99
100 </details>
101
102
103
104 #### via File
105
106 The configuration file name for this integration is `health_alarm_notify.conf`.
107
108
109 You can edit the configuration file using the [`edit-config`](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#edit-configuration-files) script from the
110 Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#locate-your-config-directory).
111
112 ```bash
113 cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata
114 sudo ./edit-config health_alarm_notify.conf
115 ```
116
117 ##### Examples
118
119 ###### Basic Configuration
120
121
122
123 ```yaml
124 #------------------------------------------------------------------------------
125 # custom notifications
126
127 SEND_CUSTOM="YES"
128 DEFAULT_RECIPIENT_CUSTOM=""
129
130 # The custom_sender() is a custom function to do whatever you need to do
131 custom_sender() {
132 # example human readable SMS
133 local msg="${host} ${status_message}: ${alarm} ${raised_for}"
134
135 # limit it to 160 characters and encode it for use in a URL
136 urlencode "${msg:0:160}" >/dev/null; msg="${REPLY}"
137
138 # a space separated list of the recipients to send alarms to
139 to="${1}"
140
141 for phone in ${to}; do
142 httpcode=$(docurl -X POST \
143 --data-urlencode "From=XXX" \
144 --data-urlencode "To=${phone}" \
145 --data-urlencode "Body=${msg}" \
146 -u "${accountsid}:${accounttoken}" \
147 https://domain.website.com/)
148
149 if [ "${httpcode}" = "200" ]; then
150 info "sent custom notification ${msg} to ${phone}"
151 sent=$((sent + 1))
152 else
153 error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}."
154 fi
155 done
156 }
157
158 ```
159
160
161 ## Troubleshooting
162
163 ### Test Notification
164
165 You can run the following command by hand, to test alerts configuration:
166
167 ```bash
168 # become user netdata
169 sudo su -s /bin/bash netdata
170
171 # enable debugging info on the console
172 export NETDATA_ALARM_NOTIFY_DEBUG=1
173
174 # send test alarms to sysadmin
175 /usr/libexec/netdata/plugins.d/alarm-notify.sh test
176
177 # send test alarms to any role
178 /usr/libexec/netdata/plugins.d/alarm-notify.sh test "ROLE"
179 ```
180
181 Note that this will test _all_ alert mechanisms for the selected role.
182
183