Begin implementing DB framework

This commit is contained in:
2022-09-27 15:15:08 +01:00
parent 845b02b0eb
commit 202a13cccb
21 changed files with 1316 additions and 968 deletions

View File

@@ -1,6 +1,5 @@
from django.conf import settings
from core.lib.opensearch import client, run_main_query
from core.lib.threshold import threshold_request
@@ -162,35 +161,6 @@ def construct_alert_query():
return query
def get_irc_alerts(user):
query = construct_alert_query()
results = run_main_query(
client,
user, # passed through run_main_query to filter_blacklisted
query,
custom_query=True,
index=settings.OPENSEARCH_INDEX_INT,
)
if not results:
return []
results_parsed = []
if "hits" in results.keys():
if "hits" in results["hits"]:
for item in results["hits"]["hits"]:
element = item["_source"]
element["id"] = item["_id"]
# Split the timestamp into date and time
ts = element["ts"]
ts_spl = ts.split("T")
date = ts_spl[0]
time = ts_spl[1]
element["date"] = date
element["time"] = time
results_parsed.append(element)
return results_parsed
def send_irc_message(net, num, channel, msg, nick=None):
url = f"irc/msg/{net}/{num}"
payload = {"msg": msg, "channel": channel}