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)
def Handle(self, args, token=None): if data_store.RelationalDBFlowsEnabled(): count = args.count or db.MAX_COUNT logs = data_store.REL_DB.ReadFlowLogEntries( str(args.client_id), str(args.flow_id), args.offset, count, args.filter) total_count = data_store.REL_DB.CountFlowLogEntries( str(args.client_id), str(args.flow_id)) return ApiListFlowLogsResult( items=[ ApiFlowLog().InitFromFlowLogEntry(log, str(args.flow_id)) for log in logs ], total_count=total_count) else: 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=[ApiFlowLog().InitFromFlowLog(x) for x in result], total_count=len(logs_collection))
def Handle(self, args, token=None): results_collection = implementation.GRRHunt.ResultCollectionForHID( args.hunt_id.ToURN()) 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) output_collection = flow.GRRFlow.ResultCollectionForFID(flow_urn) 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): 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=[ApiFlowLog().InitFromFlowLog(x) for x in 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): if data_store.RelationalDBEnabled(): crashes = data_store.REL_DB.ReadClientCrashInfoHistory( str(args.client_id)) total_count = len(crashes) result = api_call_handler_utils.FilterList( crashes, args.offset, count=args.count, filter_value=args.filter) else: crashes = aff4_grr.VFSGRRClient.CrashCollectionForCID( args.client_id.ToClientURN()) total_count = len(crashes) result = api_call_handler_utils.FilterCollection( crashes, args.offset, count=args.count, filter_value=args.filter) return ApiListClientCrashesResult(items=result, total_count=total_count)
def Handle(self, args, token=None): if data_store.RelationalDBFlowsEnabled(): items = data_store.REL_DB.ReadFlowResults( unicode(args.client_id), unicode(args.flow_id), args.offset, args.count) total_count = data_store.REL_DB.CountFlowResults( unicode(args.client_id), unicode(args.flow_id)) else: flow_urn = args.flow_id.ResolveClientFlowURN(args.client_id, token=token) output_collection = flow.GRRFlow.ResultCollectionForFID(flow_urn) total_count = len(output_collection) 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=total_count)
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")