-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.py
34 lines (25 loc) · 898 Bytes
/
listener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python3.5
# -*- coding: utf-8 -*-
import logging
import utils
from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple
from jsonrpc import JSONRPCResponseManager, dispatcher
from config import listen_port, listen_int
@dispatcher.add_method
def sendAlarm(group='Empty group', title='Empty title', body='Empty body'):
msg = [group, title, body]
logging.warning((msg))
utils.qbus.put(msg)
return "OK"
manager = JSONRPCResponseManager()
@Request.application
def application(request):
response = manager.handle(request.get_data(cache=False, as_text=True), dispatcher)
return Response(response.json, mimetype='application/json')
def start_listener():
while True:
try:
run_simple(hostname=listen_int, port=listen_port, application=application, threaded=True)
except Exception:
continue