| 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: "This 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 | |
| 84 | For the complete list of supported notification variables, see the [Alert Notification Variables](../../REFERENCE.md#alert-notification-variables) section in the Health Reference. |
| 85 | |
| 86 | examples: |
| 87 | folding: |
| 88 | enabled: true |
| 89 | title: '' |
| 90 | list: |
| 91 | - name: 'Basic Configuration' |
| 92 | folding: |
| 93 | enabled: false |
| 94 | description: '' |
| 95 | config: | |
| 96 | #------------------------------------------------------------------------------ |
| 97 | # custom notifications |
| 98 | |
| 99 | SEND_CUSTOM="YES" |
| 100 | DEFAULT_RECIPIENT_CUSTOM="" |
| 101 | |
| 102 | # The custom_sender() is a custom function to do whatever you need to do |
| 103 | custom_sender() { |
| 104 | # example human readable SMS |
| 105 | local msg="${host} ${status_message}: ${alarm} ${raised_for}" |
| 106 | |
| 107 | # limit it to 160 characters and encode it for use in a URL |
| 108 | urlencode "${msg:0:160}" >/dev/null; msg="${REPLY}" |
| 109 | |
| 110 | # a space separated list of the recipients to send alarms to |
| 111 | to="${1}" |
| 112 | |
| 113 | for phone in ${to}; do |
| 114 | httpcode=$(docurl -X POST \ |
| 115 | --data-urlencode "From=XXX" \ |
| 116 | --data-urlencode "To=${phone}" \ |
| 117 | --data-urlencode "Body=${msg}" \ |
| 118 | -u "${accountsid}:${accounttoken}" \ |
| 119 | https://domain.website.com/) |
| 120 | |
| 121 | if [ "${httpcode}" = "200" ]; then |
| 122 | info "sent custom notification ${msg} to ${phone}" |
| 123 | sent=$((sent + 1)) |
| 124 | else |
| 125 | error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}." |
| 126 | fi |
| 127 | done |
| 128 | } |
| 129 | troubleshooting: |
| 130 | problems: |
| 131 | list: [] |