Beispiel #1
0
def asset(request):
    temp_name = "cmdb/cmdb-header.html"
    webssh_domain = get_dir("webssh_domain")
    asset_find = []
    idc_info = Idc.objects.all()
    host_list = Host.objects.all()
    group_info = HostGroup.objects.all()
    asset_types = 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', '')
    export = request.GET.get("export", '')
    group_id = request.GET.get("group_id", '')
    idc_id = request.GET.get("idc_id", '')
    asset_id_all = request.GET.getlist("id", '')

    if group_id:
        group = get_object(HostGroup, id=group_id)
        if group:
            asset_find = Host.objects.filter(group=group)
    elif idc_id:
        idc = get_object(Idc, id=idc_id)
        if idc:
            asset_find = Host.objects.filter(idc=idc)
    else:
        asset_find = Host.objects.all()
    if idc_name:
        asset_find = asset_find.filter(idc__name__contains=idc_name)
    if group_name:
        asset_find = asset_find.filter(group__name__contains=group_name)
    if asset_type:
        asset_find = asset_find.filter(asset_type__contains=asset_type)
    if status:
        asset_find = asset_find.filter(status__contains=status)
    if keyword:
        asset_find = asset_find.filter(
            Q(hostname__contains=keyword) |
            Q(ip__contains=keyword) |
            Q(other_ip__contains=keyword) |
            Q(os__contains=keyword) |
            Q(vendor__contains=keyword) |
            Q(cpu_model__contains=keyword) |
            Q(cpu_num__contains=keyword) |
            Q(memory__contains=keyword) |
            Q(disk__contains=keyword) |
            Q(sn__contains=keyword) |
            Q(position__contains=keyword) |
            Q(memo__contains=keyword))
    if export:
        response = create_asset_excel(export, asset_id_all)
        return response
    assets_list, p, assets, page_range, current_page, show_first, show_end = pages(asset_find, request)
    return render(request, 'cmdb/index.html', locals())
Beispiel #2
0
def job_interval_edit(request, ids):
    status = 0
    obj = get_object(IntervalSchedule, id=ids)

    if request.method == 'POST':
        form = IntervalForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = IntervalForm(instance=obj)

    return render_to_response('setup/interval_edit.html', locals(), RequestContext(request))
Beispiel #3
0
def asset_del(request):
    asset_id = request.GET.get('id', '')
    if asset_id:
        Host.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_item = get_object(Host, id=asset_id)
                asset_item.delete()

    return HttpResponse(u'删除成功')
Beispiel #4
0
def job_result_edit(request, ids):
    status = 0
    obj = get_object(TaskResult, id=ids)

    if request.method == 'POST':
        form = TaskResultForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = TaskResultForm(instance=obj)

    return render_to_response('setup/result_edit.html', locals(), RequestContext(request))
Beispiel #5
0
def job_edit(request, ids):
    status = 0
    obj = get_object(PeriodicTask, id=ids)

    if request.method == 'POST':
        form = PeriodicTaskForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = PeriodicTaskForm(instance=obj)

    return render(request, 'setup/job_edit.html', locals())
Beispiel #6
0
def asset_edit(request, ids):
    status = 0
    # asset_types = ASSET_TYPE
    obj = get_object(models.Host, id=ids)
    if request.method == 'POST':
        form = AssetForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        af = AssetForm(instance=obj)

    return render(request, 'cmdb/asset_edit.html', locals())
Beispiel #7
0
def job_interval_edit(request, ids):
    status = 0
    obj = get_object(IntervalSchedule, id=ids)

    if request.method == 'POST':
        form = IntervalForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = IntervalForm(instance=obj)

    return render(request, 'setup/interval_edit.html', locals())
Beispiel #8
0
def asset_del(request):
    asset_id = request.GET.get('id', '')
    if asset_id:
        Host.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_item = get_object(Host, id=asset_id)
                asset_item.delete()

    return HttpResponse(u'删除成功')
Beispiel #9
0
def job_edit(request, ids):
    status = 0
    obj = get_object(PeriodicTask, id=ids)

    if request.method == 'POST':
        form = PeriodicTaskForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = PeriodicTaskForm(instance=obj)

    return render(request, 'setup/job_edit.html', locals())
