Compare commits

...

46 Commits

Author SHA1 Message Date
b95b776418 drop when empty 2025-02-18 15:23:06 +01:00
b6e11f148f add debug 2025-02-18 14:46:42 +01:00
a9e4febaa5 add debug 2025-02-18 14:43:51 +01:00
25b17f93fc add debug 2025-02-18 14:41:53 +01:00
e9f57dd3f9 add debug 2025-02-18 14:39:44 +01:00
845c937d80 fix status 2025-02-18 14:38:20 +01:00
ecb2429a0d REmove lock 2025-02-18 14:36:10 +01:00
5509f5e177 REmove lock 2025-02-18 14:35:27 +01:00
73592dd53e REmove lock 2025-02-18 14:34:26 +01:00
f92a44b5c1 Fix 2025-02-18 14:32:12 +01:00
a969b950d1 Fix 2025-02-18 14:31:40 +01:00
6bedd576be Added ZMQ 2025-02-18 14:28:51 +01:00
fbfc7d9992 Added ZMQ 2025-02-18 14:27:46 +01:00
040bd08503 Added ansible role 2025-02-12 14:21:43 +01:00
90d50084a7 Cleanup debug 2025-02-12 12:47:46 +01:00
7af2455cb6 Debug 2025-02-12 12:21:57 +01:00
fd0e386792 Disable duplicate checks 2025-02-12 11:48:22 +01:00
0595649afe Debug 2025-02-12 11:43:59 +01:00
7532b2a064 Debug 2025-02-12 11:43:23 +01:00
8fa91e5e5f Debug 2025-02-12 11:42:36 +01:00
e364c7d965 Debug 2025-02-12 11:41:45 +01:00
62e7468eb2 Debug 2025-02-12 11:39:55 +01:00
50a721267a Debug 2025-02-12 11:39:22 +01:00
84394cb3b8 Debug 2025-02-12 11:37:57 +01:00
3bba7a51f3 Debug 2025-02-12 11:37:19 +01:00
5ee659c376 Debug 2025-02-12 11:36:39 +01:00
e3b6d650b8 Debug 2025-02-12 11:35:48 +01:00
1b68889ac5 Debug 2025-02-12 11:35:00 +01:00
6529e1b88b Debug 2025-02-12 11:33:48 +01:00
a529e1eb53 Debug 2025-02-12 11:32:41 +01:00
a3010018d4 Debug 2025-02-12 11:28:43 +01:00
50ef25c129 Debug 2025-02-12 11:28:12 +01:00
ee6bb28f6a Debug 2025-02-12 11:26:58 +01:00
3847d2ea96 Debug 2025-02-12 11:26:10 +01:00
958b51ba40 Debug 2025-02-12 11:25:31 +01:00
2302e9b166 Debug 2025-02-12 11:24:21 +01:00
068af17935 Debug 2025-02-12 11:24:02 +01:00
e28d653921 Debug 2025-02-12 11:22:50 +01:00
2e9520d3cd Debug 2025-02-12 11:22:16 +01:00
150c03b05a Debug 2025-02-12 11:21:18 +01:00
761536274b Debug 2025-02-12 11:19:36 +01:00
26b6b4cd98 Debug 2025-02-12 11:18:32 +01:00
f3ef9e55d5 Debug 2025-02-12 11:17:48 +01:00
06744aa5c7 Test threading lock 2025-02-12 11:16:09 +01:00
38d9e87393 Test threading lock 2025-02-12 11:11:58 +01:00
48791ee1f1 add output 2025-02-12 11:11:29 +01:00
7 changed files with 150 additions and 24 deletions

View File

@@ -0,0 +1,3 @@
---
tellme_url: https://
tellme_webhook: 123

View File

@@ -0,0 +1,11 @@
---
- name: Send a tellme notification
uri:
url: "{{ tellme_url }}/webhook/{{ tellme_webhook }}"
method: POST
body:
message: "EPS Ansible run completed"
body_format: json
delegate_to: mon01
run_once: true
ignore_errors: yes

5
server/Changelog Normal file
View File

@@ -0,0 +1,5 @@
TellMe (1.3.0)
* Add support for mentions (-n)
TellMe (1.2.0)
* Feature complete version

14
server/package.json Normal file
View File

