Compare commits
46 Commits
4801b74405
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b95b776418 | |||
| b6e11f148f | |||
| a9e4febaa5 | |||
| 25b17f93fc | |||
| e9f57dd3f9 | |||
| 845c937d80 | |||
| ecb2429a0d | |||
| 5509f5e177 | |||
| 73592dd53e | |||
| f92a44b5c1 | |||
| a969b950d1 | |||
| 6bedd576be | |||
| fbfc7d9992 | |||
| 040bd08503 | |||
| 90d50084a7 | |||
| 7af2455cb6 | |||
| fd0e386792 | |||
| 0595649afe | |||
| 7532b2a064 | |||
| 8fa91e5e5f | |||
| e364c7d965 | |||
| 62e7468eb2 | |||
| 50a721267a | |||
| 84394cb3b8 | |||
| 3bba7a51f3 | |||
| 5ee659c376 | |||
| e3b6d650b8 | |||
| 1b68889ac5 | |||
| 6529e1b88b | |||
| a529e1eb53 | |||
| a3010018d4 | |||
| 50ef25c129 | |||
| ee6bb28f6a | |||
| 3847d2ea96 | |||
| 958b51ba40 | |||
| 2302e9b166 | |||
| 068af17935 | |||
| e28d653921 | |||
| 2e9520d3cd | |||
| 150c03b05a | |||
| 761536274b | |||
| 26b6b4cd98 | |||
| f3ef9e55d5 | |||
| 06744aa5c7 | |||
| 38d9e87393 | |||
| 48791ee1f1 |
3
Ansible/tellme_notification/defaults/main.yml
Normal file
3
Ansible/tellme_notification/defaults/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
tellme_url: https://
|
||||
tellme_webhook: 123
|
||||
11
Ansible/tellme_notification/tasks/main.yml
Normal file
11
Ansible/tellme_notification/tasks/main.yml
Normal 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
5
server/Changelog
Normal 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
14
server/package.json
Normal 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
80
server/src/notifier.py
Normal 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")
|
||||
@@ -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()
|
||||
|
||||
12
server/tellme_notifier.service
Normal file
12
server/tellme_notifier.service
Normal 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
|
||||
Reference in New Issue
Block a user