mirror of https://github.com/jumpserver/jumpserver
fix bugs
parent
8f985ade97
commit
2c3e681942
|
@ -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):
|
||||||
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):
|
||||||
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)
|
||||||
|
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'备注']
|
u'所属主机组', 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''
|
||||||
|
@ -214,12 +218,13 @@ def write_excel(asset_all):
|
||||||
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, asset.mac, asset.remote_ip, asset.cpu, asset.memory,
|
||||||
asset.disk, system_os, asset.cabinet, group_all, status,
|
disk, system_os, asset.cabinet, group_all, 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,18 +313,21 @@ 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 = {}
|
||||||
for disk_name, disk_info in disk_all.iteritems():
|
disk_all = setup_info.get("ansible_devices")
|
||||||
if disk_name.startswith('sd') or disk_name.startswith('hd') or disk_name.startswith('vd'):
|
if disk_all:
|
||||||
disk_size = disk_info.get("size")
|
for disk_name, disk_info in disk_all.iteritems():
|
||||||
if 'M' in disk_size:
|
print disk_name, disk_info
|
||||||
disk_format = round(float(disk_size[:-2]) / 1000, 0)
|
if disk_name.startswith('sd') or disk_name.startswith('hd') or disk_name.startswith('vd'):
|
||||||
elif 'T' in disk_size:
|
disk_size = disk_info.get("size", '')
|
||||||
disk_format = round(float(disk_size[:-2]) * 1000, 0)
|
if 'M' in disk_size:
|
||||||
else:
|
disk_format = round(float(disk_size[:-2]) / 1000, 0)
|
||||||
disk_format = float(disk_size)
|
elif 'T' in disk_size:
|
||||||
disk_need[disk_name] = disk_format
|
disk_format = round(float(disk_size[:-2]) * 1000, 0)
|
||||||
|
else:
|
||||||
|
disk_format = float(disk_size[:-2])
|
||||||
|
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 []
|
||||||
other_ip = ','.join(other_ip_list) if other_ip_list else ''
|
other_ip = ','.join(other_ip_list) if other_ip_list else ''
|
||||||
|
@ -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=''):
|
||||||
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,
|
||||||
|
|
|
@ -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')
|
||||||
|
|
||||||
|
|
|
@ -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):
|
||||||
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
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -193,27 +193,29 @@
|
||||||
<div>
|
<div>
|
||||||
<div class="text-left">
|
<div class="text-left">
|
||||||
{% if perm_info %}
|
{% if perm_info %}
|
||||||
<table class="table">
|
{% if user_perm %}
|
||||||
<p>授权用户信息</p>
|
<table class="table">
|
||||||
<td class="text-navy">授权用户</td>
|
<p>授权用户信息</p>
|
||||||
<td class="text-navy">系统角色</td>
|
<td class="text-navy">授权用户</td>
|
||||||
{% for perm in user_perm %}
|
<td class="text-navy">系统角色</td>
|
||||||
<tr>
|
{% for perm in user_perm %}
|
||||||
<td class="text-navy"><a href="/juser/user_detail/?id={{ perm.0.id }}">{{ perm.0 }}</a></td>
|
<tr>
|
||||||
<td>
|
<td class="text-navy"><a href="/juser/user_detail/?id={{ perm.0.id }}">{{ perm.0 }}</a></td>
|
||||||
<table class="table">
|
<td>
|
||||||
{% if perm.1 %}
|
<table class="table">
|
||||||
{% for role in perm.1 %}
|
{% if perm.1 %}
|
||||||
<tr>
|
{% for role in perm.1 %}
|
||||||
<td class="text-navy"><a href="/jperm/role/perm_role_detail/?id={{ role.id }}">{{ role }}</a></td>
|
<tr>
|
||||||
</tr>
|
<td class="text-navy"><a href="/jperm/role/perm_role_detail/?id={{ role.id }}">{{ role }}</a></td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
{% endif %}
|
{% endfor %}
|
||||||
</table>
|
{% endif %}
|
||||||
</td>
|
</table>
|
||||||
</tr>
|
</td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
</table>
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
{% if user_group_perm %}
|
{% if user_group_perm %}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<p>授权用户组信息</p>
|
<p>授权用户组信息</p>
|
||||||
|
|
|
@ -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 }}#}
|
||||||
|
|
||||||
|
|
|
@ -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 }} </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 @@
|
||||||
<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,37 +347,40 @@
|
||||||
$('#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});
|
||||||
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
url: "/jasset/asset_update_batch/?arg=all",
|
||||||
|
success: function () {
|
||||||
|
parent.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
layer.msg('玩命更新中...', {time: 200000});
|
||||||
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
data: {asset_id_all: asset_id_all},
|
||||||
|
url: "/jasset/asset_update_batch/",
|
||||||
|
success: function () {
|
||||||
|
parent.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
layer.msg('玩命更新中...', {time: 200000});
|
|
||||||
$.ajax({
|
|
||||||
type: "post",
|
|
||||||
data: {asset_id_all: asset_id_all},
|
|
||||||
url: "/jasset/asset_update_batch/",
|
|
||||||
success: function () {
|
|
||||||
parent.location.reload();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{# function update_tips(){#}
|
{# $('#asset_update_all').click(function () {#}
|
||||||
{# layer.tips('我是另外一个tips,只不过我长得跟之前那位稍有些不一样。', '吸附元素选择器', {#}
|
{# layer.msg('玩命更新中...', {time: 200000});#}
|
||||||
{# tips: [1, '#3595CC'],#}
|
{# $.ajax({#}
|
||||||
{# time: 4000#}
|
{# type: "post",#}
|
||||||
|
{# url: "/jasset/asset_update_batch/?arg=all",#}
|
||||||
|
{# 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(){
|
function change_info(){
|
||||||
var args = $("#asset_form").serialize();
|
var args = $("#asset_form").serialize();
|
||||||
|
|
Loading…
Reference in New Issue