@@ -0,0 +1,14 @@
{
"name": "TellMe Server",
"version": "2.0.0b2",
"description": "TellMe Server",
"scripts": {
"dev": "webpack-dev-server --inline --hot"
},
"author": "Guy Van Sanden <guy@taurix.net>",
"license": "AGPL",
"dependencies": {
"grunt": "~0.4.5",
"grunt-version": "~1.1.0"
}
}

80
server/src/notifier.py Normal file
View File

@@ -0,0 +1,80 @@
#!/bin/env python3
import websocket
import json
import random
import zmq
from pprint import pprint
__version__ = "2.0.0b2"
ws = None
uri = "ws://localhost:5080"
ws = websocket.create_connection(uri)
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
def sendsmpmessage(target, message):
global ws
print("Sendmessage %s called to %s" % (message, target))
msg = ("%s %s" % (target, message))
# Create a unique correlation ID
command = {
"corrId": f"id{random.randint(0, 999999)}",
"cmd": msg,
}
json_command = json.dumps(command)
""" Connects to WebSocket server, sends a message, and returns the response """
if ws is None:
uri = "ws://localhost:5080"
ws = websocket.create_connection(uri) # Blocking WebSocket connection
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
# for chatitem in response['resp']['chatItems']:
# statusdict = chatitem['chatItem']['meta']['itemStatus']
# try:
# status = statusdict['sndProgress']
# except KeyError:
# pprint(response['resp']['chatItems'])
# print('---')
# pprint(chatitem)
# print("FAILED")
# status = 'FAILED'
# else:
# smessage = chatitem['chatItem']['meta']['itemText']
# print("Message '%s' sent over websocket to %s, status was %s" % (smessage, target, status))
# if status == 'complete' or status == 'partial':
# return True
# else:
# return False
if __name__ == '__main__':
print("Tellme Notifier started...")
while True:
zmqmessage = socket.recv_string()
print(f"Received request: {zmqmessage}")
result = True
decoded = json.loads(zmqmessage)
pprint(decoded)
result = sendsmpmessage(decoded.get('target'), decoded.get('message'))
print(result)
if result is True:
socket.send_string("sent")
else:
socket.send_string("failed")

View File

@@ -3,44 +3,44 @@ from flask import Flask, request, jsonify
import websocket
import json
import yaml
import random
import threading
import zmq
from pprint import pprint
__version__ = "2.0.0b2"
versionstring='Taurix TellMe server v' + __version__
app = Flask(__name__)
lock = threading.Lock()
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")
hooks = {}
with open(r'/etc/tellme/hooks.yml') as hooksfile:
hooks = yaml.load(hooksfile, Loader=yaml.FullLoader)
def sendmessage(target, message):
print("Sendmessage %s called to %s" % (message, target))
with lock:
msg = ("%s %s" % (target, message))
global socket
jsonmessage = {}
jsonmessage['target'] = target
jsonmessage['message'] = message
socket.send_string(json.dumps(jsonmessage))
# Create a unique correlation ID
command = {
"corrId": f"id{random.randint(0, 999999)}",
"cmd": msg,
}
json_command = json.dumps(command)
# Wait for a reply
reply = socket.recv_string()
print(f"Received reply: {reply}")
if reply == 'sent':
return True
else:
return False
""" Connects to WebSocket server, sends a message, and returns the response """
uri = "ws://localhost:5080"
ws = websocket.create_connection(uri) # Blocking WebSocket connection
ws.send(json_command) # Send message to WebSocket
response = ws.recv() # Receive response
# ws.close() # Close WebSocket connection
# print(response)
ws.close()
return response
@app.route("/webhook/<id>", methods=['POST'])
def webhook_receiver(id):
print("Webhook id %s" % (id))
pprint(request.json)
data = request.json # Get the JSON data from the incoming request
# Process the data and perform actions based on the event
print("Received webhook data:", data)
@@ -52,7 +52,10 @@ def webhook_receiver(id):
if target is not None:
print(target)
if data.get('message') is not None:
sendmessage(target, data.get('message'))
else:
print("No message, droppint")
else:
print("No target found, dropping message")
@@ -61,6 +64,4 @@ def webhook_receiver(id):
if __name__ == '__main__':
print("Started %s" % (versionstring))
uri = "ws://localhost:5080"
# ws = websocket.create_connection(uri)
app.run()

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Tellme Notifier
After=network.target
[Service]
User=tellme
WorkingDirectory=/opt/tellme
ExecStart=python3 notifier.py
Restart=always
[Install]
WantedBy=multi-user.target