1
+# yamllint disable rule:line-length
2
+---
3
+- id: 'notify-custom'
4
+ meta:
5
+ name: 'Custom'
6
+ link: ''
7
+ categories:
8
+ - notify.agent
9
+ icon_filename: 'custom.png'
10
+ keywords:
11
+ - custom
12
+ overview:
13
+ notification_description: |
14
+ Netdata Agent's alert notification feature allows you to send custom notifications to any endpoint you choose.
15
+ notification_limitations: ''
16
+ setup:
17
+ prerequisites:
18
+ list:
19
+ - title: ''
20
+ description: |
21
+ - Access to the terminal where Netdata Agent is running
22
+ configuration:
23
+ file:
24
+ name: 'health_alarm_notify.conf'
25
+ options:
26
+ description: 'The following options can be defined for this notification'
27
+ folding:
28
+ title: 'Config Options'
29
+ enabled: true
30
+ list:
31
+ - name: 'SEND_CUSTOM'
32
+ default_value: 'YES'
33
+ description: "Set `SEND_CUSTOM` to YES"
34
+ required: true
35
+ - name: 'DEFAULT_RECIPIENT_CUSTOM'
36
+ default_value: ''
37
+ description: "The `DEFAULT_RECIPIENT_CUSTOM` value is dependent on how you handle the `${to}` variable inside the `custom_sender()` function."
38
+ required: true
39
+ detailed_description: >
40
+ 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:
41
+ ```
42
+ role_recipients_custom[sysadmin]="systems"
43
+ role_recipients_custom[domainadmin]="domains"
44
+ role_recipients_custom[dba]="databases systems"
45
+ role_recipients_custom[webmaster]="marketing development"
46
+ role_recipients_custom[proxyadmin]="proxy-admin"
47
+ role_recipients_custom[sitemgr]="sites"
48
+ ```
49
+ - name: 'custom_sender()'
50
+ default_value: ''
51
+ description: "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."
52
+ required: false
53
+ detailed_description: >
54
+ 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:
55
+ ```
56
+ custom_sender() {
57
+ # example human readable SMS
58
+ local msg="${host} ${status_message}: ${alarm} ${raised_for}"
59
+
60
+ # limit it to 160 characters and encode it for use in a URL
61
+ urlencode "${msg:0:160}" >/dev/null; msg="${REPLY}"
62
+
63
+ # a space separated list of the recipients to send alarms to
64
+ to="${1}"
65
+
66
+ for phone in ${to}; do
67
+ httpcode=$(docurl -X POST \
68
+ --data-urlencode "From=XXX" \
69
+ --data-urlencode "To=${phone}" \
70
+ --data-urlencode "Body=${msg}" \
71
+ -u "${accountsid}:${accounttoken}" \
72
+ https://domain.website.com/)
73
+
74
+ if [ "${httpcode}" = "200" ]; then
75
+ info "sent custom notification ${msg} to ${phone}"
76
+ sent=$((sent + 1))
77
+ else
78
+ error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}."
79
+ fi
80
+ done
81
+ }
82
+ ```
83
+ The supported variables that you can use for the function's msg variable are:
84
+ ```
85
+ Variable name Description
86
+ ${alarm} Like "name = value units"
87
+ ${status_message} Like "needs attention", "recovered", "is critical"
88
+ ${severity} Like "Escalated to CRITICAL", "Recovered from WARNING"
89
+ ${raised_for} Like "(alarm was raised for 10 minutes)"
90
+ ${host} The host generated this event
91
+ ${url_host} Same as ${host} but URL encoded
92
+ ${unique_id} The unique id of this event
93
+ ${alarm_id} The unique id of the alarm that generated this event
94
+ ${event_id} The incremental id of the event, for this alarm id
95
+ ${when} The timestamp this event occurred
96
+ ${name} The name of the alarm, as given in netdata health.d entries
97
+ ${url_name} Same as ${name} but URL encoded
98
+ ${chart} The name of the chart (type.id)
99
+ ${url_chart} Same as ${chart} but URL encoded
100
+ ${family} The family of the chart
101
+ ${url_family} Same as ${family} but URL encoded
102
+ ${status} The current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
103
+ ${old_status} The previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL
104
+ ${value} The current value of the alarm
105
+ ${old_value} The previous value of the alarm
106
+ ${src} The line number and file the alarm has been configured
107
+ ${duration} The duration in seconds of the previous alarm state
108
+ ${duration_txt} Same as ${duration} for humans
109
+ ${non_clear_duration} The total duration in seconds this is/was non-clear
110
+ ${non_clear_duration_txt} Same as ${non_clear_duration} for humans
111
+ ${units} The units of the value
112
+ ${info} A short description of the alarm
113
+ ${value_string} Friendly value (with units)
114
+ ${old_value_string} Friendly old value (with units)
115
+ ${image} The URL of an image to represent the status of the alarm
116
+ ${color} A color in AABBCC format for the alarm
117
+ ${goto_url} The URL the user can click to see the netdata dashboard
118
+ ${calc_expression} The expression evaluated to provide the value for the alarm
119
+ ${calc_param_values} The value of the variables in the evaluated expression
120
+ ${total_warnings} The total number of alarms in WARNING state on the host
121
+ ${total_critical} The total number of alarms in CRITICAL state on the host
122
+ ```
123
+ examples:
124
+ folding:
125
+ enabled: true
126
+ title: ''
127
+ list:
128
+ - name: 'Basic Configuration'
129
+ folding:
130
+ enabled: false
131
+ description: ''
132
+ config: |
133
+ #------------------------------------------------------------------------------
134
+ # custom notifications
135
+
136
+ SEND_CUSTOM="YES"
137
+ DEFAULT_RECIPIENT_CUSTOM=""
138
+
139
+ # The custom_sender() is a custom function to do whatever you need to do
140
+ custom_sender() {
141
+ # example human readable SMS
142
+ local msg="${host} ${status_message}: ${alarm} ${raised_for}"
143
+
144
+ # limit it to 160 characters and encode it for use in a URL
145
+ urlencode "${msg:0:160}" >/dev/null; msg="${REPLY}"
146
+
147
+ # a space separated list of the recipients to send alarms to
148
+ to="${1}"
149
+
150
+ for phone in ${to}; do
151
+ httpcode=$(docurl -X POST \
152
+ --data-urlencode "From=XXX" \
153
+ --data-urlencode "To=${phone}" \
154
+ --data-urlencode "Body=${msg}" \
155
+ -u "${accountsid}:${accounttoken}" \
156
+ https://domain.website.com/)
157
+
158
+ if [ "${httpcode}" = "200" ]; then
159
+ info "sent custom notification ${msg} to ${phone}"
160
+ sent=$((sent + 1))
161
+ else
162
+ error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}."
163
+ fi
164
+ done
165
+ }