2019-07-18 11:19:03 +00:00
|
|
|
# Webhook Matrix Notifier
|
|
|
|
|
2023-10-27 11:46:58 +00:00
|
|
|
Takes notifications via webhook, checks a secret and notifies a [Matrix](https://matrix.org) room.
|
2021-06-28 07:56:48 +00:00
|
|
|
Listens to HTTP only. Should be used behind a reverse-proxy with HTTPS.
|
|
|
|
|
2023-10-27 12:42:41 +00:00
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
An example configuration is located at `config.yml.example`.
|
|
|
|
By default the file `config.yml` in the current working directory will be used as the configuration.
|
|
|
|
To specify a different configuration file, use the environment variable `WMN_CONFIG_PATH`.
|
2021-06-28 07:56:48 +00:00
|
|
|
|
|
|
|
|
2023-10-27 12:09:13 +00:00
|
|
|
## Running the command line notifier
|
|
|
|
|
2023-10-27 12:42:41 +00:00
|
|
|
To notify a room with a simple text message, ensure credentials are filled out in your configuration file and run
|
2023-10-27 12:09:13 +00:00
|
|
|
|
|
|
|
```
|
2023-10-27 12:42:41 +00:00
|
|
|
python -m wmn.notify -r '!room:matrix.org' "text" "html"
|
2023-10-27 12:09:13 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Installing the webhook-matrix-notifier will create the shorthand script "matrix-notify" for this.
|
|
|
|
|
|
|
|
|
|
|
|
## Testing the webhook application locally
|
2021-06-28 07:56:48 +00:00
|
|
|
|
|
|
|
First, start the webserver locally by `env FLASK_APP=wmn.py flask run` or have your IDE start it for you. \
|
|
|
|
Then, send a POST request using curl.
|
|
|
|
|
|
|
|
### GitLab
|
|
|
|
|
|
|
|
```
|
2023-10-27 11:46:58 +00:00
|
|
|
export URLQUOTED_ROOM=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("#room:matrix.org"))'`
|
|
|
|
curl -i -X POST "http://localhost:5000/matrix?room=${URLQUOTED_ROOM}" -H "X-Gitlab-Event: Push Hook" -H "X-Gitlab-Token: 123" -H "Content-Type: application/json" --data-binary @./testrequest_gitlab.json
|
2021-06-28 07:56:48 +00:00
|
|
|
```
|
|
|
|
|
2023-10-27 12:42:41 +00:00
|
|
|
The `X-Gitlab-Token` must correspond to the secret provided in the configuration.
|
2021-06-28 07:56:48 +00:00
|
|
|
|
|
|
|
### Prometheus
|
|
|
|
|
|
|
|
```
|
2023-10-27 11:46:58 +00:00
|
|
|
export URLQUOTED_ROOM=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("#room:matrix.org"))'`
|
|
|
|
export URLQUOTED_SECRET=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("123"))'`
|
|
|
|
curl -i -X POST "http://localhost:5000/matrix?type=prometheus&secret=${URLQUOTED_SECRET}&room=${URLQUOTED_ROOM}" -H "Content-Type: application/json" --data-binary @./testrequest_prometheus.json
|
2021-06-28 07:56:48 +00:00
|
|
|
```
|
|
|
|
|
2023-10-27 12:42:41 +00:00
|
|
|
The secret must be passed as a URI parameter.
|
|
|
|
|