def addhost(self, request): try: hostgroup_id = int(request.POST['hostgroup_id']) hostnames = request.POST['hostnames'] #先统计该机器组现有的机器列表 f = Falcon() result = f.get_hostgroup_info_by_id(hostgroup_id) hosts = result['hosts'] hostname_list = [i['hostname'] for i in hosts] hostname_list += hostnames.strip().split() hostname_list = list(set(hostname_list)) result = f.addHost2HhostGroup(hostgroup_id, hostname_list) except: print traceback.format_exc() return FalconResponse(result)
def get_hosts(self, request): try: limit = int(request.GET['limit']) page = int(request.GET['page']) name = request.GET['name'] hostgroup_id = request.GET['hostgroup_id'] f = Falcon() result = f.get_hostgroup_info_by_id(hostgroup_id) data = [] for i in result['hosts']: if i['hostname'].find(name) >= 0: data.append({'id': i['id'], 'hostname': i['hostname']}) total = len(data) data = data[(page - 1) * limit:page * limit] except: print traceback.format_exc() return HttpResponse(json.dumps({'total': total, 'rows': data}))
def host_add(self, request): hostgroup_id = request.GET['hostgroup_id'] f = Falcon() result = f.get_hostgroup_info_by_id(hostgroup_id) hostgroup_info = result['hostgroup'] return render(request, 'alarm/host_add.html', locals())