Handle various recipients and multi-number alerts
This commit is contained in:
parent
8f1495cf0c
commit
a5576a83c7
3 changed files with 13 additions and 5 deletions
|
@ -13,7 +13,8 @@ def root() -> t.Tuple[str, int]:
|
|||
|
||||
|
||||
@app.route("/alertmanager", methods=["POST"])
|
||||
def alertmanager():
|
||||
@app.route("/alertmanager/<recipient>", methods=["POST"])
|
||||
def alertmanager(recipient=None):
|
||||
data = request.get_json(cache=False)
|
||||
|
||||
if "version" not in data or int(data["version"]) != 4:
|
||||
|
@ -42,6 +43,13 @@ def alertmanager():
|
|||
msg += "\n\n"
|
||||
msg += "\n".join(["* " + line for line in alert_lines])
|
||||
|
||||
signal.signal_send(configuration.RECIPIENTS[configuration.DEFAULT_RECIPIENT], msg)
|
||||
if recipient is None:
|
||||
recipient = configuration.DEFAULT_RECIPIENT
|
||||
try:
|
||||
recipient_nums = configuration.RECIPIENTS[recipient]
|
||||
except KeyError:
|
||||
return "Bad recipient", 400
|
||||
|
||||
signal.signal_send(recipient_nums, msg)
|
||||
|
||||
return "OK", 200
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Signal 'address book'
|
||||
RECIPIENTS = {"foo": "+42..."} # FIXME
|
||||
RECIPIENTS = {"foo": ["+42..."]} # FIXME
|
||||
|
||||
# Recipient from the dict above to send to by default
|
||||
DEFAULT_RECIPIENT = "foo" # FIXME
|
||||
|
|
|
@ -5,14 +5,14 @@ from gi.repository.GLib import GError
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def signal_send(recipient, message):
|
||||
def signal_send(recipients, message):
|
||||
try:
|
||||
bus = SystemBus()
|
||||
signal_bus = bus.get("org.asamk.Signal")
|
||||
signal_bus.sendMessage(
|
||||
message,
|
||||
[],
|
||||
[recipient],
|
||||
recipients,
|
||||
)
|
||||
except GError as exn:
|
||||
logger.error("Cannot send Signal notification: %s", exn)
|
||||
|
|
Loading…
Reference in a new issue