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")
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')
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')
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')
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!")
def collect(request): req = request if req.POST: vendor = req.POST.get('vendor') product = req.POST.get('product') sn = req.POST.get('sn') hostname = req.POST.get('hostname') osbit = req.POST.get('osbit') osver = req.POST.get('osver') cpu_model = req.POST.get('cpu_model') cpucores = req.POST.get('cpucores') cpu_num = req.POST.get('cpu_num') memory = req.POST.get('memory') ipaddr = req.POST.get('ip') #ipaddrs = req.POST.get('ipaddr') identity = req.POST.get('identity') try: #host = Host.objects.get(hostname=hostname) host = Host.objects.get(identity=identity) except: host = Host() host.identity = identity host.vendor = vendor host.product = product host.sn = sn host.hostname = hostname host.osbit = osbit host.osver = osver host.cpumodel = cpu_model host.cpucores = cpucores host.cpunum = cpu_num host.memory = memory host.ipaddr = ipaddr host.save() return HttpResponse("ok") else: return HttpResponse("no post data")
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)}))
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')
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)}))