Esempio n. 1
0
def collect(request):
    req = request
    if req.method == 'POST':
        vender = req.POST.get('vender')
        product = req.POST.get('product')
        cpu_model = req.POST.get('cpu_model')
        cpu_num = req.POST.get('cpu_num')
        memory = req.POST.get('memory')
        sn = req.POST.get('sn')
        osver = req.POST.get('osver')
        hostname = req.POST.get('hostname')
        ipaddrs = req.POST.get('ipaddrs')

        host = Host()
        host.vender = vender
        host.product = product
        host.cpu_model = cpu_model
        host.cpu_num = int(cpu_num)
        host.memory = int(memory)
        host.sn = sn
        host.osver = osver
        host.hostname = hostname

        host.save()

        for ip in ipaddrs.split(':'):
            o_ip = IpAddr()
            o_ip.ipaddr = ip
            o_ip.host = host
            o_ip.save()

        return HttpResponse('OK')
    else:
        return HttpResponse('No post data')
Esempio n. 2
0
def collect(request):
    req = request
    if req.POST:
        vendor = req.POST.get('vendor')
        product = req.POST.get('product')
        cpu_model = req.POST.get('cpu_model')
        cpu_num = req.POST.get('cpu_num')
        memory = req.POST.get('memory')
        sn = req.POST.get('sn')
        osver = req.POST.get('osver')
        hostname = req.POST.get('hostname')
        try:
            host = Host.objects.get(hostname=hostname)
        except:
            host = Host()
        host.hostname=hostname
        host.product=product
        host.cpu_num=int(cpu_num)
        host.cpu_model=cpu_model
        host.memory = int(memory)
        host.sn = sn
        host.osver = osver
        host.vendor = vendor
        host.ipaddr = req.POST.get('ip')
        host.save()
        return HttpResponse("ok")
    else:
        return HttpResponse("no post data")
Esempio n. 3
0
def collect(request):
    req = request
    if req.POST:
        vendor = req.POST.get('Product_Name')
        sn = req.POST.get('Serial_Number')
        product = req.POST.get('Manufacturer')
        cpu_model = req.POST.get('Model_Name')
        cpu_num = req.POST.get('Cpu_Cores')
        cpu_vendor = req.POST.get('Vendor_Id')
        memory_part_number = req.POST.get('Part_Number')
        memory_manufacturer = req.POST.get('Manufacturer')
        memory_size = req.POST.get('Size')
        #uuid = req.POST.get('UUID')
        identity = req.POST.get('identity')
        device_model = req.POST.get('Device_Model')
        device_version = req.POST.get('Firmware_Version')
        device_sn = req.POST.get('Serial_Number')
        device_size = req.POST.get('User_Capacity')
        osver = req.POST.get('os_version')
        hostname = req.POST.get('os_name')
        os_release = req.POST.get('os_release')
        ipaddrs = req.POST.get('Ipaddr')
        mac = req.POST.get('Device')
        link = req.POST.get('Link')
        mask = req.POST.get('Mask')
        device = req.POST.get('Device')

        host = Host()
        host.hostname = hostname
        host.product = product
        host.cpu_num = cpu_num
        host.cpu_model = cpu_model
        host.cpu_vendor = cpu_vendor
        host.memory_part_number = memory_part_number
        host.memory_manufacturer = memory_manufacturer
        host.memory_size = memory_size
        host.device_model = device_model
        host.device_version = device_version
        host.device_sn = device_sn
        host.device_size = device_size
        host.osver = osver
        host.os_release = os_release
        host.vendor = vendor
        #host.uuid = uuid
        host.identity = identity
        host.sn = sn
        host.ipaddr = ipaddrs
        host.save()

        #for ip in ipaddrs.split(';'):
        #    o_ip = IPaddr()
        #    o_ip.ipaddr = ip
        #    o_ip.host = host
        #    o_ip.save()

        return HttpResponse('OK')
    else:
        return HttpResponse('no post data')
