def get_cpu(): info = nsfocus.Work(0) try: cpu = int(info.sys__status()['cpu']) if cpu < 30: nsfocus_task = Nsfocus_task.objects.filter(nsfocus_status=8)[0] print nsfocus_task.nsfocus_tgthost assets_list = json.loads(nsfocus_task.nsfocus_tgthost) print assets_list print type(assets_list) iplist = get_tgthost(assets_list) ret = nsfocus.Work(dev_id=0) ret.create_xml(targets=iplist, taskname=nsfocus_task.nsfocus_name, live=nsfocus_task.nsfocus_active, port_strategy_userports=nsfocus_task.nsfocus_port, port_speed=str(nsfocus_task.nsfocus_port_level), scan_level=str(nsfocus_task.nsfocus_level)) result = ret.addtask() result = json.loads(result) print result['ret_msg'] if result['ret_msg'] == 'success': task_id = result['data']['task_id'] Nsfocus_task.objects.filter(id=nsfocus_task.id).update( nsfocus_status=2, nsfocus_task_id=int(task_id)) else: print '参数有误' except Exception as e: print '服务器不能正常连接' print e print cpu
def get_cpu(): nsfocus_dev_obj=Nsfoucs_Scan_dev.objects.all() for item in nsfocus_dev_obj: work_init= nsfocus.Work(item.address,item.user,item.passwd) try: cpu =int(work_init.sys__status()['cpu']) if cpu<30: nsfocus_task= Nsfocus_task.objects.filter(nsfocus_status=8,nsfocus_dev=item.id)[0] print nsfocus_task.nsfocus_tgthost assets_list=json.loads(nsfocus_task.nsfocus_tgthost) print assets_list print type(assets_list) iplist=get_tgthost(assets_list) work_init.create_xml(targets=iplist, taskname=nsfocus_task.nsfocus_name, live=nsfocus_task.nsfocus_active, port_strategy_userports=nsfocus_task.nsfocus_port, port_speed=str(nsfocus_task.nsfocus_port_level), scan_level=str(nsfocus_task.nsfocus_level) ) result=work_init.addtask() result=json.loads(result) print result['ret_msg'] if result['ret_msg'] == 'success': task_id = result['data']['task_id'] Nsfocus_task.objects.filter(id=nsfocus_task.id).update(nsfocus_status=2, nsfocus_task_id=int(task_id)) else: print '参数有误' except Exception as e: print '服务器不能正常连接' print e print cpu
def start_nsfocus_task(request, id, format=None): if request.method == 'GET': task_arg = Nsfocus_task.objects.get(id=id) print task_arg.nsfocus_tgthost dev_id = task_arg.nsfocus_dev nsfocus_obj = Nsfoucs_Scan_dev.objects.get(id=dev_id) url = nsfocus_obj.address username = nsfocus_obj.user password = nsfocus_obj.passwd ret = nsfocus.Work(url, username, password) ret.create_xml(targets=task_arg.nsfocus_tgthost, taskname=task_arg.nsfocus_name, live=task_arg.nsfocus_active, port_strategy_userports=task_arg.nsfocus_port, port_speed=str(task_arg.nsfocus_port_level), scan_level=str(task_arg.nsfocus_level)) result = ret.addtask() result = json.loads(result) print result['ret_msg'] if result['ret_msg'] == 'success': task_id = result['data']['task_id'] Nsfocus_task.objects.filter(id=id).update( nsfocus_status=2, nsfocus_task_id=int(task_id)) return HttpResponse('200', status=200) else: return HttpResponse('200', status=200) else: return HttpResponse('200', status=200)
def task_status(assets): id = assets.id print '*************************************************************' dev_id = assets.nsfocus_dev print dev_id print type(dev_id) nsfocus_id = str(assets.nsfocus_task_id) info = nsfocus.Work(0) ret = info.task__status(nsfocus_id) return ret
def get_nsfocus_report(request, id, format=None): if request.method == 'GET': arg=Nsfocus_task.objects.get(id=id) admin_user_id=request.user.id ret = nsfocus.Work(dev_id=arg.nsfocus_dev) print arg.id print arg.nsfocus_dev nsfocus_task_id= str(arg.nsfocus_task_id) result=ret.task__result(nsfocus_task_id) SQL_db.vul_db(id=id,nsfocus_task_id=nsfocus_task_id,result=result,admin_user_id=admin_user_id) return HttpResponse('200', status=200)
def get_nsfcous_status(assets): try: id = assets.id dev_id = assets.nsfocus_dev print dev_id nsfocus_obj = Nsfoucs_Scan_dev.objects.get(id=dev_id) url = nsfocus_obj.address username = nsfocus_obj.user password = nsfocus_obj.passwd print url, username, password nsfocus_id = str(assets.nsfocus_task_id) info = nsfocus.Work(url, username, password) ret = info.task__status(nsfocus_id) return ret except Exception as e: print e