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): 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!")