Esempio n. 4
0
def collect(request):
    req = request
    if req.POST:
        vendor = req.POST.get('Product_Name')
        sn = req.POST.get('Serial_Number')
        product = req.POST.get('Manufacturer')
        cpu_model = req.POST.get('Model_Name')
        cpu_num = req.POST.get('Cpu_Cores')
        cpu_vendor = req.POST.get('Vendor_Id')
        memory_part_number = req.POST.get('Part_Number')
        memory_manufacturer = req.POST.get('Manufacturer')
        memory_size = req.POST.get('Size')
        #uuid = req.POST.get('UUID')
        identity = req.POST.get('identity')
        device_model = req.POST.get('Device_Model')
        device_version = req.POST.get('Firmware_Version')
        device_sn = req.POST.get('Serial_Number')
        device_size = req.POST.get('User_Capacity')
        osver = req.POST.get('os_version')
        hostname = req.POST.get('os_name')
        os_release = req.POST.get('os_release')
        ipaddrs = req.POST.get('Ipaddr')
        mac = req.POST.get('Device')
        link = req.POST.get('Link')
        mask = req.POST.get('Mask')
        device = req.POST.get('Device')
 
        host = Host()
        host.hostname = hostname
        host.product = product
        host.cpu_num = cpu_num
        host.cpu_model = cpu_model
        host.cpu_vendor = cpu_vendor
        host.memory_part_number = memory_part_number
        host.memory_manufacturer = memory_manufacturer
        host.memory_size = memory_size
        host.device_model = device_model
        host.device_version = device_version
        host.device_sn = device_sn
        host.device_size = device_size
        host.osver = osver
        host.os_release = os_release
        host.vendor = vendor
        #host.uuid = uuid
        host.identity = identity
        host.sn = sn
        host.ipaddr = ipaddrs 
        host.save()
       
        #for ip in ipaddrs.split(';'):
        #    o_ip = IPaddr()
        #    o_ip.ipaddr = ip
        #    o_ip.host = host
        #    o_ip.save()
          
        return HttpResponse('OK')
    else:
        return HttpResponse('no post data')
Esempio n. 5
0
def collect(request):
    asset_info = json.loads(request.body)
    if request.method == 'POST':
        vendor = asset_info['vendor']
        # group = asset_info['group']
        disk = asset_info['disk']
        cpu_model = asset_info['cpu_model']
        cpu_num = asset_info['cpu_num']
        memory = asset_info['memory']
        sn = asset_info['sn']
        osver = asset_info['osver']
        hostname = asset_info['hostname']
        ip = asset_info['ip']
        mgm_ip = asset_info['mgm_ip']
        terminal_user = asset_info['terminal_user']
        # asset_type = ""
        # status = ""
        try:
            host = Host.objects.get(hostname=hostname)
        except Exception as msg:
            print(msg)
            host = Host()
            level = get_dir("log_level")
            ssh_pwd = get_dir("ssh_pwd")
            log_path = get_dir("log_path")
            log("cmdb.log", level, log_path)
            logging.info("==========sshkey deploy start==========")
            data = deploy_key(ip, ssh_pwd)
            logging.info(data)
            logging.info("==========sshkey deploy end==========")

        # if req.POST.get('identity'):
        #     identity = req.POST.get('identity')
        #     try:
        #         host = Host.objects.get(identity=identity)
        #     except:
        #         host = Host()
        host.hostname = hostname
        # host.group = group
        host.cpu_num = int(cpu_num)
        host.cpu_model = cpu_model
        host.memory = int(memory)
        host.sn = sn
        host.disk = disk
        host.os = osver
        host.vendor = vendor
        host.ip = ip
        host.mgm_ip = mgm_ip
        host.terminal_user = terminal_user
        # host.asset_type = asset_type
        # host.status = status
        host.save()
        return HttpResponse("Post asset data to server successfully!")
    else:
        return HttpResponse("No any post data!")
Esempio n. 6
0
def collect(request):
    asset_info = json.loads(request.body)
    if request.method == 'POST':
        vendor = asset_info['vendor']
        # group = asset_info['group']
        disk = asset_info['disk']
        cpu_model = asset_info['cpu_model']
        cpu_num = asset_info['cpu_num']
        memory = asset_info['memory']
        sn = asset_info['sn']
        osver = asset_info['osver']
        hostname = asset_info['hostname']
        ip = asset_info['ip']
        if not ip or not hostname:
            return HttpResponse("Error your agent ip or hostname is empty! Please resolve your hostname.")
        # asset_type = ""
        # status = ""
        try:
            host = Host.objects.get(hostname=hostname)
        except Exception as msg:
            print(msg)
            host = Host()
            level = get_dir("log_level")
            ssh_pwd = get_dir("ssh_pwd")
            log_path = get_dir("log_path")
            log("cmdb.log", level, log_path)
            logging.info("==========sshkey deploy start==========")
            data = deploy_key(ip, ssh_pwd)
            logging.info(data)
            logging.info("==========sshkey deploy end==========")

        # if req.POST.get('identity'):
        #     identity = req.POST.get('identity')
        #     try:
        #         host = Host.objects.get(identity=identity)
        #     except:
        #         host = Host()
        host.hostname = hostname
        # host.group = group
        host.cpu_num = int(cpu_num)
        host.cpu_model = cpu_model
        host.memory = int(memory)
        host.sn = sn
        host.disk = disk
        host.os = osver
        host.vendor = vendor
        host.ip = ip
        # host.asset_type = asset_type
        # host.status = status
        host.save()
        return HttpResponse("Post asset data to server successfully!")
    else:
        return HttpResponse("No any post data!")
