webhook-matrix-notifier/README.md
Ben 1d62653830
Update to Python 3.11 and Pipfile.lock
Rename wsgi module from wmn
Update Dockerfile to use `pipenv install --deploy`
Clarify README.md
2024-02-05 17:33:14 +01:00

2 KiB

Webhook Matrix Notifier

This Python project, Webhook Matrix Notifier, is designed to receive data via webhooks, verify a secret, and send notifications to a Matrix room. The project provides a wsgi-compatible interface at wmn.wsgi, which is suitable for use behind a reverse proxy.

Configuration

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.

Running the Command Line Notifier

To notify a room with a simple text/html message, ensure your credentials are filled out in the configuration file and run:

python -m wmn.notify -r '!room:matrix.org' "text" "html"

The installation of the package, specified by pyproject.yaml will create a shorthand script called "matrix-notify" for this purpose.

Testing the Webhook Application Locally

  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.

GitLab

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

Ensure that the X-Gitlab-Token corresponds to the secret provided in the configuration.

Prometheus

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

Ensure that the secret is passed as a URI parameter.