Add base boilerplate

This commit is contained in:
Théophile Bastian 2022-03-22 14:15:39 +01:00
parent 6e499e2e9c
commit bc4639a055
3 changed files with 47 additions and 0 deletions

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
Flask
pydbus

27
signal_webhook/app.py Normal file
View file

@ -0,0 +1,27 @@
import typing as t
from flask import Flask, request
from . import signal
app = Flask(__name__)
@app.route("/")
def root() -> t.Tuple[str, int]:
return "Not supported.", 400
@app.route("/alertmanager", methods=["POST"])
def alertmanager():
data = request.get_json(cache=False)
if "version" not in data or int(data["version"]) != 4:
return "Bad API version", 400
if "alerts" not in data:
return "No alerts", 400
if "status" not in data:
return "No status", 400
if data["status"] != "firing":
# Ignore
return "OK", 200
for alert in data["alerts"]:
...

18
signal_webhook/signal.py Normal file
View file

@ -0,0 +1,18 @@
import logging
from pydbus import SystemBus
from gi.repository.GLib import GError
logger = logging.getLogger(__name__)
def signal_send(recipient, message):
try:
bus = SystemBus()
signal_bus = bus.get("org.asamk.Signal")
signal_bus.sendMessage(
message,
[],
[recipient],
)
except GError as exn:
logger.error("Cannot send Signal notification: %s", exn)