Exemplo n.º 1
0
    def Run(self):
        with test_lib.FakeTime(42):
            if data_store.RelationalDBEnabled():
                hunt_id = self.CreateHunt(description="the hunt")
                hunt.StartHunt(hunt_id)
            else:
                hunt_urn = self.StartHunt(description="the hunt")
                hunt_id = hunt_urn.Basename()

            if data_store.RelationalDBEnabled():
                client = self.SetupTestClientObject(0)
                client_ids = [rdf_client.ClientURN(client.client_id)]
            else:
                client_ids = self.SetupClients(1)
            self.RunHunt(failrate=2, client_ids=client_ids)

        # Create replace dictionary.
        replace = {hunt_id: "H:123456"}
        if data_store.RelationalDBEnabled():
            stats = data_store.REL_DB.ReadHuntClientResourcesStats(hunt_id)
            for performance in stats.worst_performers:
                session_id = unicode(performance.session_id)
                replace[session_id] = "<replaced session value>"
        else:
            with aff4.FACTORY.Open(hunt_urn, mode="r",
                                   token=self.token) as hunt_obj:
                stats = hunt_obj.GetRunner().context.usage_stats
                for performance in stats.worst_performers:
                    session_id = unicode(performance.session_id)
                    replace[session_id] = "<replaced session value>"

        self.Check("GetHuntStats",
                   args=hunt_plugin.ApiGetHuntStatsArgs(hunt_id=hunt_id),
                   replace=replace)
Exemplo n.º 2
0
    def Run(self):
        with test_lib.FakeTime(42):
            hunt_id = self.CreateHunt(description="the hunt",
                                      creator=self.token.username)
            hunt.StartHunt(hunt_id)

            client_id = self.SetupClient(0)
            self.RunHunt(failrate=2, client_ids=[client_id])

        # Create replace dictionary.
        replace = {hunt_id: "H:123456"}
        stats = data_store.REL_DB.ReadHuntClientResourcesStats(hunt_id)
        for performance in stats.worst_performers:
            session_id = str(performance.session_id)
            replace[session_id] = "<replaced session value>"

        self.Check("GetHuntStats",
                   args=hunt_plugin.ApiGetHuntStatsArgs(hunt_id=hunt_id),
                   replace=replace)
Exemplo n.º 3
0
    def Run(self):
        with test_lib.FakeTime(42):
            hunt_id = self.CreateHunt(description="the hunt")
            hunt.StartHunt(hunt_id)

            if data_store.RelationalDBEnabled():
                client = self.SetupTestClientObject(0)
                client_ids = [rdf_client.ClientURN(client.client_id)]
            else:
                client_ids = self.SetupClients(1)
            self.RunHunt(failrate=2, client_ids=client_ids)

        # Create replace dictionary.
        replace = {hunt_id: "H:123456"}
        stats = data_store.REL_DB.ReadHuntClientResourcesStats(hunt_id)
        for performance in stats.worst_performers:
            session_id = unicode(performance.session_id)
            replace[session_id] = "<replaced session value>"

        self.Check("GetHuntStats",
                   args=hunt_plugin.ApiGetHuntStatsArgs(hunt_id=hunt_id),
                   replace=replace)
Exemplo n.º 4
0
    def Run(self):
        with test_lib.FakeTime(42):
            hunt_urn = self.StartHunt(description="the hunt")

            if data_store.RelationalDBReadEnabled():
                client = self.SetupTestClientObject(0)
                client_ids = [rdf_client.ClientURN(client.client_id)]
            else:
                client_ids = self.SetupClients(1)
            self.AssignTasksToClients(client_ids=client_ids)
            self.RunHunt(client_ids=client_ids)

        # Create replace dictionary.
        replace = {hunt_urn.Basename(): "H:123456"}
        with aff4.FACTORY.Open(hunt_urn, mode="r", token=self.token) as hunt:
            stats = hunt.GetRunner().context.usage_stats
            for performance in stats.worst_performers:
                session_id = performance.session_id.Basename()
                replace[session_id] = "<replaced session value>"

        self.Check(
            "GetHuntStats",
            args=hunt_plugin.ApiGetHuntStatsArgs(hunt_id=hunt_urn.Basename()),
            replace=replace)