Added config reader, added config file and move hooks to a function, rename send function to smp specific

This commit is contained in:
2026-05-02 12:27:22 +02:00
parent b521ae2ba2
commit 342da10dbb
2 changed files with 30 additions and 9 deletions

View File

@@ -1,2 +1,4 @@
--- ---
2345555XE: "#Bottest" 2345555XE:
transport: "simplex"
target: "#Bottest"

View File

@@ -6,6 +6,7 @@ import yaml
import random import random
import logging import logging
import os import os
import os.path
from pprint import pprint from pprint import pprint
__version__ = "2.2.0" __version__ = "2.2.0"
@@ -28,11 +29,21 @@ app = Flask(__name__)
# socket.connect("tcp://localhost:5555") # socket.connect("tcp://localhost:5555")
hooks = {} hooks = {}
with open(r'/etc/tellme/hooks.yml') as hooksfile: config = {}
def read_configs():
global hooks
with open(r'/etc/tellme/hooks.yml') as hooksfile:
hooks = yaml.load(hooksfile, Loader=yaml.FullLoader) hooks = yaml.load(hooksfile, Loader=yaml.FullLoader)
if os.path.isfile('/etc/tellme/config.yml'):
with open(r'/etc/tellme/config.yml') as configfile:
config = yaml.load(configfile, Loader=yaml.FullLoader)
def sendmessage(target, message):
def send_smp_message(target, message):
# global socket # global socket
msg = ("%s %s" % (target, message)) msg = ("%s %s" % (target, message))
@@ -60,6 +71,15 @@ def sendmessage(target, message):
return False return False
def get(hook_id)
target = None
for key, value in hooks.items():
if str(key) == str(id):
target = value
return target
@app.route("/webhook/<id>", methods=['POST']) @app.route("/webhook/<id>", methods=['POST'])
def webhook_receiver(id): def webhook_receiver(id):
log.info("Webhook id %s" % (id)) log.info("Webhook id %s" % (id))
@@ -89,15 +109,13 @@ def webhook_receiver(id):
if type == 'AlertStatus': if type == 'AlertStatus':
message = ("Alert %s: %s" % (data.get('AlertID'), data.get('LogEntry'))) message = ("Alert %s: %s" % (data.get('AlertID'), data.get('LogEntry')))
target = None hook = get_hook(id)
for key, value in hooks.items():
if str(key) == str(id):
target = value
target = hook.get('target')
if target is not None: if target is not None:
log.info(target) log.info(target)
if message is not None: if message is not None:
sendmessage(target, message) send_smp_message(target, message)
else: else:
log.error("No message, dropping") log.error("No message, dropping")
else: else:
@@ -108,4 +126,5 @@ def webhook_receiver(id):
if __name__ == '__main__': if __name__ == '__main__':
log.info("Started %s" % (versionstring)) log.info("Started %s" % (versionstring))
read_configs()
app.run() app.run()