Esempio n. 7
0
def collect(request):
    req = request
    if req.POST:
        vendor = req.POST.get('Product_Name')
        sn = req.POST.get('Serial_Number')
        product = req.POST.get('Manufacturer')
        cpu_model = req.POST.get('Model_Name')
        cpu_num = req.POST.get('Cpu_Cores')
        cpu_vendor = req.POST.get('Vendor_Id')
        memory_part_number = req.POST.get('Part_Number')
        memory_manufacturer = req.POST.get('Manufacturer')
        memory_size = req.POST.get('Size')
        device_model = req.POST.get('Device_Model')
        device_version = req.POST.get('Firmware_Version')
        device_sn = req.POST.get('Serial_Number')
        device_size = req.POST.get('User_Capacity')
        osver = req.POST.get('os_version')
        hostname = req.POST.get('os_name')
        os_release = req.POST.get('os_release')
        ipaddrs = req.POST.get('Ipaddr')
        mac = req.POST.get('Device')
        link = req.POST.get('Link')
        mask = req.POST.get('Mask')
        device = req.POST.get('Device')
        host = Host()
        host.hostname = hostname
        host.product = product
        host.cpu_num = cpu_num
        host.cpu_model = cpu_model
        host.cpu_vendor = cpu_vendor
        host.memory_part_number = memory_part_number
        host.memory_manufacturer = memory_manufacturer
        host.memory_size = memory_size
        host.device_model = device_model
        host.device_version = device_version
        host.device_sn = device_sn
        host.device_size = device_size
        host.osver = osver
        host.os_release = os_release
        host.vendor = vendor
        host.sn = sn
        host.ipaddr = ipaddrs
        host.save()       #将客户端传过来的数据通过POST接收,存入数据库
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
        return HttpResponse('OK')   #如果插入成功,返回'ok'
    else:
        return HttpResponse('no post data')
Esempio n. 8
0
def collect(request):
    req = request
    if req.POST:
        vendor = req.POST.get('vendor')
        group = req.POST.get('group')
        disk = req.POST.get('disk')
        cpu_model = req.POST.get('cpu_model')
        cpu_num = req.POST.get('cpu_num')
        memory = req.POST.get('memory')
        sn = req.POST.get('sn')
        osver = req.POST.get('osver')
        hostname = req.POST.get('hostname')
        ip = req.POST.get('ip')
        asset_type = ""
        status = ""
        try:
            host = Host.objects.get(hostname=hostname)
        except:
            host = Host()
        # if req.POST.get('identity'):
        #     identity = req.POST.get('identity')
        #     try:
        #         host = Host.objects.get(identity=identity)
        #     except:
        #         host = Host()
        host.hostname = hostname
        #host.group = group
        host.cpu_num = int(cpu_num)
        host.cpu_model = cpu_model
        host.memory = int(memory)
        host.sn = sn
        host.disk = disk
        host.os = osver
        host.vendor = vendor
        host.ip = ip
        host.asset_type = asset_type
        host.status = status
        host.save()
        return HttpResponse("post data successfully!")
    else:
        return HttpResponse("no any post data!")
Esempio n. 9
0
def collect(request):
    asset_info = json.loads(request.body)
    if request.method == 'POST':
        vendor = asset_info['vendor']
        # group = asset_info['group']
        disk = asset_info['disk']
        cpu_model = asset_info['cpu_model']
        cpu_num = asset_info['cpu_num']
        memory = asset_info['memory']
        sn = asset_info['sn']
        osver = asset_info['osver']
        hostname = asset_info['hostname']
        ip = asset_info['ip']
        asset_type = ""
        status = ""
        try:
            host = Host.objects.get(hostname=hostname)
        except:
            host = Host()
        # if req.POST.get('identity'):
        #     identity = req.POST.get('identity')
        #     try:
        #         host = Host.objects.get(identity=identity)
        #     except:
        #         host = Host()
        host.hostname = hostname
        # host.group = group
        host.cpu_num = int(cpu_num)
        host.cpu_model = cpu_model
        host.memory = int(memory)
        host.sn = sn
        host.disk = disk
        host.os = osver
        host.vendor = vendor
        host.ip = ip
        host.asset_type = asset_type
        host.status = status
        host.save()
        return HttpResponse("Post asset data to server successfully!")
    else:
        return HttpResponse("No any post data!")
