Compare commits
2 commits
b0c6bc8b8b
...
10b96bcd25
Author | SHA1 | Date | |
---|---|---|---|
10b96bcd25 | |||
8460454283 |
2 changed files with 17 additions and 17 deletions
|
@ -4,7 +4,10 @@ import requests
|
|||
import urllib
|
||||
import json
|
||||
|
||||
from alerta.plugins import app
|
||||
try:
|
||||
from alerta.plugins import app # alerta >= 5.0
|
||||
except ImportError:
|
||||
from alerta.app import app # alerta < 5.0
|
||||
from alerta.plugins import PluginBase
|
||||
|
||||
LOG = logging.getLogger("alerta.plugins.matrix")
|
||||
|
@ -13,15 +16,12 @@ MATRIX_HOMESERVER_URL = [
|
|||
os.environ.get("MATRIX_HOMESERVER") or app.config["MATRIX_HOMESERVER"],
|
||||
"/_matrix/client/r0/rooms/",
|
||||
urllib.parse.quote(os.environ.get("MATRIX_ROOM") or app.config["MATRIX_ROOM"], ":"),
|
||||
"/send/m.room.message",
|
||||
"/send/m.room.message"
|
||||
]
|
||||
MATRIX_ACCESS_TOKEN = (
|
||||
os.environ.get("MATRIX_ACCESS_TOKEN") or app.config["MATRIX_ACCESS_TOKEN"]
|
||||
)
|
||||
|
||||
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")
|
||||
DASHBOARD_URL = os.environ.get("DASHBOARD_URL") or app.config.get("DASHBOARD_URL", "")
|
||||
|
||||
PRIORITY = {
|
||||
SEVERITY_ICON = {
|
||||
"critical": "🔴 ",
|
||||
"warning": "⚠️ ",
|
||||
"ok": "✅ ",
|
||||
|
@ -30,7 +30,7 @@ PRIORITY = {
|
|||
}
|
||||
|
||||
|
||||
class PushMessage(PluginBase):
|
||||
class SendMessage(PluginBase):
|
||||
def pre_receive(self, alert):
|
||||
return alert
|
||||
|
||||
|
@ -39,10 +39,10 @@ class PushMessage(PluginBase):
|
|||
if alert.repeat:
|
||||
return
|
||||
|
||||
priority = PRIORITY.get(alert.severity, "")
|
||||
severity = SEVERITY_ICON.get(alert.severity, "")
|
||||
|
||||
body = "{}{}: {} alert for {} \n{} - {} - {} \n{} \nDate: {}".format(
|
||||
priority,
|
||||
severity,
|
||||
alert.environment,
|
||||
alert.severity.capitalize(),
|
||||
",".join(alert.service),
|
||||
|
@ -54,7 +54,7 @@ class PushMessage(PluginBase):
|
|||
)
|
||||
|
||||
formatted_body = "{}<strong>{}: {} alert for {} </br>{} - {} - {} </strong></br>{} </br><strong>Date: </strong> {} | <a rel='noopener' href='{}/#/alert/{}'>View alert</a>".format(
|
||||
priority,
|
||||
severity,
|
||||
alert.environment,
|
||||
alert.severity.capitalize(),
|
||||
",".join(alert.service),
|
||||
|
@ -68,7 +68,7 @@ class PushMessage(PluginBase):
|
|||
)
|
||||
|
||||
payload = {
|
||||
"msgtype": "m.notice",
|
||||
"msgtype": MATRIX_MESSAGE_TYPE,
|
||||
"format": "org.matrix.custom.html",
|
||||
"body": body,
|
||||
"formatted_body": formatted_body,
|
||||
|
|
8
setup.py
8
setup.py
|
@ -1,13 +1,13 @@
|
|||
from setuptools import setup, find_packages
|
||||
|
||||
version = "0.0.4"
|
||||
version = "0.0.5"
|
||||
|
||||
setup(
|
||||
name="alerta-matrix",
|
||||
version=version,
|
||||
description="Alerta plugin for sending matrix alerts",
|
||||
description="Alerta plugin for Matrix",
|
||||
url="https://github.com/alerta/alerta-contrib",
|
||||
license="Apache License 2.0",
|
||||
license="MIT",
|
||||
author="Magnus Walbeck",
|
||||
author_email="mw@mwalbeck.org",
|
||||
packages=find_packages(),
|
||||
|
@ -15,5 +15,5 @@ setup(
|
|||
install_requires=["requests"],
|
||||
include_package_data=True,
|
||||
zip_safe=True,
|
||||
entry_points={"alerta.plugins": ["matrix = alerta_matrix:PushMessage"]},
|
||||
entry_points={"alerta.plugins": ["matrix = alerta_matrix:SendMessage"]},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue