Added config reader, added config file and move hooks to a function, rename send function to smp specific
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
---
|
||||
2345555XE: "#Bottest"
|
||||
2345555XE:
|
||||
transport: "simplex"
|
||||
target: "#Bottest"
|
||||
|
||||
@@ -6,6 +6,7 @@ import yaml
|
||||
import random
|
||||
import logging
|
||||
import os
|
||||
import os.path
|
||||
from pprint import pprint
|
||||
|
||||
__version__ = "2.2.0"
|
||||
@@ -28,11 +29,21 @@ app = Flask(__name__)
|
||||
# socket.connect("tcp://localhost:5555")
|
||||
|
||||
hooks = {}
|
||||
config = {}
|
||||
|
||||
|
||||
def read_configs():
|
||||
global hooks
|
||||
|
||||
with open(r'/etc/tellme/hooks.yml') as hooksfile:
|
||||
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
|
||||
|
||||
msg = ("%s %s" % (target, message))
|
||||
@@ -60,6 +71,15 @@ def sendmessage(target, message):
|
||||
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'])
|
||||
def webhook_receiver(id):
|
||||
log.info("Webhook id %s" % (id))
|
||||
@@ -89,15 +109,13 @@ def webhook_receiver(id):
|
||||
if type == 'AlertStatus':
|
||||
message = ("Alert %s: %s" % (data.get('AlertID'), data.get('LogEntry')))
|
||||
|
||||
target = None
|
||||
for key, value in hooks.items():
|
||||
if str(key) == str(id):
|
||||
target = value
|
||||
hook = get_hook(id)
|
||||
|
||||
target = hook.get('target')
|
||||
if target is not None:
|
||||
log.info(target)
|
||||
if message is not None:
|
||||
sendmessage(target, message)
|
||||
send_smp_message(target, message)
|
||||
else:
|
||||
log.error("No message, dropping")
|
||||
else:
|
||||
@@ -108,4 +126,5 @@ def webhook_receiver(id):
|
||||
|
||||
if __name__ == '__main__':
|
||||
log.info("Started %s" % (versionstring))
|
||||
read_configs()
|
||||
app.run()
|
||||
|
||||
Reference in New Issue
Block a user