Esempio n. 10
0
def collect(request):
    req = request
    if req.POST:
        vendor = req.POST.get('vendor')
        product = req.POST.get('product')
        cpu_model = req.POST.get('cpu_model')
        cpu_num = req.POST.get('cpu_num')
        memory = req.POST.get('memory')
        sn = req.POST.get('sn')
        osver = req.POST.get('osver')
        hostname = req.POST.get('hostname')
        try:
            host = Host.objects.get(hostname=hostname)
        except:
            host = Host()
        ipaddrs = req.POST.get('ipaddrs')
        identity = req.POST.get('identity')
        try:
            host = Host.objects.get(identity=identity)
        except:
            host = Host()
        host.hostname = hostname
        host.product = product
        host.cpu_num = int(cpu_num)
        host.cpu_model = cpu_model
        host.memory = int(memory)
        host.sn = sn
        host.osver = osver
        host.vendor = vendor
        host.save()
        for ip in ipaddrs.split(';'):
            o_ip = Ipaddr()
            o_ip.ipaddr = ip
            o_ip.host = host
            o_ip.save()
        return HttpResponse("post data successfully!")
    else:
        return HttpResponse("no any post data!")
Esempio n. 11
0
def collect(request):
    req = request
    if req.POST:
        vendor = req.POST.get('vendor')
        product = req.POST.get('product')
        cpu_model = req.POST.get('cpu_model')
        cpu_num = req.POST.get('cpu_num')
        memory = req.POST.get('memory')
        sn = req.POST.get('sn')
        osver = req.POST.get('osver')
        hostname = req.POST.get('hostname')
        try:
            host = Host.objects.get(hostname=hostname)
        except:
            host = Host()
        ipaddrs = req.POST.get('ipaddrs')
        identity = req.POST.get('identity')
        try:
            host = Host.objects.get(identity=identity)
        except:
            host = Host()
        host.hostname = hostname
        host.product = product
        host.cpu_num = int(cpu_num)
        host.cpu_model = cpu_model
        host.memory = int(memory)
        host.sn = sn
        host.osver = osver
        host.vendor = vendor
        host.save()
        for ip in ipaddrs.split(';'):
            o_ip = Ipaddr()
            o_ip.ipaddr = ip
            o_ip.host = host
            o_ip.save()
        return HttpResponse("post data successfully!")
    else:
        return HttpResponse("no any post data!")
Esempio n. 12
0
def collectjson(request):
    req = request
    if req.method == "POST":
        jsonobj = json.loads(req.body)
        try:
            host = Host.objects.get(identity=jsonobj['identity'])
        except:
            host = Host()
        try:
            host.identity = jsonobj['identity']
            host.hostname = jsonobj['hostname']
            host.product = jsonobj['product']
            host.cpu_num = jsonobj['cpu_num']
            host.cpu_model = jsonobj['cpu_model']
            host.memory = jsonobj['memory']
            host.sn = jsonobj['sn']
            host.osver = jsonobj['osver']
            host.vendor = jsonobj['vendor']
            host.ipaddr = jsonobj['ip']
            host.save()
            return HttpResponse(json.dumps({'status': 0, 'message': "ok"}))
        except Exception, e:
            return HttpResponse(json.dumps({'status': -1, 'message': str(e)}))
Esempio n. 13
0
def gethosts(request):
    if request.method == 'POST':
        data = json.loads(request)
        host = Host()
        host.vender = data['verder']
        host.product = data['product']
        host.cpu_model = data['cpu_model']
        host.cpu_num = data['cpu_num']
        host.memory = data['memory']
        host.sn = data['sn']
        host.osver = data['osver']
        host.hostname = data['hostname']

        host.save()

        ipaddrs = data['ipaddrs']
        for ip in ipaddrs.split(':'):
            o_ip = IpAddr()
            o_ip.ipaddr = ip
            o_ip.host = host
            o_ip.save()
    else:
        return HttpResponse('No post data')
Esempio n. 14
0
def collectjson(request):
    req = request
    if req.method == "POST":
        jsonobj = json.loads(req.body)
        try:
            host = Host.objects.get(identity=jsonobj['identity'])
        except:
            host = Host()
        try:
            host.identity = jsonobj['identity']
            host.hostname = jsonobj['hostname']
            host.product = jsonobj['product']
            host.cpu_num = jsonobj['cpu_num']
            host.cpu_model = jsonobj['cpu_model']
            host.memory = jsonobj['memory']
            host.sn = jsonobj['sn']
            host.osver = jsonobj['osver']
            host.vendor = jsonobj['vendor']
            host.ipaddr = jsonobj['ip']
            host.save()
            return HttpResponse(json.dumps({'status':0,'message':"ok"}))
        except Exception, e:
            return HttpResponse(json.dumps({'status':-1,'message':str(e)}))