Beispiel #10
0
def job_crontab_edit(request, ids):
    status = 0
    obj = get_object(CrontabSchedule, id=ids)

    if request.method == 'POST':
        form = CrontabForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = CrontabForm(instance=obj)

    return render(request, 'setup/crontab_edit.html', locals())
Beispiel #11
0
def asset_edit(request, ids):
    status = 0
    asset_types = ASSET_TYPE
    obj = get_object(Host, id=ids)

    if request.method == 'POST':
        af = AssetForm(request.POST, instance=obj)
        if af.is_valid():
            af.save()
            status = 1
        else:
            status = 2
    else:
        af = AssetForm(instance=obj)

    return render(request, 'cmdb/asset_edit.html', locals())
Beispiel #12
0
def instance_del(request):
    if 'GET' == request.method:
        instance_id = request.GET.get('id', '')
        if instance_id:
            Instance.objects.filter(id=instance_id).delete()
        return HttpResponseRedirect(reverse('instance_index'))

    if 'POST' == request.method:
        instance_batch = request.GET.get('arg', '')
        instance_id_all = str(request.POST.get('instance_id_all', ''))

        if instance_batch:
            for instance_id in instance_id_all.split(','):
                instance_instance = get_object(Instance, id=instance_id)
                instance_instance.delete()

    return HttpResponse(u'删除成功')
Beispiel #13
0
def trigger_del(request):
    if 'GET' == request.method:
        trigger_id = request.GET.get('id', '')
        if trigger_id:
            Trigger.objects.filter(id=trigger_id).delete()
        return HttpResponseRedirect(reverse('trigger_index'))

    if 'POST' == request.method:
        trigger_batch = request.GET.get('arg', '')
        trigger_id_all = str(request.POST.get('trigger_id_all', ''))

        if trigger_batch:
            for trigger_id in trigger_id_all.split(','):
                trigger_trigger = get_object(Trigger, id=trigger_id)
                trigger_trigger.delete()

    return HttpResponse(u'删除成功')
Beispiel #14
0
def rule_del(request):
    if 'GET' == request.method:
        rule_id = request.GET.get('id', '')
        if rule_id:
            Rule.objects.filter(id=rule_id).delete()
        return HttpResponseRedirect(reverse('rule_index'))

    if 'POST' == request.method:
        rule_batch = request.GET.get('arg', '')
        rule_id_all = str(request.POST.get('rule_id_all', ''))

        if rule_batch:
            for rule_id in rule_id_all.split(','):
                rule_rule = get_object(Rule, id=rule_id)
                rule_rule.delete()

    return HttpResponse(u'删除成功')
Beispiel #15
0
def item_del(request):
    if 'GET' == request.method:
        item_id = request.GET.get('id', '')
        if item_id:
            Item.objects.filter(id=item_id).delete()
        return HttpResponseRedirect(reverse('item_index'))

    if 'POST' == request.method:
        item_batch = request.GET.get('arg', '')
        item_id_all = str(request.POST.get('item_id_all', ''))

        if item_batch:
            for item_id in item_id_all.split(','):
                item_item = get_object(Item, id=item_id)
                item_item.delete()

    return HttpResponse(u'删除成功')
