pull/26/head
root 2015-11-03 23:53:12 +08:00
parent 0c0f05b6d9
commit 159398b391
6 changed files with 317 additions and 460 deletions

View File

@ -1,4 +1,6 @@
# coding: utf-8
import xlsxwriter
from jumpserver.api import *
@ -171,3 +173,62 @@ def db_asset_update(**kwargs):
# else:
# return httperror(request, '删除失败, 没有这个IDC!')
SERVER_STATUS = {1: u"已安装系统", 2: u"未安装系统", 3: u"正在安装系统", 4: u"报废"}
now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
file_name = 'cmdb_excel_' + now + '.xlsx'
workbook = xlsxwriter.Workbook('static/excels/%s' % file_name)
worksheet = workbook.add_worksheet('CMDB数据')
worksheet.set_first_sheet()
worksheet.set_column('A:Z', 15)
def write_excel(hosts):
data = []
title = [u'主机名', u'IP', u'IDC', u'MAC', u'远控IP', u'CPU', u'内存', u'硬盘', u'操作系统', u'机柜位置',
u'资产编号', u'所属业务', u'机器状态', u'SN', u'运行服务', u'备注']
for host in hosts:
projects_list, services_list = [], []
for p in host.project.all():
projects_list.append(p.name)
for s in host.service.all():
print s.name, s.port
services_list.append(s.name + '-' + str(s.port))
projects = '/'.join(projects_list)
services = '/'.join(services_list)
status = SERVER_STATUS.get(int(host.status))
info = [host.hostname, host.eth1, host.idc.name, host.mac, host.remote_ip, host.cpu, host.memory,
host.disk, host.system_type, host.cabinet, host.number, projects, status,
host.sn, services, host.comment]
data.append(info)
print data
format = workbook.add_format()
format.set_border(1)
format.set_align('center')
format_title = workbook.add_format()
format_title.set_border(1)
format_title.set_bg_color('#cccccc')
format_title.set_align('center')
format_title.set_bold()
format_ave = workbook.add_format()
format_ave.set_border(1)
format_ave.set_num_format('0.00')
worksheet.write_row('A1', title, format_title)
i = 2
for info in data:
location = 'A' + str(i)
worksheet.write_row(location, info, format)
i += 1
workbook.close()
ret = (True, file_name)
return ret
def sort_ip_list(ip_list):
""" ip地址排序 """
ip_list.sort(key=lambda s: map(int, s.split('.')))
return ip_list

View File

@ -4,6 +4,23 @@ import datetime
from django.db import models
from juser.models import User, UserGroup
ENVIRONMENT = (
(0, U'生产环境'),
(1, U'测试环境')
)
ASSET_STATUS = (
(0, u"已使用"),
(1, u"未使用"),
(2, u"报废")
)
ASSET_TYPE = (
(0, u"服务器"),
(2, u"网络设备"),
(3, u"其他")
)
class AssetGroup(models.Model):
GROUP_TYPE = (
@ -83,21 +100,6 @@ class Asset(models.Model):
"""
asset modle
"""
ENVIRONMENT = (
(0, U'生产环境'),
(1, U'测试环境')
)
SERVER_STATUS = (
(0, u"已使用"),
(1, u"未使用"),
(2, u"报废")
)
ASSET_TYPE = (
(0, u"服务器"),
(2, u"网络设备"),
(3, u"其他")
)
ip = models.IPAddressField(unique=True, verbose_name=u"主机IP")
second_ip = models.CharField(max_length=255, blank=True, null=True, verbose_name=u"其他IP")
hostname = models.CharField(max_length=64, blank=True, null=True, verbose_name=u"主机名")
@ -118,7 +120,7 @@ class Asset(models.Model):
cabinet = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机柜号')
position = models.IntegerField(max_length=2, blank=True, null=True, verbose_name=u'机器位置')
number = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'资产编号')
status = models.IntegerField(max_length=2, choices=SERVER_STATUS, blank=True, null=True, default=1, verbose_name=u"机器状态")
status = models.IntegerField(max_length=2, choices=ASSET_STATUS, blank=True, null=True, default=1, verbose_name=u"机器状态")
asset_type = models.IntegerField(max_length=2, choices=ASSET_TYPE, blank=True, null=True, verbose_name=u"主机类型")
env = models.IntegerField(max_length=2, choices=ENVIRONMENT, blank=True, null=True, verbose_name=u"运行环境")
sn = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"SN编号")
@ -129,22 +131,6 @@ class Asset(models.Model):
def __unicode__(self):
return self.ip
def get_user(self):
perm_list = []
asset_group_all = self.bis_group.all()
for asset_group in asset_group_all:
perm_list.extend(asset_group.perm_set.all())
user_group_list = []
for perm in perm_list:
user_group_list.append(perm.user_group)
user_permed_list = []
for user_group in user_group_list:
user_permed_list.extend(user_group.user_set.all())
user_permed_list = list(set(user_permed_list))
return user_permed_list
class AssetAlias(models.Model):
user = models.ForeignKey(User)

