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