2019-07-18 11:19:03 +00:00
|
|
|
# Webhook Matrix Notifier
|
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
This Python project, Webhook Matrix Notifier, is designed to receive data via webhooks, verify a secret,
|
|
|
|
and send notifications to a [Matrix](https://matrix.org) room.
|
|
|
|
The project provides a wsgi-compatible interface at `wmn.wsgi`, which is suitable for use behind a reverse proxy.
|
2023-10-27 12:42:41 +00:00
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
An example configuration can be found at `config.yml.example`. By default, the project uses the `config.yml` file
|
|
|
|
in the current working directory for configuration.
|
|
|
|
To specify a different configuration file, use the `WMN_CONFIG_PATH` environment variable.
|
2021-06-28 07:56:48 +00:00
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
## Running the Command Line Notifier
|
2023-10-27 12:09:13 +00:00
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
To notify a room with a simple text/html message,
|
|
|
|
ensure your credentials are filled out in the configuration file and run:
|
2023-10-27 12:09:13 +00:00
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
```bash
|
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
|
|
|
```
|
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
The installation of the package, specified by `pyproject.yaml`
|
|
|
|
will create a shorthand script called "matrix-notify" for this purpose.
|
2023-10-27 12:09:13 +00:00
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
## Testing the Webhook Application Locally
|
2021-06-28 07:56:48 +00:00
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
1. Start the local webserver using either `env FLASK_APP=wmn.wsgi flask run` or have your IDE start it for you.
|
|
|
|
2. Send a POST request using curl.
|
2021-06-28 07:56:48 +00:00
|
|
|
|
|
|
|
### GitLab
|
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
```bash
|
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
|
|
|
```
|
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
Ensure that the `X-Gitlab-Token` corresponds to the secret provided in the configuration.
|
2021-06-28 07:56:48 +00:00
|
|
|
|
|
|
|
### Prometheus
|
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
```bash
|
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
|
|
|
```
|
|
|
|
|
2024-02-05 16:33:14 +00:00
|
|
|
Ensure that the secret is passed as a URI parameter.
|