Beispiel #16
0
def create_asset_excel(export, asset_id_all):
    if export == "true":
        if asset_id_all:
            asset_find = []
            for asset_id in asset_id_all:
                asset_item = get_object(Host, id=asset_id)
                if asset_item:
                    asset_find.append(asset_item)
            response = HttpResponse(content_type='text/csv')
            now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
            file_name = 'adminset_cmdb_' + now + '.csv'
            response[
                'Content-Disposition'] = "attachment; filename=" + file_name
            writer = csv.writer(response)
            writer.writerow([
                str2gb(u'主机名'),
                str2gb(u'IP地址'),
                str2gb(u'其它IP'),
                str2gb(u'所在机房'),
                str2gb(u'资产编号'),
                str2gb(u'设备类型'),
                str2gb(u'设备状态'),
                str2gb(u'操作系统'),
                str2gb(u'设备厂商'),
                str2gb(u'CPU型号'),
                str2gb(u'CPU核数'),
                str2gb(u'内存大小'),
                str2gb(u'硬盘信息'),
                str2gb(u'SN号码'),
                str2gb(u'所在位置'),
                str2gb(u'备注信息')
            ])
            for h in asset_find:
                if h.asset_type:
                    at_num = int(h.asset_type)
                    a_type = ASSET_TYPE[at_num - 1][1]
                else:
                    a_type = ""
                if h.status:
                    at_as = int(h.status)
                    a_status = ASSET_STATUS[at_as - 1][1]
                else:
                    a_status = ""
                writer.writerow([
                    str2gb(h.hostname), h.ip, h.other_ip,
                    str2gb(h.idc),
                    str2gb(h.asset_no),
                    str2gb(a_type),
                    str2gb(a_status),
                    str2gb(h.os),
                    str2gb(h.vendor),
                    str2gb(h.cpu_model),
                    str2gb(h.cpu_num),
                    str2gb(h.memory),
                    str2gb(h.disk),
                    str2gb(h.sn),
                    str2gb(h.position),
                    str2gb(h.memo)
                ])
            return response

    if export == "all":
        host = Host.objects.all()
        response = HttpResponse(content_type='text/csv')
        now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
        file_name = 'adminset_cmdb_' + now + '.csv'
        response['Content-Disposition'] = "attachment; filename=" + file_name
        writer = csv.writer(response)
        writer.writerow([
            str2gb('主机名'),
            str2gb('IP地址'),
            str2gb('其它IP'),
            str2gb('所在机房'),
            str2gb('资产编号'),
            str2gb('设备类型'),
            str2gb('设备状态'),
            str2gb('操作系统'),
            str2gb('设备厂商'),
            str2gb('CPU型号'),
            str2gb('CPU核数'),
            str2gb('内存大小'),
            str2gb('硬盘信息'),
            str2gb('SN号码'),
            str2gb('所在位置'),
            str2gb('备注信息')
        ])
        for h in host:
            if h.asset_type:
                at_num = int(h.asset_type)
                a_type = ASSET_TYPE[at_num - 1][1]
            else:
                a_type = ""
            if h.status:
                at_as = int(h.status)
                a_status = ASSET_STATUS[at_as - 1][1]
            else:
                a_status = ""
            writer.writerow([
                str2gb(h.hostname), h.ip, h.other_ip,
                str2gb(h.idc),
                str2gb(h.asset_no),
                str2gb(a_type),
                str2gb(a_status),
                str2gb(h.os),
                str2gb(h.vendor),
                str2gb(h.cpu_model),
                str2gb(h.cpu_num),
                str2gb(h.memory),
                str2gb(h.disk),
                str2gb(h.sn),
                str2gb(h.position),
                str2gb(h.memo)
            ])
        return response
Beispiel #17
0
def asset(request):
    temp_name = "cmdb/cmdb-header.html"
    webssh_domain = get_dir("webssh_domain")
    asset_find = []
    idc_info = Idc.objects.all()
    host_list = Host.objects.all()
    group_info = HostGroup.objects.all()
    asset_types = 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', '')
    export = request.GET.get("export", '')
    group_id = request.GET.get("group_id", '')
    cabinet_id = request.GET.get("cabinet_id", '')
    idc_id = request.GET.get("idc_id", '')
    asset_id_all = request.GET.getlist("id", '')

    if group_id:
        group = get_object(HostGroup, id=group_id)
        if group:
            asset_find = Host.objects.filter(group=group)

    if cabinet_id:
        cabinet = get_object(Cabinet, id=cabinet_id)
        if cabinet:
            asset_find = Host.objects.filter(cabinet=cabinet)

    elif idc_id:
        idc = get_object(Idc, id=idc_id)
        if idc:
            asset_find = Host.objects.filter(idc=idc)
    else:
        asset_find = Host.objects.all()
    if idc_name:
        asset_find = asset_find.filter(idc__name__contains=idc_name)
    if group_name:
        get_group = HostGroup.objects.get(name=group_name)
        asset_find = get_group.serverList.all()
    if asset_type:
        asset_find = asset_find.filter(asset_type__contains=asset_type)
    if status:
        asset_find = asset_find.filter(status__contains=status)
    if keyword:
        asset_find = asset_find.filter(
            Q(hostname__contains=keyword) |
            Q(ip__contains=keyword) |
            Q(other_ip__contains=keyword) |
            Q(os__contains=keyword) |
            Q(vendor__contains=keyword) |
            Q(cpu_model__contains=keyword) |
            Q(cpu_num__contains=keyword) |
            Q(memory__contains=keyword) |
            Q(disk__contains=keyword) |
            Q(sn__contains=keyword) |
            Q(position__contains=keyword) |
            Q(memo__contains=keyword))
    if export:
        response = create_asset_excel(export, asset_id_all)
        return response
    assets_list, p, assets, page_range, current_page, show_first, show_end = pages(asset_find, request)
    return render(request, 'cmdb/index.html', locals())
