def Handle(self, args, token=None): results_collection = implementation.GRRHunt.ResultCollectionForHID( args.hunt_id.ToURN(), token=token) items = api_call_handler_utils.FilterCollection( results_collection, args.offset, args.count, args.filter) wrapped_items = [ApiHuntResult().InitFromGrrMessage(item) for item in items] return ApiListHuntResultsResult( items=wrapped_items, total_count=len(results_collection))
def Handle(self, args, token=None): # TODO(user): handle cases when hunt doesn't exists. logs_collection = implementation.GRRHunt.LogCollectionForHID( args.hunt_id.ToURN()) result = api_call_handler_utils.FilterCollection( logs_collection, args.offset, args.count, args.filter) return ApiListHuntLogsResult(items=result, total_count=len(logs_collection))
def Handle(self, args, token=None): flow_urn = args.flow_id.ResolveClientFlowURN(args.client_id, token=token) output_collection = flow.GRRFlow.ResultCollectionForFID( flow_urn, token=token) items = api_call_handler_utils.FilterCollection( output_collection, args.offset, args.count, args.filter) wrapped_items = [ApiFlowResult().InitFromRdfValue(item) for item in items] return ApiListFlowResultsResult( items=wrapped_items, total_count=len(output_collection))
def Handle(self, args, token=None): aff4_crashes = aff4_grr.VFSGRRClient.CrashCollectionForCID( args.client_id.ToClientURN()) total_count = len(aff4_crashes) result = api_call_handler_utils.FilterCollection( aff4_crashes, args.offset, args.count, args.filter) return ApiListClientCrashesResult(items=result, total_count=total_count)
def Handle(self, args, token=None): results_collection = aff4.FACTORY.Open( args.hunt_id.ToURN().Add("Results"), mode="r", token=token) items = api_call_handler_utils.FilterCollection(results_collection, args.offset, args.count, args.filter) wrapped_items = [ApiHuntResult().InitFromGrrMessage(item) for item in items] return ApiListHuntResultsResult( items=wrapped_items, total_count=len(results_collection))
def Handle(self, args, token=None): flow_urn = args.flow_id.ResolveClientFlowURN(args.client_id, token=token) logs_collection = flow.GRRFlow.LogCollectionForFID(flow_urn) result = api_call_handler_utils.FilterCollection( logs_collection, args.offset, args.count, args.filter) return ApiListFlowLogsResult(items=result, total_count=len(logs_collection))
def Handle(self, args, token=None): # TODO(user): handle cases when hunt doesn't exists. errors_collection = implementation.GRRHunt.ErrorCollectionForHID( args.hunt_id.ToURN()) result = api_call_handler_utils.FilterCollection( errors_collection, args.offset, args.count, args.filter) return ApiListHuntErrorsResult( items=[ApiHuntError().InitFromHuntError(x) for x in result], total_count=len(errors_collection))
def Handle(self, args, token=None): # TODO(user): handle cases when hunt doesn't exists. # TODO(user): Use hunt's logs_collection_urn to open errors collection. errors_collection = aff4.FACTORY.Open( args.hunt_id.ToURN().Add("ErrorClients"), mode="r", token=token) result = api_call_handler_utils.FilterCollection( errors_collection, args.offset, args.count, args.filter) return ApiListHuntErrorsResult(items=result, total_count=len(errors_collection))
def Handle(self, args, token=None): logs_collection_urn = args.flow_id.ResolveClientFlowURN( args.client_id, token=token).Add("Logs") logs_collection = aff4.FACTORY.Create( logs_collection_urn, aff4_type=flow_runner.FlowLogCollection, mode="r", token=token) result = api_call_handler_utils.FilterCollection( logs_collection, args.offset, args.count, args.filter) return ApiListFlowLogsResult(items=result, total_count=len(logs_collection))
def Handle(self, args, token=None): try: aff4_crashes = aff4.FACTORY.Open( HUNTS_ROOT_PATH.Add(args.hunt_id).Add("crashes"), mode="r", aff4_type=collects.PackedVersionedCollection, token=token) total_count = len(aff4_crashes) result = api_call_handler_utils.FilterCollection( aff4_crashes, args.offset, args.count, args.filter) except aff4.InstantiationError: total_count = 0 result = [] return ApiListHuntCrashesResult(items=result, total_count=total_count)
def Handle(self, args, token=None): # TODO(user): handle cases when hunt doesn't exists. # TODO(user): Use hunt's logs_collection_urn to open logs collection. try: logs_collection = aff4.FACTORY.Open( HUNTS_ROOT_PATH.Add(args.hunt_id).Add("Logs"), aff4_type=flow_runner.FlowLogCollection, mode="r", token=token) except IOError: logs_collection = aff4.FACTORY.Create( HUNTS_ROOT_PATH.Add(args.hunt_id).Add("Logs"), aff4_type=collects.RDFValueCollection, mode="r", token=token) result = api_call_handler_utils.FilterCollection( logs_collection, args.offset, args.count, args.filter) return ApiListHuntLogsResult(items=result, total_count=len(logs_collection))
def Handle(self, args, token=None): flow_urn = args.flow_id.ResolveClientFlowURN(args.client_id, token=token) flow_obj = aff4.FACTORY.Open(flow_urn, aff4_type=flow.GRRFlow, mode="r", token=token) # TODO(user): Remove this as soon as possible. Once we do, old # flow results will not be shown properly in the UI anymore. try: output_urn = flow_obj.GetRunner().output_urn except AttributeError: # Old style flow. output_urn = flow_obj.GetRunner().context.output_urn try: # TODO(user): Remove support for RDFValueCollection. output_collection = aff4.FACTORY.Open( flow_obj.state.context.output_urn, aff4_type=aff4_collects.RDFValueCollection, mode="r", token=token) except (aff4.InstantiationError, AttributeError): try: output_collection = aff4.FACTORY.Open( output_urn, aff4_type=sequential_collection.GeneralIndexedCollection, mode="r", token=token) except aff4.InstantiationError: return ApiListFlowResultsResult(total_count=0) items = api_call_handler_utils.FilterCollection( output_collection, args.offset, args.count, args.filter) wrapped_items = [ ApiFlowResult().InitFromRdfValue(item) for item in items ] return ApiListFlowResultsResult(items=wrapped_items, total_count=len(output_collection))
def testFiltersByFilterString(self): data = api_call_handler_utils.FilterCollection(self.fd, 0, 0, "tmp-8") self.assertEqual(len(data), 1) self.assertEqual(data[0].path, "/var/os/tmp-8")
def testRaisesOnNegativeCount(self): with self.assertRaises(ValueError): api_call_handler_utils.FilterCollection(self.fd, 0, -10, None)
def testIngoresTooBigCount(self): data = api_call_handler_utils.FilterCollection(self.fd, 0, 50, None) self.assertEqual(len(data), 10) self.assertEqual(data[0].path, "/var/os/tmp-0") self.assertEqual(data[-1].path, "/var/os/tmp-9")
def testFiltersByOffsetAndCount(self): data = api_call_handler_utils.FilterCollection(self.fd, 2, 5, None) self.assertEqual(len(data), 5) self.assertEqual(data[0].path, "/var/os/tmp-2") self.assertEqual(data[-1].path, "/var/os/tmp-6")
def Handle(self, args, token=None): crashes = implementation.GRRHunt.CrashCollectionForHID(args.hunt_id.ToURN()) total_count = len(crashes) result = api_call_handler_utils.FilterCollection(crashes, args.offset, args.count, args.filter) return ApiListHuntCrashesResult(items=result, total_count=total_count)