1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

instance view: added logs section to graphs (renamed graphs -> stats)

This commit is contained in:
Ing. Jan KRCMAR 2017-12-11 15:07:01 +01:00
parent fdca3cef9c
commit 839b8d420d
3 changed files with 69 additions and 6 deletions

View file

@ -84,8 +84,8 @@
</li> </li>
<li role="presentation"> <li role="presentation">
<a href="#graphics" id="chartgraphs" class="action-button" aria-controls="graphics" role="tab" data-toggle="tab"> <a href="#graphics" id="chartgraphs" class="action-button" aria-controls="graphics" role="tab" data-toggle="tab">
<span id="action-block" class="glyphicon glyphicon-signal" aria-hidden="true"></span> <span id="action-block" class="glyphicon glyphicon-stats" aria-hidden="true"></span>
{% trans "Graphs" %} {% trans "Stats" %}
</a> </a>
</li> </li>
<li role="presentation"> <li role="presentation">
@ -1043,6 +1043,11 @@
{% trans "Real Time" %} {% trans "Real Time" %}
</a> </a>
</li> </li>
<li role="presentation">
<a href="#logs" aria-controls="logs" role="tab" data-toggle="tab" onclick='update_logs_table("{{ vname }}");'>
{% trans "Logs" %}
</a>
</li>
</ul> </ul>
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
@ -1089,6 +1094,23 @@
{% endfor %} {% endfor %}
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="logs">
<div class="table-responsive">
<table class="table table-striped sortable-theme-bootstrap" id="logs_table" data-sortable>
<thead>
<tr>
<th>{% trans "Date" %}</th>
<th>{% trans "User" %}</th>
<th>{% trans "Message" %}</th>
</tr>
</thead>
<tbody class="searchable">
<tr><td colspan="3"><i>None ...</i></td></tr>
</tbody>
</table>
</div>
<div class="clearfix"></div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -1467,4 +1489,19 @@
}); });
} }
</script> </script>
<script>
function update_logs_table(vname) {
$.getJSON('/logs/vm_logs/'+vname+'/', function(data) {
var logs = "";
$.each(data, function(id) {
row = data[id];
console.log(row);
logs += '<tr><td style="width:150px">'+row['date']+'</td>';
logs += '<td>'+row['user']+'</td>';
logs += '<td>'+row['message']+'</td></tr>';
});
$("#logs_table > tbody").html(logs);
});
}
</script>
{% endblock %} {% endblock %}

View file

@ -4,4 +4,5 @@ from . import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.showlogs, name='showlogs'), url(r'^$', views.showlogs, name='showlogs'),
url(r'^(?P<page>[0-9]+)/$', views.showlogs, name='showlogspage'), url(r'^(?P<page>[0-9]+)/$', views.showlogs, name='showlogspage'),
url(r'^vm_logs/(?P<vname>[\w\-\.]+)/$', views.vm_logs, name='vm_logs'),
] ]

View file

@ -1,8 +1,11 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from instances.models import Instance
from logs.models import Logs from logs.models import Logs
from django.conf import settings from django.conf import settings
import json
def addlogmsg(user, instance, message): def addlogmsg(user, instance, message):
@ -14,15 +17,13 @@ def addlogmsg(user, instance, message):
add_log_msg.save() add_log_msg.save()
@login_required
def showlogs(request, page=1): def showlogs(request, page=1):
""" """
:param request: :param request:
:return: :return:
""" """
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser: if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index')) return HttpResponseRedirect(reverse('index'))
@ -34,3 +35,27 @@ def showlogs(request, page=1):
# TODO: remove last element from queryset, but do not affect database # TODO: remove last element from queryset, but do not affect database
return render(request, 'showlogs.html', locals()) return render(request, 'showlogs.html', locals())
@login_required
def vm_logs(request, vname):
"""
:param request:
:param vm:
:return:
"""
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
vm = Instance.objects.get(name=vname)
logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by('-date')
logs = []
for l in logs_:
log = {}
log['user'] = l.user
log['instance'] = l.instance
log['message'] = l.message
log['date'] = l.date.strftime('%x %X')
logs.append(log)
return HttpResponse(json.dumps(logs))