Add README and allow only m.text and m.notice message types using config option notice and text

This commit is contained in:
Magnus Walbeck 2021-01-28 17:16:12 +01:00
parent 10b96bcd25
commit 00009d8a82
Signed by: mwalbeck
GPG key ID: CCB78CFF3F950769
2 changed files with 69 additions and 2 deletions

63
README.md Normal file
View file

@ -0,0 +1,63 @@
Matrix Plugin
===================
Send Matrix messages for new alerts.
Installation
------------
Clone the GitHub repo and run:
$ python setup.py install
Or, to install remotely from GitHub run:
$ pip install git+https://github.com/alerta/alerta-contrib.git#subdirectory=plugins/matrix
Note: If Alerta is installed in a python virtual environment then plugins
need to be installed into the same environment for Alerta to dynamically
discover them.
Configuration
-------------
Add `matrix` to the list of enabled `PLUGINS` in `alertad.conf` server
configuration file and set plugin-specific variables either in the
server configuration file or as environment variables.
```python
PLUGINS = ['matrix']
MATRIX_HOMESERVER = '' # default="not set"
MATRIX_ROOM = '' # default="not set"
MATRIX_ACCESS_TOKEN = '' # default="not set"
MATRIX_MESSAGE_TYPE = '' # default="notice" | can be "notice" or "text"
```
The `DASHBOARD_URL` setting should be configured to link matrix messages to
the Alerta console:
```python
DASHBOARD_URL = '' # default="not set"
```
**Example**
```python
PLUGINS = ['reject','matrix']
MATRIX_HOMESERVER = 'https://matrix.org'
MATRIX_ROOM = '!VMKjBnKVghpiiBqwjEg:matrix.org'
MATRIX_ACCESS_TOKEN = '4yHuHptP2crTWvLdzUzvhPmoArz6mLTqN9DnpvY5mFDLEW8yxWEJLU8kg6nLUdDcxHS6SwXNrchKM2pmscgoAue2XxUfCrhWBtGtP7QtECTtQiE6h4HuSGu6Vj8F9Zdge'
MATRIX_MESSAGE_TYPE = 'notice'
DASHBOARD_URL = 'https://try.alerta.io'
```
References
----------
* How to get an access token: https://www.matrix.org/docs/guides/client-server-api#login
* Matrix message types: https://matrix.org/docs/spec/client_server/latest#m-room-message-msgtypes
License
-------
Copyright (c) 2021 Magnus Walbeck. Available under the MIT License.

View file

@ -19,7 +19,11 @@ MATRIX_HOMESERVER_URL = [
"/send/m.room.message"
]
MATRIX_ACCESS_TOKEN = os.environ.get("MATRIX_ACCESS_TOKEN") or app.config["MATRIX_ACCESS_TOKEN"]
MATRIX_MESSAGE_TYPE = os.environ.get("MATRIX_MESSAGE_TYPE") or app.config.get("MATRIX_MESSAGE_TYPE", "m.notice")
MATRIX_MESSAGE_TYPE = os.environ.get("MATRIX_MESSAGE_TYPE") or app.config.get("MATRIX_MESSAGE_TYPE", "notice")
MATRIX_MESSAGE_TYPES = {
"text": "m.text",
"notice": "m.notice"
}
DASHBOARD_URL = os.environ.get("DASHBOARD_URL") or app.config.get("DASHBOARD_URL", "")
SEVERITY_ICON = {
"critical": "🔴 ",
@ -68,7 +72,7 @@ class SendMessage(PluginBase):
)
payload = {
"msgtype": MATRIX_MESSAGE_TYPE,
"msgtype": MATRIX_MESSAGE_TYPES.get(MATRIX_MESSAGE_TYPE, "m.notice"),
"format": "org.matrix.custom.html",
"body": body,
"formatted_body": formatted_body,