-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Logging View #1080
Add Logging View #1080
Changes from 40 commits
dba3552
7fc743a
04e87fa
f690f75
eab0061
b231a1a
d424386
080174e
0b9115f
837ca01
a16e0ed
91703b1
56e8a8b
079c4f1
b3ae4f1
4c7879f
46b6e24
37c72a9
a4239fe
8687faa
4b08f9b
7779dcd
c79651a
54a6508
e9bc7ca
4568856
c3b51d9
ea7fe55
d268372
a367547
3d7432f
41a4e88
958d0cb
878ed44
cbdc7d0
d47bb00
d167cf8
e5972aa
22fd5ac
27fa941
33470c2
152b850
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block preamble %} | ||
|
||
<title>Monitor Log Viewer - JWQL</title> | ||
|
||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<main role="main" class="container"> | ||
<h2>Explore JWQL monitoring logs through the web browser.</h2><hr> | ||
|
||
<p align="justify"> | ||
This page allows users to load monitoring logs into the web browsers. This feature | ||
obtains logs from all JWQL servers (ops, dev, and test). | ||
|
||
<br><br> | ||
</p> | ||
|
||
<hr> | ||
<form action="" method="post" id="logForm"> | ||
{{ csrf_input }} | ||
|
||
<!--LOG SELECT DROPDOWN--> | ||
<h4>Select JWQL Monitoring Log</h4> | ||
<div class="col-6 mx-auto text-left mt-5"> | ||
<input id="log_select" type="text" list="logs" placeholder="Log Name" class="form-control"> | ||
<datalist id="logs"> | ||
{% for log_name in all_logs %} | ||
<option id="{{ log_name }}" value="{{ log_name }}"></option> | ||
{% endfor %} | ||
</datalist> | ||
</div> | ||
|
||
<br> | ||
|
||
<button id="log_submit" name="log_submit" class="btn btn-primary" onclick="GetSelectedTextValue()" type="submit" style="float: left;" disabled>Submit</button> | ||
<br><br><br> | ||
|
||
<!-- If log is passed, render log. --> | ||
<!-- Log is not rendered when coming from home/monitor views --> | ||
{% if log_text %} | ||
<h4> {{ log_name|safe }} </h4><hr> | ||
<!-- Show Logs here --> | ||
<pre> | ||
{{ log_text }} | ||
</pre> | ||
{% endif %} | ||
|
||
<script type="text/javascript"> | ||
function GetSelectedTextValue() { | ||
var log_value = document.getElementById("log_select").value; | ||
document.getElementById("log_submit").value = log_value; | ||
} | ||
</script> | ||
|
||
<script type="text/javascript"> | ||
const idInputField = document.getElementById('log_select'); | ||
var logsList = document.getElementById("logs"); | ||
idInputField.addEventListener('input', function () { | ||
if (logsList.options.namedItem(this.value) != null) { | ||
document.getElementById("log_submit").disabled = false; | ||
} else { | ||
document.getElementById("log_submit").disabled = true; | ||
} | ||
}); | ||
</script> | ||
|
||
</form> | ||
</main> | ||
|
||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
from collections import defaultdict | ||
from copy import deepcopy | ||
import csv | ||
import glob | ||
import logging | ||
import os | ||
import operator | ||
|
@@ -746,6 +747,50 @@ def jwqldb_table_viewer(request, tablename_param=None): | |
return render(request, template, context) | ||
|
||
|
||
def log_view(request): | ||
"""Access JWQL monitoring logs from the web app. | ||
|
||
Parameters | ||
---------- | ||
request : HttpRequest object | ||
Incoming request from the webpage | ||
|
||
Returns | ||
------- | ||
HttpResponse object | ||
Outgoing response sent to the webpage | ||
""" | ||
|
||
template = 'log_view.html' | ||
log_path = get_config()['log_dir'] | ||
log_name = request.POST.get('log_submit', None) | ||
|
||
full_uri = request.build_absolute_uri() | ||
|
||
if 'dljwql' in full_uri: | ||
server = 'dev' | ||
elif 'tljwql' in full_uri: | ||
server = 'test' | ||
else: | ||
server = 'ops' | ||
|
||
full_log_paths = sorted(glob.glob(os.path.join(log_path, server, '*', '*')), reverse=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you may need more tests to verify you are on the correct server. "pljwql" is showing up on the test server. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went ahead and used a different library for this portion of the app. I have it working successfully now! |
||
full_log_paths = [log for log in full_log_paths if not os.path.basename(log).startswith('.')] | ||
log_dictionary = {os.path.basename(path): path for path in full_log_paths} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dictionary comprehension! I had forgotten that was a thing. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was super useful here. |
||
|
||
if log_name: | ||
with open(log_dictionary[log_name]) as f: | ||
log_text = f.read() | ||
else: | ||
log_text = None | ||
|
||
context = {'inst': '', | ||
'all_logs': log_dictionary, | ||
'log_text': log_text, | ||
'log_name': log_name} | ||
|
||
return render(request, template, context) | ||
|
||
def not_found(request, *kwargs): | ||
"""Generate a ``not_found`` page | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this is something that would be useful to have as its own general function somewhere, or is there not enough use for it to warrant a separate function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this was causing the issue with the production logs being show on the test server. I went ahead and changed it to use the
socket
library to get the hostname of the machine rather than the URL.