pull/6/head
root 10 years ago
parent bbe5b588c0
commit e086a03692

@ -2,6 +2,8 @@
import django
import os
import sys
import random
import datetime
sys.path.append('../')
os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings'
@ -12,6 +14,7 @@ from jasset.models import Asset, IDC, BisGroup
from juser.models import UserGroup
from jasset.views import jasset_group_add
from jperm.models import CmdGroup
from jlog.models import Log
def test_add_idc():
@ -72,6 +75,25 @@ def test_add_asset():
print "Add: %s" % ip
def test_add_log():
li_date = []
today = datetime.date.today()
oneday = datetime.timedelta(days=1)
for i in range(0, 7):
today = today-oneday
li_date.append(today)
user_list = ['马云', '马化腾', '丁磊', '周鸿祎', '雷军', '柳传志', '陈天桥', '李彦宏', '李开复', '罗永浩']
for i in range(1, 1000):
user = random.choice(user_list)
ip = random.randint(1, 20)
start_time = random.choice(li_date)
end_time = datetime.datetime.now()
log_path = '/var/log/jumpserver/test.log'
host = '192.168.1.' + str(ip)
Log.objects.create(user=user, host=host, log_path=log_path, pid=168, start_time=start_time,
is_finished=1, log_finished=1, end_time=end_time)
if __name__ == '__main__':
test_add_idc()
test_add_asset_group()
@ -79,6 +101,7 @@ if __name__ == '__main__':
test_add_cmd_group()
test_add_asset()
test_add_user()
test_add_log()

@ -50,7 +50,7 @@ def f_add_host(ip, port, idc, jtype, group, active, comment, username='', passwo
def add_host(request):
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
header_title, path1, path2 = u'添加主机 | Add Host', u'资产管理', u'添加主机'
header_title, path1, path2 = u'添加主机', u'资产管理', u'添加主机'
eidc = IDC.objects.all()
egroup = BisGroup.objects.filter(type='A')
eusergroup = UserGroup.objects.all()
@ -80,7 +80,7 @@ def add_host(request):
def add_host_multi(request):
header_title, path1, path2 = u'批量添加主机 | Add Hosts', u'资产管理', u'批量添加主机'
header_title, path1, path2 = u'批量添加主机', u'资产管理', u'批量添加主机'
login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
j_group = []
if request.method == 'POST':
@ -141,7 +141,7 @@ def batch_host_edit(request):
def list_host(request):
header_title, path1, path2 = u'查看主机 | List Host', u'资产管理', u'查看主机'
header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
posts = contact_list = Asset.objects.all().order_by('ip')
p = paginator = Paginator(contact_list, 10)
@ -181,7 +181,7 @@ def host_del(request, offset):
def host_edit(request):
actives = {1: u'激活', 0: u'禁用'}
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
header_title, path1, path2 = u'修改主机 | Edit Host', u'资产管理', u'修改主机'
header_title, path1, path2 = u'修改主机', u'资产管理', u'修改主机'
groups, e_group = [], []
eidc = IDC.objects.all()
egroup = BisGroup.objects.filter(type='A')
@ -232,7 +232,7 @@ def host_edit(request):
def jlist_ip(request, offset):
header_title, path1, path2 = u'主机详细信息 | Host Detail.', u'资产管理', u'主机详情'
header_title, path1, path2 = u'主机详细信息', u'资产管理', u'主机详情'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
post = contact_list = Asset.objects.get(ip=str(offset))
log = Log.objects.filter(host=str(offset))
@ -240,7 +240,7 @@ def jlist_ip(request, offset):
def add_idc(request):
header_title, path1, path2 = u'添加IDC | Add IDC', u'资产管理', u'添加IDC'
header_title, path1, path2 = u'添加IDC', u'资产管理', u'添加IDC'
if request.method == 'POST':
j_idc = request.POST.get('j_idc')
j_comment = request.POST.get('j_comment')
@ -255,7 +255,7 @@ def add_idc(request):
def list_idc(request):
header_title, path1, path2 = u'查看IDC | List IDC', u'资产管理', u'查看IDC'
header_title, path1, path2 = u'查看IDC', u'资产管理', u'查看IDC'
posts = IDC.objects.all().order_by('id')
return render_to_response('jasset/idc_list.html', locals(), context_instance=RequestContext(request))
@ -266,7 +266,7 @@ def del_idc(request, offset):
def add_group(request):
header_title, path1, path2 = u'添加主机组 | Add Group', u'资产管理', u'添加主机组'
header_title, path1, path2 = u'添加主机组', u'资产管理', u'添加主机组'
posts = Asset.objects.all()
if request.method == 'POST':
j_group = request.POST.get('j_group')
@ -288,13 +288,13 @@ def add_group(request):
def list_group(request):
header_title, path1, path2 = u'查看主机组 | List Group', u'资产管理', u'查看主机组'
header_title, path1, path2 = u'查看主机组', u'资产管理', u'查看主机组'
posts = BisGroup.objects.filter(type='A').order_by('id')
return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request))
def edit_group(request):
header_title, path1, path2 = u'编辑主机组 | Edit Group', u'资产管理', u'编辑主机组'
header_title, path1, path2 = u'编辑主机组', u'资产管理', u'编辑主机组'
group_id = request.GET.get('id')
group = BisGroup.objects.get(id=group_id)
all = Asset.objects.all()
@ -317,7 +317,7 @@ def edit_group(request):
def detail_group(request):
header_title, path1, path2 = u'主机组详情 | Group Detail', u'资产管理', u'主机组详情'
header_title, path1, path2 = u'主机组详情', u'资产管理', u'主机组详情'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
offset = request.GET.get('id')
group_name = BisGroup.objects.get(id=offset).name
@ -337,7 +337,7 @@ def detail_group(request):
def detail_idc(request):
header_title, path1, path2 = u'主机组详情 | Group Detail', u'资产管理', u'主机组详情'
header_title, path1, path2 = u'主机组详情', u'资产管理', u'主机组详情'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
offset = request.GET.get('id')
idc_name = IDC.objects.get(id=offset).name

