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): 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!")
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!")
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!")
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!")
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)}))
def collect(request): asset_info = json.loads(request.body) print asset_info 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['privateIps'] # asset_type = "" # status = "" try: # 检查hostname是否已经存在 host = Host.objects.get(hostname=hostname) except Exception as msg: print(msg) host = Host() host.hostname = hostname # host.group = group host.cpu_num = int(cpu_num) #host.cpu_model = cpu_model host.memory = float(memory) host.sn = sn host.disk = disk host.os = osver #host.vendor = vendor host.ip = ip host.save() return HttpResponse("Post asset data to server successfully!") else: return HttpResponse("No any post data!")