| 1 | <!--startmeta |
| 2 | custom_edit_url: "https://github.com/netdata/netdata/edit/master/src/health/notifications/matrix/README.md" |
| 3 | meta_yaml: "https://github.com/netdata/netdata/edit/master/src/health/notifications/matrix/metadata.yaml" |
| 4 | sidebar_label: "Matrix" |
| 5 | learn_status: "Published" |
| 6 | learn_rel_path: "Alerts & Notifications/Notifications/Agent Dispatched Notifications" |
| 7 | keywords: ['Matrix'] |
| 8 | message: "DO NOT EDIT THIS FILE DIRECTLY, IT IS GENERATED BY THE NOTIFICATION'S metadata.yaml FILE" |
| 9 | endmeta--> |
| 10 | |
| 11 | # Matrix |
| 12 | |
| 13 | |
| 14 | <img src="https://netdata.cloud/img/matrix.svg" width="150"/> |
| 15 | |
| 16 | |
| 17 | Send notifications to Matrix network rooms using Netdata's Agent alert notification feature, which supports dozens of endpoints, user roles, and more. |
| 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 | - The url of the homeserver (`https://homeserver:port`). |
| 30 | - Credentials for connecting to the homeserver, in the form of a valid access token for your account (or for a dedicated notification account). These tokens usually don't expire. |
| 31 | - The Room ids that you want to sent the notification to. |
| 32 | - Access to the terminal where Netdata Agent is running |
| 33 | |
| 34 | |
| 35 | |
| 36 | ### Configuration |
| 37 | |
| 38 | #### Options |
| 39 | |
| 40 | The following options can be defined for this notification |
| 41 | |
| 42 | <details open><summary>Config Options</summary> |
| 43 | |
| 44 | |
| 45 | |
| 46 | | Option | Description | Default | Required | |
| 47 | |:-----|:------------|:--------|:---------:| |
| 48 | | SEND_MATRIX | Set `SEND_MATRIX` to YES | YES | yes | |
| 49 | | MATRIX_HOMESERVER | set `MATRIX_HOMESERVER` to the URL of the Matrix homeserver. | | yes | |
| 50 | | [MATRIX_ACCESSTOKEN](#option-matrix-accesstoken) | Set `MATRIX_ACCESSTOKEN` to the access token from your Matrix account. | | yes | |
| 51 | | [DEFAULT_RECIPIENT_MATRIX](#option-default-recipient-matrix) | Set `DEFAULT_RECIPIENT_MATRIX` to the Rooms you want the alert notifications to be sent to. The format is `!roomid:homeservername`. | | yes | |
| 52 | |
| 53 | <a id="option-matrix-accesstoken"></a> |
| 54 | ##### MATRIX_ACCESSTOKEN |
| 55 | |
| 56 | To obtain the access token, you can use the following curl command: |
| 57 | ``` |
| 58 | curl -XPOST -d '{"type":"m.login.password", "user":"example", "password":"wordpass"}' "https://homeserver:8448/_matrix/client/r0/login" |
| 59 | ``` |
| 60 | |
| 61 | |
| 62 | <a id="option-default-recipient-matrix"></a> |
| 63 | ##### DEFAULT_RECIPIENT_MATRIX |
| 64 | |
| 65 | The Room ids are unique identifiers and can be obtained from the Room settings in a Matrix client (e.g. Riot). |
| 66 | |
| 67 | You can define multiple Rooms like this: `!roomid1:homeservername` `!roomid2:homeservername`. |
| 68 | |
| 69 | All roles will default to this variable if left unconfigured. |
| 70 | |
| 71 | You can have different Rooms per role, by editing `DEFAULT_RECIPIENT_MATRIX` with the `!roomid:homeservername` you want, in the following entries at the bottom of the same file: |
| 72 | |
| 73 | ```text |
| 74 | role_recipients_matrix[sysadmin]="!roomid1:homeservername" |
| 75 | role_recipients_matrix[domainadmin]="!roomid2:homeservername" |
| 76 | role_recipients_matrix[dba]="!roomid3:homeservername" |
| 77 | role_recipients_matrix[webmaster]="!roomid4:homeservername" |
| 78 | role_recipients_matrix[proxyadmin]="!roomid5:homeservername" |
| 79 | role_recipients_matrix[sitemgr]="!roomid6:homeservername" |
| 80 | ``` |
| 81 | |
| 82 | |
| 83 | |
| 84 | </details> |
| 85 | |
| 86 | |
| 87 | |
| 88 | #### via File |
| 89 | |
| 90 | The configuration file name for this integration is `health_alarm_notify.conf`. |
| 91 | |
| 92 | |
| 93 | 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 |
| 94 | Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#locate-your-config-directory). |
| 95 | |
| 96 | ```bash |
| 97 | cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata |
| 98 | sudo ./edit-config health_alarm_notify.conf |
| 99 | ``` |
| 100 | |
| 101 | ##### Examples |
| 102 | |
| 103 | ###### Basic Configuration |
| 104 | |
| 105 | |
| 106 | |
| 107 | ```yaml |
| 108 | #------------------------------------------------------------------------------ |
| 109 | # Matrix notifications |
| 110 | |
| 111 | SEND_MATRIX="YES" |
| 112 | MATRIX_HOMESERVER="https://matrix.org:8448" |
| 113 | MATRIX_ACCESSTOKEN="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
| 114 | DEFAULT_RECIPIENT_MATRIX="!XXXXXXXXXXXX:matrix.org" |
| 115 | |
| 116 | ``` |
| 117 | |
| 118 | |
| 119 | ## Troubleshooting |
| 120 | |
| 121 | ### Test Notification |
| 122 | |
| 123 | You can run the following command by hand, to test alerts configuration: |
| 124 | |
| 125 | ```bash |
| 126 | # become user netdata |
| 127 | sudo su -s /bin/bash netdata |
| 128 | |
| 129 | # enable debugging info on the console |
| 130 | export NETDATA_ALARM_NOTIFY_DEBUG=1 |
| 131 | |
| 132 | # send test alarms to sysadmin |
| 133 | /usr/libexec/netdata/plugins.d/alarm-notify.sh test |
| 134 | |
| 135 | # send test alarms to any role |
| 136 | /usr/libexec/netdata/plugins.d/alarm-notify.sh test "ROLE" |
| 137 | ``` |
| 138 | |
| 139 | Note that this will test _all_ alert mechanisms for the selected role. |
| 140 | |
| 141 |