Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
0174da6c
Commit
0174da6c
authored
Nov 10, 2015
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改index页面
parent
adc3703f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
195 additions
and
93 deletions
+195
-93
views.py
jumpserver/views.py
+53
-73
index.html
templates/index.html
+142
-20
No files found.
jumpserver/views.py
View file @
0174da6c
...
...
@@ -36,42 +36,44 @@ def getDaysByNum(num):
return
date_li
,
date_str
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
get_data
(
x
,
y
,
z
):
pass
def
get_
count
_by_day
(
date_li
,
item
):
def
get_
data
_by_day
(
date_li
,
item
):
data_li
=
[]
for
d
in
date_li
:
logs
=
Log
.
objects
.
filter
(
start_time__year
=
d
.
year
,
start_time__month
=
d
.
month
,
start_time__day
=
d
.
day
)
if
item
==
'user'
:
count
=
len
(
set
([
log
.
user
for
log
in
logs
]))
data_li
.
append
(
set
([
log
.
user
for
log
in
logs
]))
elif
item
==
'asset'
:
count
=
len
(
set
([
log
.
host
for
log
in
logs
]))
data_li
.
append
(
set
([
log
.
host
for
log
in
logs
]))
elif
item
==
'login'
:
count
=
len
(
logs
)
data_li
.
append
(
logs
)
else
:
count
=
0
data_li
.
append
(
count
)
pass
return
data_li
def
get_count_by_day
(
date_li
,
item
):
data_li
=
get_data_by_day
(
date_li
,
item
)
data_count_li
=
[]
for
data
in
data_li
:
data_count_li
.
append
(
len
(
data
))
return
data_count_li
def
get_count_by_date
(
date_li
,
item
):
data_li
=
get_data_by_day
(
date_li
,
item
)
data_count_tmp
=
[]
for
data
in
data_li
:
data_count_tmp
.
extend
(
list
(
data
))
return
len
(
set
(
data_count_tmp
))
@require_role
(
role
=
'user'
)
def
index_cu
(
request
):
user_id
=
request
.
user
.
id
...
...
@@ -102,6 +104,7 @@ def index(request):
return
index_cu
(
request
)
elif
is_role_request
(
request
,
'super'
):
# dashboard 显示汇总
users
=
User
.
objects
.
all
()
hosts
=
Asset
.
objects
.
all
()
online
=
Log
.
objects
.
filter
(
is_finished
=
0
)
...
...
@@ -109,75 +112,52 @@ def index(request):
online_user
=
online
.
values
(
'user'
)
.
distinct
()
active_users
=
User
.
objects
.
filter
(
is_active
=
1
)
active_hosts
=
Asset
.
objects
.
filter
(
is_active
=
1
)
week_data
=
Log
.
objects
.
filter
(
start_time__range
=
[
from_week
,
datetime
.
datetime
.
now
()])
# 一个月历史汇总
date_li
,
date_str
=
getDaysByNum
(
30
)
date_month
=
repr
(
date_str
)
print
date_month
active_user_month
=
str
(
get_count_by_day
(
date_li
,
'user'
))
active_asset_month
=
str
(
get_count_by_day
(
date_li
,
'asset'
))
active_login_month
=
str
(
get_count_by_day
(
date_li
,
'login'
))
elif
is_role_request
(
request
,
'admin'
):
return
index_cu
(
request
)
# user = get_session_user_info(request)[2]
# users = User.objects.filter(dept=dept)
# hosts = Asset.objects.filter(dept=dept)
# online = Log.objects.filter(dept_name=dept_name, is_finished=0)
# online_host = online.values('host').distinct()
# online_user = online.values('user').distinct()
# active_users = users.filter(is_active=1)
# active_hosts = hosts.filter(is_active=1)
# week_data = Log.objects.filter(dept_name=dept_name, start_time__range=[from_week, datetime.datetime.now()])
# percent of dashboard
if
users
.
count
()
==
0
:
percent_user
,
percent_online_user
=
'0
%
'
,
'0
%
'
else
:
percent_user
=
format
(
active_users
.
count
()
/
users
.
count
(),
'.0
%
'
)
percent_online_user
=
format
(
online_user
.
count
()
/
users
.
count
(),
'.0
%
'
)
if
hosts
.
count
()
==
0
:
percent_host
,
percent_online_host
=
'0
%
'
,
'0
%
'
else
:
percent_host
=
format
(
active_hosts
.
count
()
/
hosts
.
count
(),
'.0
%
'
)
percent_online_host
=
format
(
online_host
.
count
()
/
hosts
.
count
(),
'.0
%
'
)
active_user_per_month
=
str
(
get_count_by_day
(
date_li
,
'user'
))
active_asset_per_month
=
str
(
get_count_by_day
(
date_li
,
'asset'
))
active_login_per_month
=
str
(
get_count_by_day
(
date_li
,
'login'
))
# 活跃用户资产图
active_user_month
=
get_count_by_date
(
date_li
,
'user'
)
disabled_user_count
=
len
(
users
.
filter
(
is_active
=
False
))
inactive_user_month
=
len
(
users
)
-
active_user_month
active_asset_month
=
get_count_by_date
(
date_li
,
'asset'
)
disabled_asset_count
=
len
(
hosts
.
filter
(
is_active
=
False
))
if
hosts
.
filter
(
is_active
=
False
)
else
0
inactive_asset_month
=
len
(
hosts
)
-
active_asset_month
if
len
(
hosts
)
>
active_asset_month
else
0
# 一周top10用户和主机
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
]
host_top_ten
=
week_data
.
values
(
'host'
)
.
annotate
(
times
=
Count
(
'host'
))
.
order_by
(
'-times'
)[:
10
]
user_dic
,
host_dic
=
get_data
(
week_data
,
user_top_ten
,
'user'
),
get_data
(
week_data
,
host_top_ten
,
'host'
)
# a week data
for
user_info
in
user_top_ten
:
username
=
user_info
.
get
(
'user'
)
last
=
Log
.
objects
.
filter
(
user
=
username
)
.
latest
(
'start_time'
)
user_info
[
'last'
]
=
last
for
host_info
in
host_top_ten
:
host
=
host_info
.
get
(
'host'
)
last
=
Log
.
objects
.
filter
(
host
=
host
)
.
latest
(
'start_time'
)
host_info
[
'last'
]
=
last
# 一周top5
week_users
=
week_data
.
values
(
'user'
)
.
distinct
()
.
count
()
week_hosts
=
week_data
.
count
()
user_top_five
=
week_data
.
values
(
'user'
)
.
annotate
(
times
=
Count
(
'user'
))
.
order_by
(
'-times'
)[:
5
]
color
=
[
'label-success'
,
'label-info'
,
'label-primary'
,
'label-default'
,
'label-warnning'
]
# 最后10次权限申请
# perm apply latest 10
# perm_apply_10 = Apply.objects.order_by('-date_add')[:10]
# latest 10 login
# 最后10次登陆
login_10
=
Log
.
objects
.
order_by
(
'-start_time'
)[:
10
]
login_more_10
=
Log
.
objects
.
order_by
(
'-start_time'
)[
10
:
21
]
# a week top 10
for
user_info
in
user_top_ten
:
username
=
user_info
.
get
(
'user'
)
last
=
Log
.
objects
.
filter
(
user
=
username
)
.
latest
(
'start_time'
)
user_info
[
'last'
]
=
last
top
=
{
'user'
:
'活跃用户数'
,
'host'
:
'活跃主机数'
,
'times'
:
'登录次数'
}
top_dic
=
{}
for
key
,
value
in
top
.
items
():
li
=
[]
for
t
in
li_date
:
year
,
month
,
day
=
t
.
year
,
t
.
month
,
t
.
day
if
key
!=
'times'
:
times
=
week_data
.
filter
(
start_time__year
=
year
,
start_time__month
=
month
,
start_time__day
=
day
)
.
values
(
key
)
.
distinct
()
.
count
()
else
:
times
=
week_data
.
filter
(
start_time__year
=
year
,
start_time__month
=
month
,
start_time__day
=
day
)
.
count
()
li
.
append
(
times
)
top_dic
[
value
]
=
li
return
render_to_response
(
'index.html'
,
locals
(),
context_instance
=
RequestContext
(
request
))
...
...
templates/index.html
View file @
0174da6c
...
...
@@ -14,7 +14,7 @@
</div>
<div
class=
"ibox-content"
>
<h1
class=
"no-margins"
><a
href=
"/juser/user_list/"
>
{{ users.count}}
</a></h1>
<div
class=
"stat-percent font-bold text-success"
>
{{ percent_user }}
<i
class=
"fa fa-bolt"
></i></div>
{#
<div
class=
"stat-percent font-bold text-success"
>
{{ percent_user }}
<i
class=
"fa fa-bolt"
></i></div>
#}
<small>
All user
</small>
</div>
</div>
...
...
@@ -27,7 +27,7 @@
</div>
<div
class=
"ibox-content"
>
<h1
class=
"no-margins"
><a
href=
"/jasset/host_list/"
>
{{ hosts.count }}
</a></h1>
<div
class=
"stat-percent font-bold text-info"
>
{{ percent_host }}
<i
class=
"fa fa-level-up"
></i></div>
{#
<div
class=
"stat-percent font-bold text-info"
>
{{ percent_host }}
<i
class=
"fa fa-level-up"
></i></div>
#}
<small>
All host
</small>
</div>
</div>
...
...
@@ -40,8 +40,8 @@
<h5>
实时在线用户
</h5>
</div>
<div
class=
"ibox-content"
>
<h1
class=
"no-margins"
><a
href=
"/jlog/log_list/online/"
>
<span
id=
"online_users"
>
10
</span></a></h1>
<div
class=
"stat-percent font-bold text-navy"
>
{{ percent_online_user }}
<i
class=
"fa fa-level-up"
></i></div>
<h1
class=
"no-margins"
><a
href=
"/jlog/log_list/online/"
>
<span
id=
"online_users"
>
{{ online_user | length }}
</span></a></h1>
{#
<div
class=
"stat-percent font-bold text-navy"
>
{{ percent_online_user }}
<i
class=
"fa fa-level-up"
></i></div>
#}
<small>
Online user
</small>
</div>
</div>
...
...
@@ -54,8 +54,8 @@
<h5>
已连接服务器
</h5>
</div>
<div
class=
"ibox-content"
>
<h1
class=
"no-margins"
><a
href=
"/jlog/log_list/online/"
>
<span
id=
"online_hosts"
>
10
</span></a></h1>
<div
class=
"stat-percent font-bold text-danger"
>
{{ percent_online_host }}
<i
class=
"fa fa-level-down"
></i></div>
<h1
class=
"no-margins"
><a
href=
"/jlog/log_list/online/"
>
<span
id=
"online_hosts"
>
{{ online_host | length }}
</span></a></h1>
{#
<div
class=
"stat-percent font-bold text-danger"
>
{{ percent_online_host }}
<i
class=
"fa fa-level-down"
></i></div>
#}
<small>
Connected host
</small>
</div>
</div>
...
...
@@ -151,6 +151,51 @@
</div>
</div>
</div>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
一周Top10资产
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
></ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content ibox-heading"
>
<h3><i
class=
"fa fa-user"
></i>
一周Top10资产
</h3>
<small><i
class=
"fa fa-map-marker"
></i>
登录次数及最近一次登录记录.
</small>
</div>
<div
class=
"ibox-content inspinia-timeline"
>
{% if host_top_ten %}
{% for data in host_top_ten %}
<div
class=
"timeline-item"
>
<div
class=
"row"
>
<div
class=
"col-xs-5 date"
>
<i
class=
"fa fa-info-circle"
></i>
<strong>
{{ data.host }}
</strong>
<br/>
<small
class=
"text-navy"
>
{{ data.times }}次
</small>
</div>
<div
class=
"col-xs-7 content no-top-border"
>
<p
class=
"m-b-xs"
>
最近一次登录用户
</p>
<p>
{{ data.last.user }}
</p>
<p>
于{{ data.last.start_time |date:"Y-m-d H:i:s" }}
</p>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p
class=
"text-center"
>
(暂无)
</p>
{% endif %}
</div>
</div>
</div>
<div
class=
"col-lg-4"
>
<div
class=
"ibox float-e-margins"
>
...
...
@@ -162,7 +207,7 @@
</div>
<div
class=
"ibox-content ibox-heading"
>
<h3><i
class=
"fa fa-paper-plane-o"
></i>
登录记录
</h3>
<small
<
i
class=
"fa fa-map-marker"
></i>
最近十次登录记录.
</small>
<small
>
<i
class=
"fa fa-map-marker"
></i>
最近十次登录记录.
</small>
</div>
<div
class=
"ibox-content"
>
<div>
...
...
@@ -237,7 +282,7 @@
</div>
<div
class=
"ibox-content ibox-heading"
>
<h3><i
class=
"fa fa-user"
></i>
一周Top10用户
</h3>
<small><i
class=
"fa fa-map-marker"
></i>
一周Top10
用户登录次数及最近一次登录记录.
</small>
<small><i
class=
"fa fa-map-marker"
></i>
用户登录次数及最近一次登录记录.
</small>
</div>
<div
class=
"ibox-content inspinia-timeline"
>
{% if user_top_ten %}
...
...
@@ -251,7 +296,7 @@
<small
class=
"text-navy"
>
{{ data.times }}次
</small>
</div>
<div
class=
"col-xs-7 content no-top-border"
>
<p
class=
"m-b-xs"
>
最近一次登录
</p>
<p
class=
"m-b-xs"
>
最近一次登录
主机
</p>
<p>
{{ data.last.host }}
</p>
<p>
于{{ data.last.start_time |date:"Y-m-d H:i:s" }}
</p>
</div>
...
...
@@ -272,6 +317,7 @@
<!--<div class="col-lg-6" id="hosttop10" style="width:50%;height:400px; margin-top: 20px"></div>-->
<!--</div>-->
</div>
</div>
<script
src=
"/static/js/echarts/echarts.js"
></script>
<script>
...
...
@@ -337,22 +383,22 @@ $(document).ready(function(){
type
:
'line'
,
smooth
:
true
,
itemStyle
:
{
normal
:
{
areaStyle
:
{
type
:
'default'
}}},
data
:
{{
active_login_month
|
safe
}}
data
:
{{
active_login_
per_
month
|
safe
}}
},
{
name
:
'活跃用户'
,
type
:
'line'
,
smooth
:
true
,
itemStyle
:
{
normal
:
{
areaStyle
:
{
type
:
'default'
}}},
data
:
{{
active_user_month
|
safe
}}
data
:
{{
active_user_
per_
month
|
safe
}}
},
{
name
:
'活跃资产'
,
type
:
'line'
,
smooth
:
true
,
itemStyle
:
{
normal
:
{
areaStyle
:
{
type
:
'default'
}}},
data
:
{{
active_asset_month
|
safe
}}
}
,
data
:
{{
active_asset_
per_
month
|
safe
}}
}
]
};
...
...
@@ -368,7 +414,6 @@ $(document).ready(function(){
],
function
(
ec
)
{
var
auChart
=
ec
.
init
(
document
.
getElementById
(
'activeUser'
));
var
aaChart
=
ec
.
init
(
document
.
getElementById
(
'activeAsset'
));
var
option
=
{
tooltip
:
{
trigger
:
'item'
,
...
...
@@ -378,7 +423,7 @@ $(document).ready(function(){
show
:
false
,
orient
:
'vertical'
,
x
:
'left'
,
data
:[
'
直接访问'
,
'邮件营销'
,
'联盟广告'
,
'视频广告'
,
'搜索引擎
'
]
data
:[
'
月活跃用户'
,
'禁用用户'
,
'月未登陆用户
'
]
},
toolbox
:
{
show
:
false
,
...
...
@@ -428,17 +473,94 @@ $(document).ready(function(){
}
},
data
:[
{
value
:
335
,
name
:
'直接访问'
},
{
value
:
310
,
name
:
'邮件营销'
},
{
value
:
234
,
name
:
'联盟广告'
},
{
value
:
135
,
name
:
'视频广告'
},
{
value
:
1548
,
name
:
'搜索引擎'
}
{
value
:{{
active_user_month
}},
name
:
'月活跃用户'
},
{
value
:{{
disabled_user_count
}},
name
:
'禁用用户'
},
{
value
:{{
inactive_user_month
}},
name
:
'月未登陆用户'
}
]
}
]
};
auChart
.
setOption
(
option
);
}
);
require
(
[
'echarts'
,
'echarts/chart/pie'
],
function
(
ec
)
{
var
aaChart
=
ec
.
init
(
document
.
getElementById
(
'activeAsset'
));
var
option
=
{
tooltip
:
{
trigger
:
'item'
,
formatter
:
"{b} <br> {c} ({d}%)"
},
legend
:
{
show
:
false
,
orient
:
'vertical'
,
x
:
'left'
,
data
:[
'月被登陆主机'
,
'禁用主机'
,
'月未登陆主机'
]
},
toolbox
:
{
show
:
false
,
feature
:
{
mark
:
{
show
:
true
},
dataView
:
{
show
:
true
,
readOnly
:
false
},
magicType
:
{
show
:
true
,
type
:
[
'pie'
,
'funnel'
],
option
:
{
funnel
:
{
x
:
'25%'
,
width
:
'50%'
,
funnelAlign
:
'center'
,
max
:
1548
}
}
},
restore
:
{
show
:
true
},
saveAsImage
:
{
show
:
true
}
}
},
calculable
:
true
,
series
:
[
{
name
:
'访问来源'
,
type
:
'pie'
,
radius
:
[
'50%'
,
'70%'
],
itemStyle
:
{
normal
:
{
label
:
{
show
:
false
},
labelLine
:
{
show
:
false
}
},
emphasis
:
{
label
:
{
show
:
true
,
position
:
'center'
,
textStyle
:
{
fontSize
:
'5'
,
fontWeight
:
'bold'
}
}
}
},
data
:[
{
value
:{{
active_asset_month
}},
name
:
'月被登陆主机'
},
{
value
:{{
disabled_asset_count
}},
name
:
'禁用主机'
},
{
value
:{{
inactive_asset_month
}},
name
:
'月未登陆主机'
}
]
}
]
};
aaChart
.
setOption
(
option
);
}
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment