aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2020-01-26 22:38:02 +0100
committerjaseg <code@jaseg.net>2020-01-26 22:38:02 +0100
commitb595518607d567b9d0de010d2ff40985c8076cba (patch)
tree9c9e27ce68020a7d59433507d7e992c896ae7604
parent6345b9eec635a8d4deb1a4fd62518113af4db8fe (diff)
downloadinfra-b595518607d567b9d0de010d2ff40985c8076cba.tar.gz
infra-b595518607d567b9d0de010d2ff40985c8076cba.tar.bz2
infra-b595518607d567b9d0de010d2ff40985c8076cba.zip
deploy/klingel: Add classification support
-rw-r--r--notification_proxy.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/notification_proxy.py b/notification_proxy.py
index fcef50f..117f8e1 100644
--- a/notification_proxy.py
+++ b/notification_proxy.py
@@ -34,10 +34,10 @@ with db as conn:
mail_routes = {}
-def mail_route(name, receiver, subject, secret):
+def mail_route(name, receiver, secret):
def wrap(func):
global routes
- mail_routes[name] = (receiver, subject, func, secret)
+ mail_routes[name] = (receiver, func, secret)
return func
return wrap
@@ -109,9 +109,10 @@ def authenticate(route_name, secret, clock_delta_tolerance:'s'=120):
return msg_time, payload['scope'], payload['d']
-@mail_route('klingel', 'computerstuff@jaseg.de', 'It rang!', app.config['SECRET_KLINGEL'])
-def klingel(rms=None, capture=None, **kwargs):
- return f'rms={rms}\ncapture={capture}\nextra_args={kwargs}'
+@mail_route('klingel', 'computerstuff@jaseg.de', app.config['SECRET_KLINGEL'])
+def klingel(classification='somewhere', rms=None, capture=None, **kwargs):
+ return (f'It rang {classification}!',
+ f'rms={rms}\ncapture={capture}\nextra_args={kwargs}')
def send_mail(route_name, receiver, subject, body):
@@ -134,13 +135,16 @@ def send_mail(route_name, receiver, subject, body):
@app.route('/v1/notify/<route_name>', methods=['POST'])
def notify(route_name):
- receiver, notify_subject, func, secret = mail_routes[route_name]
+ receiver, func, secret = mail_routes[route_name]
msg_time, scope, kwargs = authenticate(route_name, secret)
if scope == 'default':
# Exceptions will yield a 500 error
- body = func(**kwargs)
- send_mail(route_name, receiver, notify_subject, body or 'empty message')
+ subject, body = func(**kwargs)
+ send_mail(route_name, receiver, subject, body or 'empty message')
+
+ elif scope == 'info':
+ send_mail(route_name, receiver, f'System info: {kwargs["info_msg"]}', f'Logged data: {kwargs}')
elif scope == 'boot':
formatted = datetime.utcfromtimestamp(msg_time).isoformat()