mirror of
https://github.com/bsedin/matrix-webhook.git
synced 2026-04-09 11:25:40 +00:00
add grafana formatter
This was initially designed and implemented in #4 Co-authored-by: Sven Seeberg <mail@sven-seeberg.de>
This commit is contained in:
@@ -16,7 +16,7 @@ from nio import AsyncClient
|
||||
from nio.exceptions import LocalProtocolError
|
||||
from nio.responses import RoomSendError
|
||||
|
||||
from . import conf
|
||||
from . import conf, formatters
|
||||
|
||||
ERROR_MAP = {"M_FORBIDDEN": HTTPStatus.FORBIDDEN}
|
||||
|
||||
@@ -46,6 +46,12 @@ async def handler(request):
|
||||
if "key" in request.rel_url.query and "key" not in data:
|
||||
data["key"] = request.rel_url.query["key"]
|
||||
|
||||
if "formatter" in request.rel_url.query:
|
||||
try:
|
||||
data = getattr(formatters, request.rel_url.query["formatter"])(data)
|
||||
except AttributeError:
|
||||
return create_json_response(HTTPStatus.BAD_REQUEST, "Unknown formatter")
|
||||
|
||||
if not all(key in data for key in ["body", "key"]):
|
||||
return create_json_response(
|
||||
HTTPStatus.BAD_REQUEST, "Missing body and/or API key property"
|
||||
|
||||
Reference in New Issue
Block a user