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
532646a4
Commit
532646a4
authored
Dec 05, 2015
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of git.coding.net:jumpserver/jumpserver into dev
parents
0fd7b980
2f0e91a5
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
34 deletions
+54
-34
asset_api.py
jasset/asset_api.py
+20
-11
views.py
jasset/views.py
+2
-3
mytags.py
jumpserver/templatetags/mytags.py
+5
-1
asset.xlsx
static/files/excels/asset.xlsx
+0
-0
cmdb_excel_2015_12_01_22_17.xlsx
static/files/excels/cmdb_excel_2015_12_01_22_17.xlsx
+0
-0
asset_detail.html
templates/jasset/asset_detail.html
+2
-0
asset_edit.html
templates/jasset/asset_edit.html
+3
-0
asset_list.html
templates/jasset/asset_list.html
+22
-19
No files found.
jasset/asset_api.py
View file @
532646a4
...
@@ -7,6 +7,7 @@ from jumpserver.api import *
...
@@ -7,6 +7,7 @@ from jumpserver.api import *
from
jasset.models
import
ASSET_STATUS
,
ASSET_TYPE
,
ASSET_ENV
,
IDC
,
AssetRecord
from
jasset.models
import
ASSET_STATUS
,
ASSET_TYPE
,
ASSET_ENV
,
IDC
,
AssetRecord
from
jperm.ansible_api
import
MyRunner
from
jperm.ansible_api
import
MyRunner
from
jperm.perm_api
import
gen_resource
from
jperm.perm_api
import
gen_resource
from
jumpserver.templatetags.mytags
import
get_disk_info
def
group_add_asset
(
group
,
asset_id
=
None
,
asset_ip
=
None
):
def
group_add_asset
(
group
,
asset_id
=
None
,
asset_ip
=
None
):
...
@@ -156,7 +157,7 @@ def db_asset_alert(asset, username, alert_dic):
...
@@ -156,7 +157,7 @@ def db_asset_alert(asset, username, alert_dic):
for
group_id
in
value
[
1
]:
for
group_id
in
value
[
1
]:
group_name
=
AssetGroup
.
objects
.
get
(
id
=
int
(
group_id
))
.
name
group_name
=
AssetGroup
.
objects
.
get
(
id
=
int
(
group_id
))
.
name
new
.
append
(
group_name
)
new
.
append
(
group_name
)
if
old
==
new
:
if
sorted
(
old
)
==
sorted
(
new
)
:
continue
continue
else
:
else
:
alert_info
=
[
field_name
,
','
.
join
(
old
),
','
.
join
(
new
)]
alert_info
=
[
field_name
,
','
.
join
(
old
),
','
.
join
(
new
)]
...
@@ -198,14 +199,17 @@ def write_excel(asset_all):
...
@@ -198,14 +199,17 @@ def write_excel(asset_all):
workbook
=
xlsxwriter
.
Workbook
(
'static/files/excels/
%
s'
%
file_name
)
workbook
=
xlsxwriter
.
Workbook
(
'static/files/excels/
%
s'
%
file_name
)
worksheet
=
workbook
.
add_worksheet
(
u'CMDB数据'
)
worksheet
=
workbook
.
add_worksheet
(
u'CMDB数据'
)
worksheet
.
set_first_sheet
()
worksheet
.
set_first_sheet
()
worksheet
.
set_column
(
'A:Z'
,
14
)
worksheet
.
set_column
(
'A:E'
,
15
)
title
=
[
u'主机名'
,
u'IP'
,
u'IDC'
,
u'MAC'
,
u'远控IP'
,
u'CPU'
,
u'内存'
,
u'硬盘'
,
u'操作系统'
,
u'机柜位置'
,
worksheet
.
set_column
(
'F:F'
,
40
)
u'所属主机组'
,
u'机器状态'
,
u'备注'
]
worksheet
.
set_column
(
'G:Z'
,
15
)
title
=
[
u'主机名'
,
u'IP'
,
u'IDC'
,
u'所属主机组'
,
u'操作系统'
,
u'CPU'
,
u'内存(G)'
,
u'硬盘(G)'
,
u'机柜位置'
,
u'MAC'
,
u'远控IP'
,
u'机器状态'
,
u'备注'
]
for
asset
in
asset_all
:
for
asset
in
asset_all
:
group_list
=
[]
group_list
=
[]
for
p
in
asset
.
group
.
all
():
for
p
in
asset
.
group
.
all
():
group_list
.
append
(
p
.
name
)
group_list
.
append
(
p
.
name
)
disk
=
get_disk_info
(
asset
.
disk
)
group_all
=
'/'
.
join
(
group_list
)
group_all
=
'/'
.
join
(
group_list
)
status
=
asset
.
get_status_display
()
status
=
asset
.
get_status_display
()
idc_name
=
asset
.
idc
.
name
if
asset
.
idc
else
u''
idc_name
=
asset
.
idc
.
name
if
asset
.
idc
else
u''
...
@@ -213,13 +217,14 @@ def write_excel(asset_all):
...
@@ -213,13 +217,14 @@ def write_excel(asset_all):
system_version
=
asset
.
system_version
if
asset
.
idc
else
u''
system_version
=
asset
.
system_version
if
asset
.
idc
else
u''
system_os
=
unicode
(
system_type
)
+
unicode
(
system_version
)
system_os
=
unicode
(
system_type
)
+
unicode
(
system_version
)
alter_dic
=
[
asset
.
hostname
,
asset
.
ip
,
idc_name
,
asset
.
mac
,
asset
.
remote_ip
,
asset
.
cpu
,
asset
.
memory
,
alter_dic
=
[
asset
.
hostname
,
asset
.
ip
,
idc_name
,
group_all
,
system_os
,
asset
.
cpu
,
asset
.
memory
,
asset
.
disk
,
system_os
,
asset
.
cabinet
,
group_all
,
status
,
disk
,
asset
.
cabinet
,
asset
.
mac
,
asset
.
remote_ip
,
status
,
asset
.
comment
]
asset
.
comment
]
data
.
append
(
alter_dic
)
data
.
append
(
alter_dic
)
format
=
workbook
.
add_format
()
format
=
workbook
.
add_format
()
format
.
set_border
(
1
)
format
.
set_border
(
1
)
format
.
set_align
(
'center'
)
format
.
set_align
(
'center'
)
format
.
set_align
(
'vcenter'
)
format
.
set_text_wrap
()
format_title
=
workbook
.
add_format
()
format_title
=
workbook
.
add_format
()
format_title
.
set_border
(
1
)
format_title
.
set_border
(
1
)
...
@@ -308,17 +313,20 @@ def excel_to_db(excel_file):
...
@@ -308,17 +313,20 @@ def excel_to_db(excel_file):
def
get_ansible_asset_info
(
asset_ip
,
setup_info
):
def
get_ansible_asset_info
(
asset_ip
,
setup_info
):
disk_all
=
setup_info
.
get
(
"ansible_devices"
)
print
asset_ip
disk_need
=
{}
disk_need
=
{}
disk_all
=
setup_info
.
get
(
"ansible_devices"
)
if
disk_all
:
for
disk_name
,
disk_info
in
disk_all
.
iteritems
():
for
disk_name
,
disk_info
in
disk_all
.
iteritems
():
print
disk_name
,
disk_info
if
disk_name
.
startswith
(
'sd'
)
or
disk_name
.
startswith
(
'hd'
)
or
disk_name
.
startswith
(
'vd'
):
if
disk_name
.
startswith
(
'sd'
)
or
disk_name
.
startswith
(
'hd'
)
or
disk_name
.
startswith
(
'vd'
):
disk_size
=
disk_info
.
get
(
"size"
)
disk_size
=
disk_info
.
get
(
"size"
,
''
)
if
'M'
in
disk_size
:
if
'M'
in
disk_size
:
disk_format
=
round
(
float
(
disk_size
[:
-
2
])
/
1000
,
0
)
disk_format
=
round
(
float
(
disk_size
[:
-
2
])
/
1000
,
0
)
elif
'T'
in
disk_size
:
elif
'T'
in
disk_size
:
disk_format
=
round
(
float
(
disk_size
[:
-
2
])
*
1000
,
0
)
disk_format
=
round
(
float
(
disk_size
[:
-
2
])
*
1000
,
0
)
else
:
else
:
disk_format
=
float
(
disk_size
)
disk_format
=
float
(
disk_size
[:
-
2
]
)
disk_need
[
disk_name
]
=
disk_format
disk_need
[
disk_name
]
=
disk_format
all_ip
=
setup_info
.
get
(
"ansible_all_ipv4_addresses"
)
all_ip
=
setup_info
.
get
(
"ansible_all_ipv4_addresses"
)
other_ip_list
=
all_ip
.
remove
(
asset_ip
)
if
asset_ip
in
all_ip
else
[]
other_ip_list
=
all_ip
.
remove
(
asset_ip
)
if
asset_ip
in
all_ip
else
[]
...
@@ -342,7 +350,7 @@ def get_ansible_asset_info(asset_ip, setup_info):
...
@@ -342,7 +350,7 @@ def get_ansible_asset_info(asset_ip, setup_info):
# asset_type = setup_info.get("ansible_system")
# asset_type = setup_info.get("ansible_system")
sn
=
setup_info
.
get
(
"ansible_product_serial"
)
sn
=
setup_info
.
get
(
"ansible_product_serial"
)
asset_info
=
[
other_ip
,
mac
,
cpu
,
memory_format
,
disk
,
sn
,
system_type
,
system_version
,
brand
,
system_arch
]
asset_info
=
[
other_ip
,
mac
,
cpu
,
memory_format
,
disk
,
sn
,
system_type
,
system_version
,
brand
,
system_arch
]
print
asset_info
return
asset_info
return
asset_info
...
@@ -357,6 +365,7 @@ def asset_ansible_update(obj_list, name=''):
...
@@ -357,6 +365,7 @@ def asset_ansible_update(obj_list, name=''):
continue
continue
else
:
else
:
asset_info
=
get_ansible_asset_info
(
asset
.
ip
,
setup_info
)
asset_info
=
get_ansible_asset_info
(
asset
.
ip
,
setup_info
)
print
asset
other_ip
,
mac
,
cpu
,
memory
,
disk
,
sn
,
system_type
,
system_version
,
brand
,
system_arch
=
asset_info
other_ip
,
mac
,
cpu
,
memory
,
disk
,
sn
,
system_type
,
system_version
,
brand
,
system_arch
=
asset_info
asset_dic
=
{
"other_ip"
:
other_ip
,
asset_dic
=
{
"other_ip"
:
other_ip
,
"mac"
:
mac
,
"mac"
:
mac
,
...
...
jasset/views.py
View file @
532646a4
...
@@ -419,10 +419,9 @@ def asset_detail(request):
...
@@ -419,10 +419,9 @@ def asset_detail(request):
if
perm
==
'user'
:
if
perm
==
'user'
:
for
user
,
role_dic
in
value
.
items
():
for
user
,
role_dic
in
value
.
items
():
user_perm
.
append
([
user
,
role_dic
.
get
(
'role'
,
''
)])
user_perm
.
append
([
user
,
role_dic
.
get
(
'role'
,
''
)])
elif
perm
==
'user_group'
:
elif
perm
==
'user_group'
or
perm
==
'rule'
:
user_group_perm
=
value
user_group_perm
=
value
elif
perm
==
'rule'
:
print
perm_info
user_rule_perm
=
value
asset_record
=
AssetRecord
.
objects
.
filter
(
asset
=
asset
)
.
order_by
(
'-alert_time'
)
asset_record
=
AssetRecord
.
objects
.
filter
(
asset
=
asset
)
.
order_by
(
'-alert_time'
)
...
...
jumpserver/templatetags/mytags.py
View file @
532646a4
...
@@ -276,7 +276,9 @@ def get_push_info(push_id, arg):
...
@@ -276,7 +276,9 @@ def get_push_info(push_id, arg):
@register.filter
(
name
=
'get_cpu_core'
)
@register.filter
(
name
=
'get_cpu_core'
)
def
get_cpu_core
(
cpu_info
):
def
get_cpu_core
(
cpu_info
):
return
cpu_info
.
split
(
'* '
)[
1
]
if
cpu_info
else
''
cpu_core
=
cpu_info
.
split
(
'* '
)[
1
]
if
cpu_info
and
'*'
in
cpu_info
else
cpu_info
return
cpu_core
@register.filter
(
name
=
'get_disk_info'
)
@register.filter
(
name
=
'get_disk_info'
)
def
get_disk_info
(
disk_info
):
def
get_disk_info
(
disk_info
):
...
@@ -287,6 +289,8 @@ def get_disk_info(disk_info):
...
@@ -287,6 +289,8 @@ def get_disk_info(disk_info):
for
disk
,
size
in
disk_dic
.
items
():
for
disk
,
size
in
disk_dic
.
items
():
disk_size
+=
size
disk_size
+=
size
disk_size
=
int
(
disk_size
)
disk_size
=
int
(
disk_size
)
else
:
disk_size
=
''
except
Exception
:
except
Exception
:
disk_size
=
''
disk_size
=
''
return
disk_size
return
disk_size
static/files/excels/asset.xlsx
0 → 100644
View file @
532646a4
File added
static/files/excels/cmdb_excel_2015_12_01_22_17.xlsx
deleted
100644 → 0
View file @
0fd7b980
File deleted
templates/jasset/asset_detail.html
View file @
532646a4
...
@@ -193,6 +193,7 @@
...
@@ -193,6 +193,7 @@
<div>
<div>
<div
class=
"text-left"
>
<div
class=
"text-left"
>
{% if perm_info %}
{% if perm_info %}
{% if user_perm %}
<table
class=
"table"
>
<table
class=
"table"
>
<p>
授权用户信息
</p>
<p>
授权用户信息
</p>
<td
class=
"text-navy"
>
授权用户
</td>
<td
class=
"text-navy"
>
授权用户
</td>
...
@@ -214,6 +215,7 @@
...
@@ -214,6 +215,7 @@
</tr>
</tr>
{% endfor %}
{% endfor %}
</table>
</table>
{% endif %}
{% if user_group_perm %}
{% if user_group_perm %}
<table
class=
"table"
>
<table
class=
"table"
>
<p>
授权用户组信息
</p>
<p>
授权用户组信息
</p>
...
...
templates/jasset/asset_edit.html
View file @
532646a4
...
@@ -46,6 +46,9 @@
...
@@ -46,6 +46,9 @@
<div
class=
"hr-line-dashed"
></div>
<div
class=
"hr-line-dashed"
></div>
{{ af.remote_ip|bootstrap_horizontal }}
{{ af.remote_ip|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
{{ af.mac|bootstrap_horizontal }}
{#
<div
class=
"hr-line-dashed"
></div>
#}
{#
<div
class=
"hr-line-dashed"
></div>
#}
{# {{ af.port|bootstrap_horizontal }}#}
{# {{ af.port|bootstrap_horizontal }}#}
...
...
templates/jasset/asset_list.html
View file @
532646a4
...
@@ -127,7 +127,7 @@
...
@@ -127,7 +127,7 @@
<td
class=
"text-center"
>
{{ asset.group.all|group_str2 }}
</td>
<td
class=
"text-center"
>
{{ asset.group.all|group_str2 }}
</td>
{#
<td
class=
"text-center"
>
{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}
</td>
#}
{#
<td
class=
"text-center"
>
{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}
</td>
#}
<td
class=
"text-center"
>
{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }}
</td>
<td
class=
"text-center"
>
{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu|get_cpu_core }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu|get_cpu_core
|default_if_none:""
}}
</td>
<td
class=
"text-center"
>
{{ asset.memory }}{% if asset.memory %}G{% endif %}
</td>
<td
class=
"text-center"
>
{{ asset.memory }}{% if asset.memory %}G{% endif %}
</td>
<td
class=
"text-center"
>
{{ asset.disk|get_disk_info }}{% if asset.memory %}G{% endif %}
</td>
<td
class=
"text-center"
>
{{ asset.disk|get_disk_info }}{% if asset.memory %}G{% endif %}
</td>
<td
class=
"text-center"
data-editable=
'false'
>
<td
class=
"text-center"
data-editable=
'false'
>
...
@@ -144,8 +144,8 @@
...
@@ -144,8 +144,8 @@
<input
type=
"button"
id=
"asset_del"
class=
"btn btn-danger btn-sm"
name=
"del_button"
value=
"删除"
/>
<input
type=
"button"
id=
"asset_del"
class=
"btn btn-danger btn-sm"
name=
"del_button"
value=
"删除"
/>
<a
value=
"/jasset/asset_edit_batch/"
type=
"button"
class=
"btn btn-sm btn-warning iframe"
>
修改
</a>
<a
value=
"/jasset/asset_edit_batch/"
type=
"button"
class=
"btn btn-sm btn-warning iframe"
>
修改
</a>
<input
type=
"button"
id=
"asset_update"
class=
"btn btn-info btn-sm"
name=
"update_button"
value=
"更新"
/>
<input
type=
"button"
id=
"asset_update"
class=
"btn btn-info btn-sm"
name=
"update_button"
value=
"更新"
/>
<input
type=
"button"
id=
"asset_update_all"
class=
"btn btn-primary btn-sm"
name=
"update_button"
value=
"更新全部"
/>
{#
<input
type=
"button"
id=
"asset_update_all"
class=
"btn btn-primary btn-sm"
name=
"update_button"
value=
"更新全部"
/>
#}
<input
type=
"button"
id=
"exec_cmd"
class=
"btn btn-sm btn-
danger
"
name=
"exec_cmd"
value=
"执行命令"
/>
<input
type=
"button"
id=
"exec_cmd"
class=
"btn btn-sm btn-
primary
"
name=
"exec_cmd"
value=
"执行命令"
/>
</div>
</div>
{% include 'paginator.html' %}
{% include 'paginator.html' %}
</div>
</div>
...
@@ -347,38 +347,41 @@
...
@@ -347,38 +347,41 @@
$
(
'#asset_update'
).
click
(
function
()
{
$
(
'#asset_update'
).
click
(
function
()
{
var
asset_id_all
=
getIDall
();
var
asset_id_all
=
getIDall
();
if
(
asset_id_all
==
''
){
if
(
asset_id_all
==
''
){
alert
(
"请至少选择一行!"
);
if
(
confirm
(
"更新全部资产信息?"
))
{
return
false
;
}
layer
.
msg
(
'玩命更新中...'
,
{
time
:
200000
});
layer
.
msg
(
'玩命更新中...'
,
{
time
:
200000
});
$
.
ajax
({
$
.
ajax
({
type
:
"post"
,
type
:
"post"
,
data
:
{
asset_id_all
:
asset_id_all
},
url
:
"/jasset/asset_update_batch/?arg=all"
,
url
:
"/jasset/asset_update_batch/"
,
success
:
function
()
{
success
:
function
()
{
parent
.
location
.
reload
();
parent
.
location
.
reload
();
}
}
});
});
});
}
}
{
#
function
update_tips
(){
#
}
else
{
{
#
layer
.
tips
(
'我是另外一个tips,只不过我长得跟之前那位稍有些不一样。'
,
'吸附元素选择器'
,
{
#
}
{
#
tips
:
[
1
,
'#3595CC'
],
#
}
{
#
time
:
4000
#
}
{
#
});
#
}
{
#
}
#
}
$
(
'#asset_update_all'
).
click
(
function
()
{
layer
.
msg
(
'玩命更新中...'
,
{
time
:
200000
});
layer
.
msg
(
'玩命更新中...'
,
{
time
:
200000
});
$
.
ajax
({
$
.
ajax
({
type
:
"post"
,
type
:
"post"
,
url
:
"/jasset/asset_update_batch/?arg=all"
,
data
:
{
asset_id_all
:
asset_id_all
},
url
:
"/jasset/asset_update_batch/"
,
success
:
function
()
{
success
:
function
()
{
parent
.
location
.
reload
();
parent
.
location
.
reload
();
}
}
});
});
}
});
});
{
#
$
(
'#asset_update_all'
).
click
(
function
()
{
#
}
{
#
layer
.
msg
(
'玩命更新中...'
,
{
time
:
200000
});
#
}
{
#
$
.
ajax
({
#
}
{
#
type
:
"post"
,
#
}
{
#
url
:
"/jasset/asset_update_batch/?arg=all"
,
#
}
{
#
success
:
function
()
{
#
}
{
#
parent
.
location
.
reload
();
#
}
{
#
}
#
}
{
#
});
#
}
{
#
});
#
}
function
change_info
(){
function
change_info
(){
var
args
=
$
(
"#asset_form"
).
serialize
();
var
args
=
$
(
"#asset_form"
).
serialize
();
window
.
location
=
"/jasset/asset_list/?"
+
args
window
.
location
=
"/jasset/asset_list/?"
+
args
...
...
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