Moved notifier into main process
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
TellMe Server (2.2.0)
|
||||
* Moved the notifier into tellmesrv
|
||||
|
||||
TellMe Server (2.1.0)
|
||||
* Added support for GoAlert messages
|
||||
|
||||
|
||||
@@ -3,17 +3,17 @@ from flask import Flask, request, jsonify
|
||||
import websocket
|
||||
import json
|
||||
import yaml
|
||||
import zmq
|
||||
import random
|
||||
from pprint import pprint
|
||||
|
||||
__version__ = "2.1.1"
|
||||
__version__ = "2.2.0"
|
||||
versionstring='Taurix TellMe server v' + __version__
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.REQ)
|
||||
socket.connect("tcp://localhost:5555")
|
||||
# context = zmq.Context()
|
||||
# socket = context.socket(zmq.REQ)
|
||||
# socket.connect("tcp://localhost:5555")
|
||||
|
||||
hooks = {}
|
||||
with open(r'/etc/tellme/hooks.yml') as hooksfile:
|
||||
@@ -21,17 +21,26 @@ with open(r'/etc/tellme/hooks.yml') as hooksfile:
|
||||
|
||||
|
||||
def sendmessage(target, message):
|
||||
global socket
|
||||
jsonmessage = {}
|
||||
jsonmessage['target'] = target
|
||||
jsonmessage['message'] = message
|
||||
socket.send_string(json.dumps(jsonmessage))
|
||||
# global socket
|
||||
|
||||
# Wait for a reply
|
||||
reply = socket.recv_string()
|
||||
print(f"Received reply: {reply}")
|
||||
msg = ("%s %s" % (target, message))
|
||||
|
||||
if reply == 'sent':
|
||||
# Create a unique correlation ID
|
||||
command = {
|
||||
"corrId": f"id{random.randint(0, 999999)}",
|
||||
"cmd": msg,
|
||||
}
|
||||
json_command = json.dumps(command)
|
||||
|
||||
uri = "ws://localhost:5080"
|
||||
ws = websocket.create_connection(uri)
|
||||
|
||||
ws.send(json_command) # Send message to WebSocket
|
||||
responsejson = ws.recv() # Receive response
|
||||
response = json.loads(responsejson)
|
||||
ws.close()
|
||||
|
||||
if response is not None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
[Unit]
|
||||
Description=Tellme Notifier
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=tellme
|
||||
WorkingDirectory=/opt/tellme
|
||||
ExecStart=python3 notifier.py
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user