@ -17,7 +17,7 @@ CONF.read('%s/jumpserver.conf' % BASE_DIR)
def log_list_online(request):
header_title, path1, path2 = u'查看日志 | Log List.', u'查看日志', u'在线用户'
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
web_socket_host = CONF.get('websocket', 'web_socket_host')
posts = Log.objects.filter(is_finished=0).order_by('-start_time')
contact_list, p, contacts = pages(posts, request)
@ -26,7 +26,7 @@ def log_list_online(request):
def log_list_offline(request):
header_title, path1, path2 = u'查看日志 | Log List.', u'查看日志', u'历史记录'
header_title, path1, path2 = u'查看日志', u'查看日志', u'历史记录'
web_socket_host = CONF.get('websocket', 'web_socket_host')
posts = Log.objects.filter(is_finished=1).order_by('-start_time')
contact_list, p, contacts = pages(posts, request)

@ -58,21 +58,33 @@ def base(request):
def index(request):
path1, path2 = u'仪表盘', 'Dashboard'
dic = {}
user_dic, host_dic = {}, {}
li_date, li_str = getDaysByNum(7)
today = datetime.datetime.now().day
from_week = datetime.datetime.now() - datetime.timedelta(days=7)
week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()])
top_ten = week_data.values('user').annotate(times=Count('user')).order_by('-times')[:10]
for user in top_ten:
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]
for user in user_top_ten:
username = user['user']
li = []
li_user = []
user_data = week_data.filter(user=username)
for t in li_date:
year, month, day = t.year, t.month, t.day
times = user_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count()
li.append(times)
dic[username] = li
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:
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()
li_host.append(times)
host_dic[ip] = li_host
users = User.objects.all()
hosts = Asset.objects.all()
online_host = Log.objects.filter(is_finished=0)

@ -58,16 +58,17 @@
</div>
</div>
</div>
<div id="high" style="width:100%;height:400px;"></div>
<div id="usertop10" style="width:100%;height:400px;"></div>
<div id="hosttop10" style="width:100%;height:400px; margin-top:170px"></div>
</br>
<div id="dynamic" style="width:100%;height:400px; margin-top:170px"></div>
<div id="dynamic" style="width:100%;height:400px;"></div>
</div>
</div>
<script>
var cate = {{ li_str|safe }};
$(function () {
$('#high').highcharts({
$('#usertop10').highcharts({
title: {
text: '一周用户登录TOP10',
x: -20 //center
@ -101,7 +102,7 @@ $(function () {
borderWidth: 0
},
series: [
{% for k,v in dic.items %}
{% for k,v in user_dic.items %}
{
name: '{{ k }}',
data: {{ v }}
@ -110,6 +111,50 @@ $(function () {
]
});
$('#hosttop10').highcharts({
title: {
text: '一周主机登录TOP10',
x: -20 //center
},
subtitle: {
text: 'Source: JumpServer',
x: -20
},
xAxis: {
type: 'datetime',
categories: cate
},
yAxis:{
min: 0,
title: {
text: '登录次数'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '次'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [
{% for k,v in host_dic.items %}
{
name: '{{ k }}',
data: {{ v }}
},
{% endfor %}
]
});
$(document).ready(function() {
Highcharts.setOptions({
global: {

@ -62,7 +62,7 @@
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
<td class="text-center" data-editable='false'>
<a href="/jasset/?id={{ post.ip }}/" class="iframe btn btn-xs btn-primary">详情</a>
<a value="/jasset/{{ post.ip }}/" class="iframe btn btn-xs btn-primary">详情</a>
<a href="/jasset/host_del/{{ post.id }}" class="btn btn-xs btn-danger">删除</a>
</td>
</tr>
@ -119,6 +119,21 @@
$('#editable').editableTableWidget();
});
$(".iframe").on('click', function(){
var url= $(this).attr("value");
$.layer({
type: 2,
title: 'JumpServer主机详情',
maxmin: true,
shift: 'top',
border: [2, 0.3, '#1AB394'],
shade: [0.5, '#000000'],
shadeClose: true,
area : ['800px' , '600px'],
iframe: {src: url}
});
});
function alter(form) {
selectData = GetTableDataBox();
if (selectData[1] != 0) {

Loading…
Cancel
Save