diff --git a/jasset/asset_api.py b/jasset/asset_api.py
index 1e8083062..bf2b93923 100644
--- a/jasset/asset_api.py
+++ b/jasset/asset_api.py
@@ -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'机柜位置',
- 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'所属主机组', u'操作系统', u'CPU', u'内存(G)', u'硬盘(G)',
+ u'机柜位置', u'MAC', u'远控IP', 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''
@@ -213,13 +217,14 @@ def write_excel(asset_all):
system_version = asset.system_version if asset.idc else u''
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]
+ alter_dic = [asset.hostname, asset.ip, idc_name, group_all, system_os, asset.cpu, asset.memory,
+ disk, asset.cabinet, asset.mac, asset.remote_ip, 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,18 +313,21 @@ 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 = {}
- for disk_name, disk_info in disk_all.iteritems():
- if disk_name.startswith('sd') or disk_name.startswith('hd') or disk_name.startswith('vd'):
- 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_need[disk_name] = disk_format
+ 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", '')
+ 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[:-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 []
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")
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,
diff --git a/jasset/views.py b/jasset/views.py
index 7f7621892..0f7cb55b6 100644
--- a/jasset/views.py
+++ b/jasset/views.py
@@ -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')
diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py
index 880fd2b12..af41f6b0e 100644
--- a/jumpserver/templatetags/mytags.py
+++ b/jumpserver/templatetags/mytags.py
@@ -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
diff --git a/static/files/excels/asset.xlsx b/static/files/excels/asset.xlsx
new file mode 100644
index 000000000..1b92db891
Binary files /dev/null and b/static/files/excels/asset.xlsx differ
diff --git a/static/files/excels/cmdb_excel_2015_12_01_22_17.xlsx b/static/files/excels/cmdb_excel_2015_12_01_22_17.xlsx
deleted file mode 100644
index 37718bab3..000000000
Binary files a/static/files/excels/cmdb_excel_2015_12_01_22_17.xlsx and /dev/null differ
diff --git a/templates/jasset/asset_detail.html b/templates/jasset/asset_detail.html
index dd5305d8b..53f9f357a 100644
--- a/templates/jasset/asset_detail.html
+++ b/templates/jasset/asset_detail.html
@@ -193,27 +193,29 @@
{% if perm_info %}
-
- 授权用户信息
- 授权用户 |
- 系统角色 |
- {% for perm in user_perm %}
-
- {{ perm.0 }} |
-
-
- {% if perm.1 %}
- {% for role in perm.1 %}
-
- {{ role }} |
-
- {% endfor %}
- {% endif %}
-
- |
-
- {% endfor %}
-
+ {% if user_perm %}
+
+ 授权用户信息
+ 授权用户 |
+ 系统角色 |
+ {% for perm in user_perm %}
+
+ {{ perm.0 }} |
+
+
+ {% if perm.1 %}
+ {% for role in perm.1 %}
+
+ {{ role }} |
+
+ {% endfor %}
+ {% endif %}
+
+ |
+
+ {% endfor %}
+
+ {% endif %}
{% if user_group_perm %}
授权用户组信息
diff --git a/templates/jasset/asset_edit.html b/templates/jasset/asset_edit.html
index a2db11d00..870579738 100644
--- a/templates/jasset/asset_edit.html
+++ b/templates/jasset/asset_edit.html
@@ -46,6 +46,9 @@
{{ af.remote_ip|bootstrap_horizontal }}
+
+ {{ af.mac|bootstrap_horizontal }}
+
{# #}
{# {{ af.port|bootstrap_horizontal }}#}
diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html
index e8ee6e485..175271e73 100644
--- a/templates/jasset/asset_list.html
+++ b/templates/jasset/asset_list.html
@@ -127,7 +127,7 @@
{{ asset.group.all|group_str2 }} |
{# {{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }} | #}
{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }} |
- {{ asset.cpu|get_cpu_core }} |
+ {{ asset.cpu|get_cpu_core|default_if_none:"" }} |
{{ asset.memory }}{% if asset.memory %}G{% endif %} |
{{ asset.disk|get_disk_info }}{% if asset.memory %}G{% endif %} |
@@ -144,8 +144,8 @@
修改
-
-
+{# #}
+
{% include 'paginator.html' %}
@@ -347,37 +347,40 @@
$('#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",
+ 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(){#}
-{# layer.tips('我是另外一个tips,只不过我长得跟之前那位稍有些不一样。', '吸附元素选择器', {#}
-{# tips: [1, '#3595CC'],#}
-{# time: 4000#}
+{# $('#asset_update_all').click(function () {#}
+{# layer.msg('玩命更新中...', {time: 200000});#}
+{# $.ajax({#}
+{# 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(){
var args = $("#asset_form").serialize();
|