Пример #1
0
def ProcessHuntFlowError(flow_obj,
                         error_message=None,
                         backtrace=None,
                         status_msg=None):
    """Processes error and status message for a given hunt-induced flow."""

    if not hunt.IsLegacyHunt(flow_obj.parent_hunt_id):
        hunt.StopHuntIfCPUOrNetworkLimitsExceeded(flow_obj.parent_hunt_id)
        return

    hunt_urn = rdfvalue.RDFURN("hunts").Add(flow_obj.parent_hunt_id)
    client_urn = rdf_client.ClientURN(flow_obj.client_id)

    error = rdf_hunts.HuntError(client_id=flow_obj.client_id,
                                backtrace=backtrace)
    if error_message is not None:
        error.log_message = error_message
    with data_store.DB.GetMutationPool() as pool:
        grr_collections.HuntErrorCollection.StaticAdd(
            hunt_urn.Add("ErrorClients"), error, mutation_pool=pool)
        grr_collections.ClientUrnCollection.StaticAdd(
            hunt_urn.Add("CompletedClients"), client_urn, mutation_pool=pool)

    if status_msg is not None:
        with aff4.FACTORY.Open(hunt_urn, mode="rw") as fd:
            # Legacy AFF4 code expects token to be set.
            fd.token = access_control.ACLToken(username=fd.creator)
            fd.GetRunner().SaveResourceUsage(flow_obj.client_id, status_msg)
Пример #2
0
def ProcessHuntFlowError(flow_obj,
                         error_message=None,
                         backtrace=None,
                         status_msg=None):
    """Processes error and status message for a given hunt-induced flow."""

    if not hunt.IsLegacyHunt(flow_obj.parent_hunt_id):

        def UpdateFn(hunt_obj):
            hunt_obj.num_failed_clients += 1
            return hunt_obj

        hunt_obj = data_store.REL_DB.UpdateHuntObject(flow_obj.parent_hunt_id,
                                                      UpdateFn)
        hunt_obj = hunt.StopHuntIfAverageLimitsExceeded(hunt_obj)
        return

    hunt_urn = rdfvalue.RDFURN("hunts").Add(flow_obj.parent_hunt_id)
    client_urn = rdf_client.ClientURN(flow_obj.client_id)

    error = rdf_hunts.HuntError(client_id=flow_obj.client_id,
                                backtrace=backtrace)
    if error_message is not None:
        error.log_message = error_message
    with data_store.DB.GetMutationPool() as pool:
        grr_collections.HuntErrorCollection.StaticAdd(
            hunt_urn.Add("ErrorClients"), error, mutation_pool=pool)
        grr_collections.ClientUrnCollection.StaticAdd(
            hunt_urn.Add("CompletedClients"), client_urn, mutation_pool=pool)

    if status_msg is not None:
        with aff4.FACTORY.OpenWithLock(hunt_urn,
                                       lease_time=_HUNT_LEASE_TIME,
                                       blocking=True) as fd:
            fd.GetRunner().SaveResourceUsage(flow_obj.client_id, status_msg)
Пример #3
0
def ProcessHuntFlowError(flow_obj,
                         error_message=None,
                         backtrace=None,
                         status_msg=None):
    """Process error and status message for a given hunt-induced flow."""

    hunt_urn = rdfvalue.RDFURN("hunts").Add(flow_obj.parent_hunt_id)
    client_urn = rdf_client.ClientURN(flow_obj.client_id)

    error = rdf_hunts.HuntError(client_id=flow_obj.client_id,
                                backtrace=backtrace)
    if error_message is not None:
        error.log_message = error_message
    with data_store.DB.GetMutationPool() as pool:
        grr_collections.HuntErrorCollection.StaticAdd(
            hunt_urn.Add("ErrorClients"), error, mutation_pool=pool)
        grr_collections.ClientUrnCollection.StaticAdd(
            hunt_urn.Add("CompletedClients"), client_urn, mutation_pool=pool)

    if status_msg is not None:
        with aff4.FACTORY.OpenWithLock(hunt_urn,
                                       lease_time=_HUNT_LEASE_TIME,
                                       blocking=True) as fd:
            fd.GetRunner().SaveResourceUsage(flow_obj.client_id, status_msg)