Commit 60729c49 authored by halcyon's avatar halcyon

bug

parent d0600662
...@@ -20,7 +20,7 @@ def log_list_online(request): ...@@ -20,7 +20,7 @@ def log_list_online(request):
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户' header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
web_socket_host = CONF.get('websocket', 'web_socket_host') web_socket_host = CONF.get('websocket', 'web_socket_host')
posts = Log.objects.filter(is_finished=0).order_by('-start_time') posts = Log.objects.filter(is_finished=0).order_by('-start_time')
contact_list, p, contacts = pages(posts, request) contact_list, p, contacts, page_range, current_page = pages(posts, request)
return render_to_response('jlog/log_online.html', locals()) return render_to_response('jlog/log_online.html', locals())
...@@ -29,7 +29,7 @@ def log_list_offline(request): ...@@ -29,7 +29,7 @@ def log_list_offline(request):
header_title, path1, path2 = u'查看日志', u'查看日志', u'历史记录' header_title, path1, path2 = u'查看日志', u'查看日志', u'历史记录'
web_socket_host = CONF.get('websocket', 'web_socket_host') web_socket_host = CONF.get('websocket', 'web_socket_host')
posts = Log.objects.filter(is_finished=1).order_by('-start_time') posts = Log.objects.filter(is_finished=1).order_by('-start_time')
contact_list, p, contacts = pages(posts, request) contact_list, p, contacts, page_range, current_page = pages(posts, request)
return render_to_response('jlog/log_offline.html', locals()) return render_to_response('jlog/log_offline.html', locals())
...@@ -60,10 +60,10 @@ def log_search(request): ...@@ -60,10 +60,10 @@ def log_search(request):
if env == 'online': if env == 'online':
posts = contact_list = Log.objects.filter(Q(user__contains=keyword) | Q(host__contains=keyword)) \ posts = contact_list = Log.objects.filter(Q(user__contains=keyword) | Q(host__contains=keyword)) \
.filter(is_finished=0).order_by('-start_time') .filter(is_finished=0).order_by('-start_time')
contact_list, p, contacts = pages(posts, request) contact_list, p, contacts, page_range, current_page = pages(posts, request)
elif env == 'offline': elif env == 'offline':
posts = contact_list = Log.objects.filter(Q(user__contains=keyword) | Q(host__contains=keyword)) \ posts = contact_list = Log.objects.filter(Q(user__contains=keyword) | Q(host__contains=keyword)) \
.filter(is_finished=1).order_by('-start_time') .filter(is_finished=1).order_by('-start_time')
contact_list, p, contacts = pages(posts, request) contact_list, p, contacts, page_range, current_page = pages(posts, request)
return render_to_response('jlog/log_search.html', locals()) return render_to_response('jlog/log_search.html', locals())
...@@ -56,40 +56,50 @@ def base(request): ...@@ -56,40 +56,50 @@ def base(request):
return render_to_response('base.html', context_instance=RequestContext(request)) return render_to_response('base.html', context_instance=RequestContext(request))
def get_data(data, items, option):
dic = {}
li_date, li_str = getDaysByNum(7)
for item in items:
li = []
name = item[option]
if option == 'user':
option_data = data.filter(user=name)
elif option == 'host':
option_data = data.filter(host=name)
for t in li_date:
year, month, day = t.year, t.month, t.day
times = option_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count()
li.append(times)
dic[name] = li
return dic
def index(request): def index(request):
path1, path2 = u'仪表盘', 'Dashboard' path1, path2 = u'仪表盘', 'Dashboard'
user_dic, host_dic = {}, {} users = User.objects.all()
hosts = Asset.objects.all()
online_host = Log.objects.filter(is_finished=0)
online_user = online_host.distinct()
li_date, li_str = getDaysByNum(7) li_date, li_str = getDaysByNum(7)
today = datetime.datetime.now().day today = datetime.datetime.now().day
from_week = datetime.datetime.now() - datetime.timedelta(days=7) from_week = datetime.datetime.now() - datetime.timedelta(days=7)
week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()]) week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()])
user_top_ten = week_data.values('user').annotate(times=Count('user')).order_by('-times')[:10] user_top_ten = week_data.values('user').annotate(times=Count('user')).order_by('-times')[:10]
host_top_ten = week_data.values('host').annotate(times=Count('host')).order_by('-times')[:10] host_top_ten = week_data.values('host').annotate(times=Count('host')).order_by('-times')[:10]
for user in user_top_ten: user_dic, host_dic = get_data(week_data, user_top_ten, 'user'), get_data(week_data, host_top_ten, 'host')
username = user['user']
li_user = [] top = {'user': '活跃用户数', 'host': '活跃主机数', 'times': '登录次数'}
user_data = week_data.filter(user=username) top_dic = {}
for t in li_date: for key, value in top.items():
year, month, day = t.year, t.month, t.day li = []
times = user_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count()
li_user.append(times)
user_dic[username] = li_user
for host in host_top_ten:
ip = host['host']
li_host = []
host_data = week_data.filter(host=ip)
for t in li_date: for t in li_date:
year, month, day = t.year, t.month, t.day year, month, day = t.year, t.month, t.day
times = host_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count() if key != 'times':
li_host.append(times) times = week_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).values(key).distinct().count()
host_dic[ip] = li_host else:
times = week_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count()
users = User.objects.all() li.append(times)
hosts = Asset.objects.all() top_dic[value] = li
online_host = Log.objects.filter(is_finished=0)
online_user = online_host.distinct()
top_dic = {'活跃用户数': [8, 10, 5, 9, 8, 12, 3], '活跃主机数': [10, 16, 20, 8, 9, 5, 9], '登录次数': [20, 30, 35, 18, 40, 38, 65]}
return render_to_response('index.html', locals(), context_instance=RequestContext(request)) return render_to_response('index.html', locals(), context_instance=RequestContext(request))
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
<!-- highcharts --> <!-- highcharts -->
<script src="/static/js/highcharts/highcharts.js"></script> <script src="/static/js/highcharts/highcharts.js"></script>
<script src="/static/js/highcharts/highstock.js"></script>
<!-- active menu --> <!-- active menu -->
<script> <script>
......
...@@ -107,6 +107,11 @@ $(function () { ...@@ -107,6 +107,11 @@ $(function () {
verticalAlign: 'middle', verticalAlign: 'middle',
borderWidth: 0 borderWidth: 0
}, },
navigation: {
buttonOptions: {
align: 'right'
}
},
series: [ series: [
{% for k,v in top_dic.items %} {% for k,v in top_dic.items %}
{ {
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
.bootstrap-dialog-message { .bootstrap-dialog-message {
background-color: rgba(0, 0, 0, 0); background-color: rgba(0, 0, 0, 0);
} }
.pre-class {
background-color: rgba(0, 0, 0, 1);
}
.modal-content { .modal-content {
background-color: rgba(0, 0, 0, 0.6); background-color: rgba(0, 0, 0, 0.6);
} }
...@@ -142,6 +145,7 @@ ...@@ -142,6 +145,7 @@
var username = $('#username')[0].innerText; var username = $('#username')[0].innerText;
var ip = $('#ip')[0].innerText; var ip = $('#ip')[0].innerText;
BootstrapDialog.show({message:function(){ BootstrapDialog.show({message:function(){
var option, exsit_message;
var escapeString = function (html){ var escapeString = function (html){
var elem = document.createElement('div') var elem = document.createElement('div')
var txt = document.createTextNode(html) var txt = document.createTextNode(html)
...@@ -152,14 +156,23 @@ ...@@ -152,14 +156,23 @@
//告诉服务器端有用户登录 //告诉服务器端有用户登录
socket.emit('login', {userid:message.id, filename:message.filename}); socket.emit('login', {userid:message.id, filename:message.filename});
socket.on('message',function(obj){ socket.on('message',function(obj){
option = obj.option;
console.log(option+'so')
exsit_message = obj.content;
console.log(obj.content)
//去除log中的颜色控制字符 //去除log中的颜色控制字符
var regx = /\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]/g; var regx = /\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]/g;
// tag.append('<p>'+escapeString(obj.content.replace(regx,''))+'</p>'); // tag.append('<p>'+escapeString(obj.content.replace(regx,''))+'</p>');
tag.append('<p>'+escapeString(obj.content)+'</p>'); if (option == 'new') {
tag.append('<p>' + escapeString(obj.content) + '</p>');
} else if (option == 'exist') {
tag.append('<p>' + exsit_message + '</p>');
}
tag.animate({ scrollTop: tag[0].scrollHeight}, 1); tag.animate({ scrollTop: tag[0].scrollHeight}, 1);
}); });
tag[0].style.color = "#00FF00"; tag[0].style.color = "#00FF00";
return tag[0]; return tag[0];
} , } ,
title:'Jumpserver实时监控 '+' 登录用户名: '+'<span class="text-info">'+username+'</span>'+' 登录主机: '+'<span class="text-info">'+ip, title:'Jumpserver实时监控 '+' 登录用户名: '+'<span class="text-info">'+username+'</span>'+' 登录主机: '+'<span class="text-info">'+ip,
onhide:function(){ onhide:function(){
......
...@@ -26,19 +26,29 @@ io.on('connection', function(socket){ ...@@ -26,19 +26,29 @@ io.on('connection', function(socket){
socket.name = obj.userid; socket.name = obj.userid;
socket.fileName = obj.filename; socket.fileName = obj.filename;
var tail = new Tail(obj.filename); var tail = new Tail(obj.filename);
//console.log(obj.filename);
//2015-03-06 当用户打开监控窗口时,会把已存在的文件内容打印出来
var fs = require('fs');
fs.readFile(obj.filename, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var existData = {userid:obj.userid,username:obj.username,content:data,option:'exist'};
socket.emit('message',existData);
});
tail.on('line',function(data) { tail.on('line',function(data) {
//console.log(data); //console.log(data);
var newData = {userid:obj.userid,username:obj.username,content:data}; var newData = {userid:obj.userid,username:obj.username,content:data,option:'new'};
socket.emit('message',newData); socket.emit('message',newData);
}); });
// var tail = spawn("tail", ['-f', obj.filename]); //var tail = spawn("tail", ['-f', obj.filename]);
// tail.stdout.on('data',function(data){ //tail.stdout.on('data',function(data){
// var content = data.toString(); // var content = data.toString();
// //console.log(content); // //console.log(content);
// var newData = {userid:obj.userid,username:obj.username,content:content}; // var newData = {userid:obj.userid,username:obj.username,content:content};
// socket.emit('message',newData); // socket.emit('message',newData);
// }); //});
socket.tail = tail; socket.tail = tail;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment