Implement searching int events
This commit is contained in:
parent
83cd5e7ee7
commit
9a92429291
|
@ -1,17 +1,34 @@
|
||||||
def construct_query(net, channel, src, num, size):
|
def construct_query(index, net, channel, src, num, size):
|
||||||
# Get the initial query
|
# Get the initial query
|
||||||
extra_must = []
|
extra_must = []
|
||||||
if num:
|
if num:
|
||||||
extra_must.append({"match": {"num": num}})
|
extra_must.append({"match": {"num": num}})
|
||||||
|
if net:
|
||||||
|
extra_must.append({"match": {"net": net}})
|
||||||
|
if channel:
|
||||||
|
extra_must.append({"match": {"channel": channel}})
|
||||||
types = ["msg", "notice", "action", "kick", "topic", "mode"]
|
types = ["msg", "notice", "action", "kick", "topic", "mode"]
|
||||||
|
fields = [
|
||||||
|
"nick",
|
||||||
|
"ident",
|
||||||
|
"host",
|
||||||
|
"channel",
|
||||||
|
"ts",
|
||||||
|
"msg",
|
||||||
|
"type",
|
||||||
|
"net",
|
||||||
|
"src",
|
||||||
|
]
|
||||||
|
if index == "int":
|
||||||
|
fields.append("mtype")
|
||||||
|
query_should = [{"match": {"mtype": x}} for x in types]
|
||||||
|
else:
|
||||||
query_should = [{"match": {"type": x}} for x in types]
|
query_should = [{"match": {"type": x}} for x in types]
|
||||||
query = {
|
query = {
|
||||||
"size": size,
|
"size": size,
|
||||||
"query": {
|
"query": {
|
||||||
"bool": {
|
"bool": {
|
||||||
"must": [
|
"must": [
|
||||||
{"match": {"net": net}},
|
|
||||||
{"match": {"channel": channel}},
|
|
||||||
{"match": {"src": src}},
|
{"match": {"src": src}},
|
||||||
{
|
{
|
||||||
"bool": {
|
"bool": {
|
||||||
|
@ -22,17 +39,7 @@ def construct_query(net, channel, src, num, size):
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"fields": [
|
"fields": fields,
|
||||||
"nick",
|
|
||||||
"ident",
|
|
||||||
"host",
|
|
||||||
"channel",
|
|
||||||
"ts",
|
|
||||||
"msg",
|
|
||||||
"type",
|
|
||||||
"net",
|
|
||||||
"src",
|
|
||||||
],
|
|
||||||
"_source": False,
|
"_source": False,
|
||||||
}
|
}
|
||||||
return query
|
return query
|
||||||
|
|
|
@ -365,13 +365,15 @@ def query_results(request, query_params, size=None, annotate=True, custom_query=
|
||||||
|
|
||||||
if "index" in query_params:
|
if "index" in query_params:
|
||||||
index = query_params["index"]
|
index = query_params["index"]
|
||||||
|
print("INDEX IS HERE", index)
|
||||||
if index == "main":
|
if index == "main":
|
||||||
index = settings.OPENSEARCH_INDEX_MAIN
|
index = settings.OPENSEARCH_INDEX_MAIN
|
||||||
else:
|
else:
|
||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
if index == "meta":
|
if index == "meta":
|
||||||
|
print("INDEX IS META")
|
||||||
index = settings.OPENSEARCH_INDEX_META
|
index = settings.OPENSEARCH_INDEX_META
|
||||||
if index == "int":
|
elif index == "int":
|
||||||
index = settings.OPENSEARCH_INDEX_INT
|
index = settings.OPENSEARCH_INDEX_INT
|
||||||
else:
|
else:
|
||||||
message = "Index is not valid."
|
message = "Index is not valid."
|
||||||
|
@ -383,6 +385,7 @@ def query_results(request, query_params, size=None, annotate=True, custom_query=
|
||||||
return {"message": message, "class": message_class}
|
return {"message": message, "class": message_class}
|
||||||
else:
|
else:
|
||||||
index = settings.OPENSEARCH_INDEX_MAIN
|
index = settings.OPENSEARCH_INDEX_MAIN
|
||||||
|
print("RUNNING QUERY", index, search_query)
|
||||||
results = run_main_query(
|
results = run_main_query(
|
||||||
client,
|
client,
|
||||||
request.user, # passed through run_main_query to filter_blacklisted
|
request.user, # passed through run_main_query to filter_blacklisted
|
||||||
|
@ -405,6 +408,7 @@ def query_results(request, query_params, size=None, annotate=True, custom_query=
|
||||||
results_parsed = parse_results(results)
|
results_parsed = parse_results(results)
|
||||||
if annotate:
|
if annotate:
|
||||||
annotate_results(results_parsed)
|
annotate_results(results_parsed)
|
||||||
|
print("FNL", results_parsed)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"object_list": results_parsed,
|
"object_list": results_parsed,
|
||||||
|
|
|
@ -51,6 +51,7 @@ $(document).ready(function(){
|
||||||
"mtype": "off",
|
"mtype": "off",
|
||||||
"realname": "off",
|
"realname": "off",
|
||||||
"server": "off",
|
"server": "off",
|
||||||
|
"mtype": "off",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,23 +4,6 @@
|
||||||
<script src="{% static 'modal.js' %}"></script>
|
<script src="{% static 'modal.js' %}"></script>
|
||||||
<link rel ="stylesheet" href="{% static 'tabs.css' %}">
|
<link rel ="stylesheet" href="{% static 'tabs.css' %}">
|
||||||
<script src="{% static 'tabs.js' %}"></script>
|
<script src="{% static 'tabs.js' %}"></script>
|
||||||
|
|
||||||
<div class="modal-refresh"
|
|
||||||
style="display: none;"
|
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
|
||||||
hx-post="{% url 'modal_context_table' %}"
|
|
||||||
hx-vals='{"net": "{{ net }}",
|
|
||||||
"num": "{{ num }}",
|
|
||||||
"src": "{{ src }}",
|
|
||||||
"channel": "{{ channel }}",
|
|
||||||
"time": "{{ time }}",
|
|
||||||
"date": "{{ date }}",
|
|
||||||
"index": "{{ index }}"
|
|
||||||
}'
|
|
||||||
hx-target="#modal-context-table"
|
|
||||||
hx-trigger="every 5s">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("restore-modal-scroll", function(event) {
|
document.addEventListener("restore-modal-scroll", function(event) {
|
||||||
var modalContent = document.getElementsByClassName("modal-content")[0];
|
var modalContent = document.getElementsByClassName("modal-content")[0];
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in object_list %}
|
{% for item in object_list %}
|
||||||
{% if item.type == 'msg' %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ item.time }}</td>
|
<td>{{ item.time }}</td>
|
||||||
<td
|
<td
|
||||||
|
@ -13,11 +12,27 @@
|
||||||
data-tooltip="{{ item.nick }}!{{ item.ident }}@{{ item.host }}">{{ item.nick }}</td>
|
data-tooltip="{{ item.nick }}!{{ item.ident }}@{{ item.host }}">{{ item.nick }}</td>
|
||||||
<td class="wrap">{{ item.msg }}</td>
|
<td class="wrap">{{ item.msg }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</article>
|
</article>
|
||||||
|
{% if object_list %}
|
||||||
|
<div
|
||||||
|
class="modal-refresh"
|
||||||
|
style="display: none;"
|
||||||
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
hx-post="{% url 'modal_context_table' %}"
|
||||||
|
hx-vals='{"net": "{{ net }}",
|
||||||
|
"num": "{{ num }}",
|
||||||
|
"src": "{{ src }}",
|
||||||
|
"channel": "{{ channel }}",
|
||||||
|
"time": "{{ time }}",
|
||||||
|
"date": "{{ date }}",
|
||||||
|
"index": "{{ index }}"}'
|
||||||
|
hx-target="#modal-context-table"
|
||||||
|
hx-trigger="every 5s">
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<script>
|
<script>
|
||||||
var modal_event = new Event('restore-modal-scroll');
|
var modal_event = new Event('restore-modal-scroll');
|
||||||
document.dispatchEvent(modal_event);
|
document.dispatchEvent(modal_event);
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
{% load joinsep %}
|
{% load joinsep %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if params.modal == 'context' %}
|
{% if params.modal == 'context' %}
|
||||||
<div style="display: none;"
|
<div
|
||||||
|
style="display: none;"
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-post="{% url 'modal_context' %}"
|
hx-post="{% url 'modal_context' %}"
|
||||||
hx-vals='{"net": "{{ params.net|escapejs }}",
|
hx-vals='{"net": "{{ params.net|escapejs }}",
|
||||||
|
@ -12,8 +13,7 @@
|
||||||
"channel": "{{ params.channel|escapejs }}",
|
"channel": "{{ params.channel|escapejs }}",
|
||||||
"time": "{{ params.time|escapejs }}",
|
"time": "{{ params.time|escapejs }}",
|
||||||
"date": "{{ params.date|escapejs }}",
|
"date": "{{ params.date|escapejs }}",
|
||||||
"index": "{{ params.index }}"
|
"index": "{{ params.index }}"}'
|
||||||
}'
|
|
||||||
hx-target="#modals-here"
|
hx-target="#modals-here"
|
||||||
hx-trigger="load">
|
hx-trigger="load">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -213,7 +213,8 @@
|
||||||
</td>
|
</td>
|
||||||
{% elif column.name == 'msg' %}
|
{% elif column.name == 'msg' %}
|
||||||
<td class="{{ column.name }} wrap" style="max-width: 10em">
|
<td class="{{ column.name }} wrap" style="max-width: 10em">
|
||||||
<a class="has-text-grey is-underlined"
|
<a
|
||||||
|
class="has-text-grey is-underlined"
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-post="{% url 'modal_context' %}"
|
hx-post="{% url 'modal_context' %}"
|
||||||
hx-vals='{"net": "{{ row.cells.net|escapejs }}",
|
hx-vals='{"net": "{{ row.cells.net|escapejs }}",
|
||||||
|
@ -222,8 +223,7 @@
|
||||||
"channel": "{{ row.cells.channel|escapejs }}",
|
"channel": "{{ row.cells.channel|escapejs }}",
|
||||||
"time": "{{ row.cells.time|escapejs }}",
|
"time": "{{ row.cells.time|escapejs }}",
|
||||||
"date": "{{ row.cells.date|escapejs }}",
|
"date": "{{ row.cells.date|escapejs }}",
|
||||||
"index": "{{ params.index }}"
|
"index": "{{ params.index }}"}'
|
||||||
}'
|
|
||||||
hx-target="#modals-here"
|
hx-target="#modals-here"
|
||||||
hx-trigger="click">
|
hx-trigger="click">
|
||||||
{{ row.cells.msg }}
|
{{ row.cells.msg }}
|
||||||
|
|
|
@ -243,41 +243,29 @@ class DrilldownContextModal(APIView):
|
||||||
if request.resolver_match.url_name == "modal_context_table":
|
if request.resolver_match.url_name == "modal_context_table":
|
||||||
print("POST CONTEXT TABLE")
|
print("POST CONTEXT TABLE")
|
||||||
self.template_name = "modals/context_table.html"
|
self.template_name = "modals/context_table.html"
|
||||||
# if not request.user.has_plan(self.plan_name):
|
|
||||||
# return JsonResponse({"success": False})
|
|
||||||
num = None
|
|
||||||
index = "main"
|
|
||||||
size = 20
|
size = 20
|
||||||
# Check right fields exist
|
|
||||||
if "net" not in request.data:
|
|
||||||
return JsonResponse({"success": False})
|
|
||||||
if "channel" not in request.data:
|
|
||||||
return JsonResponse({"success": False})
|
|
||||||
if "src" not in request.data:
|
|
||||||
return JsonResponse({"success": False})
|
|
||||||
if "time" not in request.data:
|
|
||||||
return JsonResponse({"success": False})
|
|
||||||
if "date" not in request.data:
|
|
||||||
return JsonResponse({"success": False})
|
|
||||||
if "num" in request.data:
|
|
||||||
if request.data["num"]:
|
|
||||||
if not request.data["num"] == "—":
|
|
||||||
num = request.data["num"]
|
|
||||||
if "index" in request.data:
|
|
||||||
if request.data["index"]:
|
|
||||||
index = request.data["index"]
|
|
||||||
net = request.data["net"]
|
|
||||||
channel = request.data["channel"]
|
|
||||||
# Create the query params from the POST arguments
|
# Create the query params from the POST arguments
|
||||||
blacklisted = ["date", "time"]
|
mandatory = ["net", "channel", "num", "src", "index"]
|
||||||
query_params = {
|
invalid = [None, False, "—", "None"]
|
||||||
k: v for k, v in request.data.items() if v and k not in blacklisted
|
query_params = {k: v for k, v in request.data.items() if v}
|
||||||
}
|
for key in query_params:
|
||||||
|
if query_params[key] in invalid:
|
||||||
|
query_params[key] = None
|
||||||
|
for key in mandatory:
|
||||||
|
if key not in query_params:
|
||||||
|
query_params[key] = None
|
||||||
query_params["sorting"] = "desc"
|
query_params["sorting"] = "desc"
|
||||||
|
|
||||||
# Create the query with the context helper
|
# Create the query with the context helper
|
||||||
search_query = construct_query(net, channel, request.data["src"], num, size)
|
search_query = construct_query(
|
||||||
print("SEARCH QUERY", search_query)
|
query_params["index"],
|
||||||
|
query_params["net"],
|
||||||
|
query_params["channel"],
|
||||||
|
query_params["src"],
|
||||||
|
query_params["num"],
|
||||||
|
size,
|
||||||
|
)
|
||||||
results = query_results(
|
results = query_results(
|
||||||
request, query_params, annotate=True, custom_query=search_query
|
request, query_params, annotate=True, custom_query=search_query
|
||||||
)
|
)
|
||||||
|
@ -290,19 +278,18 @@ class DrilldownContextModal(APIView):
|
||||||
# results["object_list"][index]["time"] = item["time"]+"SSS"
|
# results["object_list"][index]["time"] = item["time"]+"SSS"
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"net": net,
|
"net": query_params["net"],
|
||||||
"channel": channel,
|
"channel": query_params["channel"],
|
||||||
"src": request.data["src"],
|
"src": query_params["src"],
|
||||||
"ts": f"{request.data['date']} {request.data['time']}",
|
"ts": f"{query_params['date']} {query_params['time']}",
|
||||||
"object_list": results["object_list"],
|
"object_list": results["object_list"],
|
||||||
"time": request.data["time"],
|
"time": query_params["time"],
|
||||||
"date": request.data["date"],
|
"date": query_params["date"],
|
||||||
"index": request.data["date"],
|
"index": query_params["index"],
|
||||||
|
"num": query_params["num"],
|
||||||
}
|
}
|
||||||
if index:
|
print("CONTEXT", context)
|
||||||
context["index"] = index
|
|
||||||
if num:
|
|
||||||
context["num"] = num
|
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,5 +64,6 @@ class DrilldownTable(Table):
|
||||||
mtype = Column()
|
mtype = Column()
|
||||||
realname = Column()
|
realname = Column()
|
||||||
server = Column()
|
server = Column()
|
||||||
|
mtype = Column()
|
||||||
template_name = "ui/drilldown/table_results.html"
|
template_name = "ui/drilldown/table_results.html"
|
||||||
paginate_by = settings.DRILLDOWN_RESULTS_PER_PAGE
|
paginate_by = settings.DRILLDOWN_RESULTS_PER_PAGE
|
||||||
|
|
Loading…
Reference in New Issue