View File

@ -12,6 +12,7 @@ urlpatterns = patterns('',
url(r'^asset_del/$', asset_del),
url(r"^asset_detail/$", asset_detail),
url(r'^asset_edit/$', asset_edit),
url(r'^asset_search/$', asset_search),
# url(r'^search/$', host_search),
# url(r"^host_detail/$", host_detail),
# url(r"^dept_host_ajax/$", dept_host_ajax),

View File

@ -9,6 +9,7 @@ from django.shortcuts import get_object_or_404
from jasset.asset_api import *
from jumpserver.api import *
from jasset.forms import AssetForm
from jasset.models import Asset, IDC, AssetGroup, ASSET_TYPE, ASSET_STATUS
@require_role('admin')
@ -165,119 +166,6 @@ def asset_add(request):
esg = u'主机 %s 添加失败' % ip
return my_render('jasset/asset_add.html', locals(), request)
#
#
# @require_admin
# def host_add_batch(request):
# """ 批量添加主机 """
# header_title, path1, path2 = u'批量添加主机', u'资产管理', u'批量添加主机'
# login_types = {'LDAP': 'L', 'MAP': 'M'}
# active_types = {'激活': 1, '禁用': 0}
# dept_id = get_user_dept(request)
# if request.method == 'POST':
# multi_hosts = request.POST.get('j_multi').split('\n')
# for host in multi_hosts:
# if host == '':
# break
# j_ip, j_port, j_type, j_idc, j_groups, j_depts, j_active, j_comment = host.split()
# j_active = active_types[str(j_active)]
# j_group = ast.literal_eval(j_groups)
# j_dept = ast.literal_eval(j_depts)
#
# if j_type not in ['LDAP', 'MAP']:
# return httperror(request, u'没有%s这种登录方式!' %j_type)
#
# j_type = login_types[j_type]
# idc = IDC.objects.filter(name=j_idc)
# if idc:
# j_idc = idc[0].id
# else:
# return httperror(request, '添加失败, 没有%s这个IDC' % j_idc)
#
# group_ids, dept_ids = [], []
# for group_name in j_group:
# group = BisGroup.objects.filter(name=group_name)
# if group:
# group_id = group[0].id
# else:
# return httperror(request, '添加失败, 没有%s这个主机组' % group_name)
# group_ids.append(group_id)
#
# for dept_name in j_dept:
# dept = DEPT.objects.filter(name=dept_name)
# if dept:
# dept_id = dept[0].id
# else:
# return httperror(request, '添加失败, 没有%s这个部门' % dept_name)
# dept_ids.append(dept_id)
#
# if is_group_admin(request) and not validate(request, asset_group=group_ids, edept=dept_ids):
# return httperror(request, '添加失败, 没有%s这个主机组' % group_name)
#
# if Asset.objects.filter(ip=str(j_ip)):
# return httperror(request, '添加失败, 改IP%s已存在' % j_ip)
#
# host_info = [j_ip, j_port, j_idc, j_type, group_ids, dept_ids, j_active, j_comment]
# db_host_insert(host_info)
#
# smg = u'批量添加添加成功'
# return my_render('jasset/host_add_multi.html', locals(), request)
#
# return my_render('jasset/host_add_multi.html', locals(), request)
#
#
# @require_admin
# def host_edit_batch(request):
# """ 批量修改主机 """
# if request.method == 'POST':
# len_table = request.POST.get('len_table')
# for i in range(int(len_table)):
# j_id = "editable[" + str(i) + "][j_id]"
# j_ip = "editable[" + str(i) + "][j_ip]"
# j_port = "editable[" + str(i) + "][j_port]"
# j_dept = "editable[" + str(i) + "][j_dept]"
# j_idc = "editable[" + str(i) + "][j_idc]"
# j_type = "editable[" + str(i) + "][j_type]"
# j_group = "editable[" + str(i) + "][j_group]"
# j_active = "editable[" + str(i) + "][j_active]"
# j_comment = "editable[" + str(i) + "][j_comment]"
#
# j_id = request.POST.get(j_id).strip()
# j_ip = request.POST.get(j_ip).strip()
# j_port = request.POST.get(j_port).strip()
# j_dept = request.POST.getlist(j_dept)
# j_idc = request.POST.get(j_idc).strip()
# j_type = request.POST.get(j_type).strip()
# j_group = request.POST.getlist(j_group)
# j_active = request.POST.get(j_active).strip()
# j_comment = request.POST.get(j_comment).strip()
#
# host_info = [j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_active, j_comment]
# batch_host_edit(host_info)
#
# return HttpResponseRedirect('/jasset/host_list/')
#
#
# @require_role(role='user')
# def host_edit_common_batch(request):
# """ 普通用户批量修改主机别名 """
# u = get_session_user_info(request)[2]
# if request.method == 'POST':
# len_table = request.POST.get('len_table')
# for i in range(int(len_table)):
# j_id = "editable[" + str(i) + "][j_id]"
# j_alias = "editable[" + str(i) + "][j_alias]"
# j_id = request.POST.get(j_id, '').strip()
# j_alias = request.POST.get(j_alias, '').strip()
# a = Asset.objects.get(id=j_id)
# asset_alias = AssetAlias.objects.filter(user=u, host=a)
# if asset_alias:
# asset_alias = asset_alias[0]
# asset_alias.alias = j_alias
# asset_alias.save()
# else:
# AssetAlias.objects.create(user=u, host=a, alias=j_alias)
# return my_render('jasset/host_list_common.html', locals(), request)
@require_role(role='user')
@ -287,6 +175,10 @@ def asset_list(request):
列出资产表
"""
header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机'
idc_all = IDC.objects.filter()
asset_group_all = AssetGroup.objects.all()
asset_type = ASSET_TYPE
asset_status = ASSET_STATUS
keyword = request.GET.get('keyword', '')
gid = request.GET.get('gid', '') # asset group id
sid = request.GET.get('sid', '')
@ -309,8 +201,17 @@ def asset_del(request):
asset_id = request.GET.get('id', '')
if asset_id:
Asset.objects.filter(id=asset_id).delete()
if request.method == 'POST':
asset_batch = request.GET.get('arg', '')
asset_id_all = str(request.POST.get('asset_id_all', ''))
if asset_batch:
for asset_id in asset_id_all.split(','):
asset = get_object(Asset, id=asset_id)
asset.delete()
return HttpResponse(u'删除成功')
return Http404
@require_role(role='super')
@ -368,56 +269,11 @@ def asset_edit(request):
return my_render('jasset/asset_edit.html', locals(), request)
# @require_role(role='admin')
# def host_edit_adm(request):
# """ 部门管理员修改主机 """
# header_title, path1, path2 = u'修改主机', u'资产管理', u'修改主机'
# actives = {1: u'激活', 0: u'禁用'}
# login_types = {'L': 'LDAP', 'M': 'MAP'}
# eidc = IDC.objects.all()
# dept = get_session_user_info(request)[5]
# egroup = BisGroup.objects.exclude(name='ALL').filter(dept=dept)
# host_id = request.GET.get('id', '')
# post = Asset.objects.filter(id=int(host_id))
# if post:
# post = post[0]
# else:
# return httperror(request, '没有此主机!')
#
# e_group = post.bis_group.all()
#
# if request.method == 'POST':
# j_ip = request.POST.get('j_ip')
# j_idc = request.POST.get('j_idc')
# j_port = request.POST.get('j_port')
# j_type = request.POST.get('j_type')
# j_dept = request.POST.getlist('j_dept')
# j_group = request.POST.getlist('j_group')
# j_active = request.POST.get('j_active')
# j_comment = request.POST.get('j_comment')
#
# host_info = [j_ip, j_port, j_idc, j_type, j_group, j_dept, j_active, j_comment]
#
# if not validate(request, asset_group=j_group, edept=j_dept):
# emg = u'修改失败,您无权操作!'
# return my_render('jasset/asset_edit.html', locals(), request)
#
# if j_type == 'M':
# j_user = request.POST.get('j_user')
# j_password = request.POST.get('j_password')
# db_host_update(host_info, j_user, j_password, post)
# else:
# db_host_update(host_info, post)
#
# smg = u'主机 %s 修改成功' % j_ip
# return HttpResponseRedirect('/jasset/host_detail/?id=%s' % host_id)
#
# return my_render('jasset/asset_edit.html', locals(), request)
@require_role('admin')
def asset_detail(request):
""" 主机详情 """
"""
主机详情
"""
header_title, path1, path2 = u'主机详细信息', u'资产管理', u'主机详情'
asset_id = request.GET.get('id', '')
asset = get_object(Asset, id=asset_id)
@ -425,146 +281,82 @@ def asset_detail(request):
return my_render('jasset/asset_detail.html', locals(), request)
@require_role('user')
def asset_search(request):
"""
主机搜索
"""
idc_all = IDC.objects.filter()
asset_group_all = AssetGroup.objects.all()
asset_type = ASSET_TYPE
asset_status = ASSET_STATUS
idc_name = request.GET.get('idc', '')
group_name = request.GET.get('group', '')
asset_type = request.GET.get('asset_type', '')
status = request.GET.get('status', '')
keyword = request.GET.get('keyword', '')
#
#
# @require_admin
# def group_edit(request):
# """ 修改主机组 """
# header_title, path1, path2 = u'编辑主机组', u'资产管理', u'编辑主机组'
# group_id = request.GET.get('id', '')
# group = BisGroup.objects.filter(id=group_id)
# if group:
# group = group[0]
# else:
# httperror(request, u'没有这个主机组!')
#
# host_all = Asset.objects.all()
# dept_id = get_session_user_info(request)[3]
# eposts = Asset.objects.filter(bis_group=group)
#
# if is_group_admin(request) and not validate(request, asset_group=[group_id]):
# return httperror(request, '编辑失败, 您无权操作!')
# dept = DEPT.objects.filter(id=group.dept.id)
# if dept:
# dept = dept[0]
# else:
# return httperror(request, u'没有这个部门!')
#
# all_dept = dept.asset_set.all()
# posts = [g for g in all_dept if g not in eposts]
#
# if request.method == 'POST':
# j_group = request.POST.get('j_group', '')
# j_hosts = request.POST.getlist('j_hosts', '')
# j_dept = request.POST.get('j_dept', '')
# j_comment = request.POST.get('j_comment', '')
#
# j_dept = DEPT.objects.filter(id=int(j_dept))
# j_dept = j_dept[0]
#
# group.asset_set.clear()
# for host in j_hosts:
# g = Asset.objects.get(id=host)
# group.asset_set.add(g)
# BisGroup.objects.filter(id=group_id).update(name=j_group, dept=j_dept, comment=j_comment)
# smg = u'主机组%s修改成功' % j_group
# return HttpResponseRedirect('/jasset/group_list')
#
# return my_render('jasset/group_edit.html', locals(), request)
#
#
# @require_admin
# def group_detail(request):
# """ 主机组详情 """
# header_title, path1, path2 = u'主机组详情', u'资产管理', u'主机组详情'
# login_types = {'L': 'LDAP', 'M': 'MAP'}
# dept = get_session_user_info(request)[5]
# group_id = request.GET.get('id', '')
# group = BisGroup.objects.get(id=group_id)
# if is_super_user(request):
# posts = Asset.objects.filter(bis_group=group).order_by('ip')
#
# elif is_group_admin(request):
# if not validate(request, asset_group=[group_id]):
# return httperror(request, u'您无权查看!')
# posts = Asset.objects.filter(bis_group=group).filter(dept=dept).order_by('ip')
#
# contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
# return my_render('jasset/group_detail.html', locals(), request)
#
#
# @require_admin
# def group_del_host(request):
# """ 主机组中剔除主机, 并不删除真实主机 """
# if request.method == 'POST':
# group_id = request.POST.get('group_id')
# offset = request.GET.get('id', '')
# group = BisGroup.objects.get(id=group_id)
# if offset == 'group':
# len_list = request.POST.get("len_list")
# for i in range(int(len_list)):
# key = "id_list[" + str(i) + "]"
# jid = request.POST.get(key)
# g = Asset.objects.get(id=jid)
# group.asset_set.remove(g)
#
# else:
# offset = request.GET.get('id', '')
# group_id = request.GET.get('gid', '')
# group = BisGroup.objects.get(id=group_id)
# g = Asset.objects.get(id=offset)
# group.asset_set.remove(g)
#
# return HttpResponseRedirect('/jasset/group_detail/?id=%s' % group.id)
#
if not idc_name and not asset_type and not status and group_name == 'all':
select_number = 0
else:
select_number = 1
# @require_admin
# def dept_host_ajax(request):
# """ 添加主机组时, 部门联动主机异步 """
# dept_id = request.GET.get('id', '')
# if dept_id not in ['1', '2']:
# dept = DEPT.objects.filter(id=dept_id)
# if dept:
# dept = dept[0]
# hosts = dept.asset_set.all()
# else:
# hosts = Asset.objects.all()
#
# return my_render('jasset/dept_host_ajax.html', locals(), request)
#
#
# def show_all_ajax(request):
# """ 批量修改主机时, 部门和组全部显示 """
# env = request.GET.get('env', '')
# get_id = request.GET.get('id', '')
# host = Asset.objects.filter(id=get_id)
# if host:
# host = host[0]
# return my_render('jasset/show_all_ajax.html', locals(), request)
#
#
# @require_login
# def host_search(request):
# """ 搜索主机 """
# keyword = request.GET.get('keyword')
# login_types = {'L': 'LDAP', 'M': 'MAP'}
# dept = get_session_user_info(request)[5]
# post_all = Asset.objects.filter(Q(ip__contains=keyword) |
# Q(idc__name__contains=keyword) |
# Q(bis_group__name__contains=keyword) |
# Q(comment__contains=keyword)).distinct().order_by('ip')
# if is_super_user(request):
# posts = post_all
#
# elif is_group_admin(request):
# posts = post_all.filter(dept=dept)
#
# elif is_common_user(request):
# user_id, username = get_session_user_info(request)[0:2]
# post_perm = user_perm_asset_api(username)
# posts = list(set(post_all) & set(post_perm))
# contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
#
# return my_render('jasset/host_search.html', locals(), request)
if group_name == 'all':
asset_find = Asset.objects.filter(
idc__name__contains=idc_name,
asset_type__contains=asset_type,
status__contains=status
)
else:
asset_find = Asset.objects.filter(
idc__name__contains=idc_name,
group__name__contains=group_name,
asset_type__contains=asset_type,
status__contains=status
)
if keyword and select_number == 1:
asset_find = asset_find.filter(
Q(hostname__contains=keyword) |
Q(idc__name__contains=keyword) |
Q(ip__contains=keyword) |
Q(remote_ip__contains=keyword) |
Q(comment__contains=keyword) |
Q(group__name__contains=keyword) |
Q(cpu__contains=keyword) |
Q(memory__contains=keyword) |
Q(disk__contains=keyword))
elif keyword:
asset_find = Asset.objects.filter(
Q(hostname__contains=keyword) |
Q(idc__name__contains=keyword) |
Q(ip__contains=keyword) |
Q(remote_ip__contains=keyword) |
Q(comment__contains=keyword) |
Q(group__name__contains=keyword) |
Q(cpu__contains=keyword) |
Q(memory__contains=keyword) |
Q(disk__contains=keyword))
# asset_find = list(set(asset_find))
# asset_find_dic = {}
# asset_find_lis = []
# for server in asset_find:
# if server.ip:
# asset_find_dic[server.ip] = server
# asset_find_lis.append(server.ip)
# sort_ip_list(asset_find_lis)
# asset_find = []
# for ip in asset_find_lis:
# asset_find.append(asset_find_dic[ip])
# search_status = request.GET.get("_search", False)
# if search_status:
# s = write_excel(asset_find)
# if s[0]:
# file_name = s[1]
# smg = 'excel文件已生成请点击下载!'
# return my_render('cmdb/excel_download.html', locals(), request)
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(asset_find, request)
return my_render('jasset/asset_list.html', locals(), request)

View File

@ -119,3 +119,11 @@ function selectAll(){
// })
//}
function getIDall() {
var check_array = [];
$(".gradeX input:checked").each(function () {
var id = $(this).attr("value");
check_array.push(id);
});
return check_array.join(",");
}

View File

@ -23,22 +23,31 @@
</div>
<div class="ibox-content">
<form id="asset_form">
<div class="col-sm-2" style="padding-left: 0px">
<label>
<select name="change_idc" class="form-control m-b" onchange="change_info()">
<select name="idc" class="form-control m-b" onchange="change_info()">
<option value="">IDC机房</option>
{% for i in idcs %}
<option value="{{i.name}}"> {{ i }}</option>
{% for idc in idc_all %}
{% ifequal idc.name idc_name %}
<option value="{{idc.name}}" selected> {{ idc.name }}</option>
{% else %}
<option value="{{idc.name}}"> {{ idc.name }}</option>
{% endifequal %}
{% endfor %}
</select>
</label>
</div>
<div class="col-sm-2">
<label>
<select name="change_project" class="form-control m-b" onchange="change_info()">
<select name="group" class="form-control m-b" onchange="change_info()">
<option value="all">主机组</option>
{% for i in projects %}
<option value="{{ i.name }}"> {{ i.name }} </option>
{% for asset_group in asset_group_all %}
{% ifequal asset_group.name group_name %}
<option value="{{ asset_group.name }}" selected> {{ asset_group.name }} </option>
{% else %}
<option value="{{ asset_group.name }}"> {{ asset_group.name }} </option>
{% endifequal %}
{% endfor %}
</select>
</label>
@ -46,20 +55,28 @@
<div class="col-sm-2">
<label>
<select name="change_type" class="form-control m-b" onchange="change_info()">
<select name="server_type" class="form-control m-b" onchange="change_info()">
<option value="">所有类型</option>
{% for i in server_type %}
<option value="{{ i.0 }}"> {{ i.1 }}</option>
{% for type in asset_type %}
{% ifequal type.0|int2str asset_type %}
<option value="{{ type.0 }}" selected> {{ type.1 }}</option>
{% else %}
<option value="{{ type.0 }}"> {{ type.1 }}</option>
{% endifequal %}
{% endfor %}
</select>
</label>
</div>
<div class="col-sm-2">
<label>
<select name="change_type" class="form-control m-b" onchange="change_info()">
<select name="status" class="form-control m-b" onchange="change_info()">
<option value="">状态</option>
{% for i in server_type %}
<option value="{{ i.0 }}"> {{ i.1 }}</option>
{% for status in asset_status %}
{% ifequal status.0|int2str status %}
<option value="{{ status.0 }}" selected> {{ status.1 }}</option>
{% else %}
<option value="{{ status.0 }}"> {{ status.1 }}</option>
{% endifequal %}
{% endfor %}
</select>
</label>
@ -78,7 +95,6 @@
</form>
</div>
<form id="contents_form" name="contents_form">
<table class="table table-striped table-bordered table-hover " id="editable" name="editable">
<thead>
<tr>
@ -119,13 +135,13 @@
</table>
<div class="row">
<div class="col-sm-6">
<input type="button" id="del_button" class="btn btn-danger btn-sm" name="del_button" value="删除" onclick="del('contents_form')" />
<input type="button" id="asset_del" class="btn btn-danger btn-sm" name="del_button" value="删除"/>
<input type="button" id="alter_button" class="btn btn-warning btn-sm" name="alter_button" value="修改" onclick="alter('contents_form')" />
</div>
{% include 'paginator.html' %}
</div>
</form>
</div>
</form>
</div>
</div>
</div>
@ -180,38 +196,31 @@
}
}
function del(form) {
var checkboxes = document.getElementById(form);
var id_list = {};
var j = 0;
for (var i = 0; i < checkboxes.elements.length; i++) {
if (checkboxes.elements[i].type == "checkbox" && checkboxes.elements[i].checked == true && checkboxes.elements[i].value != "checkall") {
id_list[j] = checkboxes.elements[i].value;
j++;
}
$('#asset_del').click(function () {
var asset_id_all = getIDall();
console.log(asset_id_all);
if (asset_id_all == ''){
alert("请至少选择一行!");
return false;
}
if (confirm("确定删除")) {
$.ajax({
type: "POST",
url: "/jasset/host_del/multi/",
data: {"id_list": id_list, "len_list": j},
success: function (data) {
window.open("/jasset/host_list/", "_self");
type: "post",
data: {asset_id_all: asset_id_all},
url: "/jasset/asset_del/?arg=batch",
success: function () {
window.open("/jasset/asset_list/", "_self");
}
});
}
});
function change_info(){
var args = $("#asset_form").serialize();
window.location = "/jasset/asset_search/?" + args
}
{# function host_search(){#}
{# $.ajax({#}
{# type: "GET",#}
{# url: "/jasset/search/",#}
{# data: $("#search_form").serialize(),#}
{# success: function (data) {#}
{# $("#contents_form").html(data);#}
{# }#}
{# });#}
{# }#}
$("#search_input").keydown(function(e){
if(e.keyCode==13){