Beispiel #18
0
def create_asset_excel(export, asset_id_all):
    if export == "true":
        if asset_id_all:
            asset_find = []
            for asset_id in asset_id_all:
                asset_item = get_object(Host, id=asset_id)
                if asset_item:
                    asset_find.append(asset_item)
            response = HttpResponse(content_type='text/csv')
            now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
            file_name = 'adminset_cmdb_' + now + '.csv'
            response['Content-Disposition'] = "attachment; filename="+file_name
            writer = csv.writer(response)
            writer.writerow([str2gb(u'主机名'), str2gb(u'IP地址'), str2gb(u'其它IP'), str2gb(u'主机组'),
                             str2gb(u'资产编号'), str2gb(u'设备类型'), str2gb(u'设备状态'), str2gb(u'操作系统'),
                             str2gb(u'设备厂商'), str2gb(u'CPU型号'), str2gb(u'CPU核数'), str2gb(u'内存大小'),
                             str2gb(u'硬盘信息'), str2gb(u'SN号码'), str2gb(u'所在机房'), str2gb(u'所在位置'),
                             str2gb(u'备注信息')])
            for h in asset_find:
                if h.asset_type:
                    at_num = int(h.asset_type)
                    a_type = ASSET_TYPE[at_num-1][1]
                else:
                    a_type = ""
                if h.status:
                    at_as = int(h.status)
                    a_status = ASSET_STATUS[at_as-1][1]
                else:
                    a_status = ""
                writer.writerow([str2gb(h.hostname), h.ip, h.other_ip, str2gb(h.group), str2gb(h.asset_no),
                                 str2gb(a_type), str2gb(a_status), str2gb(h.os), str2gb(h.vendor),
                                 str2gb(h.cpu_model), str2gb(h.cpu_num), str2gb(h.memory), str2gb(h.disk),
                                 str2gb(h.sn), str2gb(h.idc), str2gb(h.position), str2gb(h.memo)])
            return response

    if export == "all":
        host = Host.objects.all()
        response = HttpResponse(content_type='text/csv')
        now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
        file_name = 'adminset_cmdb_' + now + '.csv'
        response['Content-Disposition'] = "attachment; filename=" + file_name
        writer = csv.writer(response)
        writer.writerow([str2gb('主机名'), str2gb('IP地址'), str2gb('其它IP'), str2gb('主机组'), str2gb('资产编号'),
                         str2gb('设备类型'), str2gb('设备状态'), str2gb('操作系统'), str2gb('设备厂商'), str2gb('CPU型号'),
                         str2gb('CPU核数'), str2gb('内存大小'), str2gb('硬盘信息'), str2gb('SN号码'), str2gb('所在机房'),
                         str2gb('所在位置'), str2gb('备注信息')])
        for h in host:
            if h.asset_type:
                at_num = int(h.asset_type)
                a_type = ASSET_TYPE[at_num-1][1]
            else:
                a_type = ""
            if h.status:
                at_as = int(h.status)
                a_status = ASSET_STATUS[at_as-1][1]
            else:
                a_status = ""
            writer.writerow([str2gb(h.hostname), h.ip, h.other_ip, str2gb(h.group), str2gb(h.asset_no), str2gb(a_type),
                             str2gb(a_status), str2gb(h.os), str2gb(h.vendor), str2gb(h.cpu_model), str2gb(h.cpu_num),
                             str2gb(h.memory), str2gb(h.disk), str2gb(h.sn), str2gb(h.idc), str2gb(h.position),
                             str2gb(h.memo)])
        return response