grr/server/grr_response_server/hunt.py
def StopHunt(hunt_id, reason=None):
  """Stops a hunt with a given id."""

  def UpdateFn(h):
    if h.hunt_state not in [h.HuntState.STARTED, h.HuntState.PAUSED]:
      raise OnlyStartedOrPausedHuntCanBeStoppedError(h)

    h.hunt_state = h.HuntState.STOPPED
    if reason is not None:
      h.hunt_state_comment = reason
    return h

  # If the hunt was not started or paused, the exception from UpdateFn is
  # guaranteed to be propagated by UpdateHuntObject implementation.
  hunt_obj = data_store.REL_DB.UpdateHuntObject(hunt_id, UpdateFn)
  data_store.REL_DB.RemoveForemanRule(hunt_id=hunt_obj.hunt_id)

  flows = data_store.REL_DB.ReadHuntFlows(hunt_obj.hunt_id, 0, sys.maxsize)
  data_store.REL_DB.UpdateFlows(
      [(f.client_id, f.flow_id) for f in flows],
      pending_termination=rdf_flow_objects.PendingFlowTermination(
          reason="Parent hunt stopped."))

  if (reason is not None and
      hunt_obj.creator not in aff4_users.GRRUser.SYSTEM_USERS):
    notification.Notify(
        hunt_obj.creator, rdf_objects.UserNotification.Type.TYPE_HUNT_STOPPED,
        reason,
        rdf_objects.ObjectReference(
            reference_type=rdf_objects.ObjectReference.Type.HUNT,
            hunt=rdf_objects.HuntReference(hunt_id=hunt_obj.hunt_id)))

  return hunt_obj
Stops a hunt with a given id.
Stops a hunt with a given id.
Stops a hunt with a given id .
def StopHunt(hunt_id, reason=None):
  def UpdateFn(h):
    if h.hunt_state not in [h.HuntState.STARTED, h.HuntState.PAUSED]:
      raise OnlyStartedOrPausedHuntCanBeStoppedError(h)
    h.hunt_state = h.HuntState.STOPPED
    if reason is not None:
      h.hunt_state_comment = reason
    return h
  hunt_obj = data_store.REL_DB.UpdateHuntObject(hunt_id, UpdateFn)
  data_store.REL_DB.RemoveForemanRule(hunt_id=hunt_obj.hunt_id)
  flows = data_store.REL_DB.ReadHuntFlows(hunt_obj.hunt_id, 0, sys.maxsize)
  data_store.REL_DB.UpdateFlows(
      [(f.client_id, f.flow_id) for f in flows],
      pending_termination=rdf_flow_objects.PendingFlowTermination(
          reason="Parent hunt stopped."))
  if (reason is not None and
      hunt_obj.creator not in aff4_users.GRRUser.SYSTEM_USERS):
    notification.Notify(
        hunt_obj.creator, rdf_objects.UserNotification.Type.TYPE_HUNT_STOPPED,
        reason,
        rdf_objects.ObjectReference(
            reference_type=rdf_objects.ObjectReference.Type.HUNT,
            hunt=rdf_objects.HuntReference(hunt_id=hunt_obj.hunt_id)))
  return hunt_obj
def StopHunt ( hunt_id , reason = None ) : def UpdateFn ( h ) : if h . hunt_state not in [ h . HuntState . STARTED , h . HuntState . PAUSED ] : raise OnlyStartedOrPausedHuntCanBeStoppedError ( h ) h . hunt_state = h . HuntState . STOPPED if reason is not None : h . hunt_state_comment = reason return h hunt_obj = data_store . REL_DB . UpdateHuntObject ( hunt_id , UpdateFn ) data_store . REL_DB . RemoveForemanRule ( hunt_id = hunt_obj . hunt_id ) flows = data_store . REL_DB . ReadHuntFlows ( hunt_obj . hunt_id , 0 , sys . maxsize ) data_store . REL_DB . UpdateFlows ( [ ( f . client_id , f . flow_id ) for f in flows ] , pending_termination = rdf_flow_objects . PendingFlowTermination ( reason = "Parent hunt stopped." ) ) if ( reason is not None and hunt_obj . creator not in aff4_users . GRRUser . SYSTEM_USERS ) : notification . Notify ( hunt_obj . creator , rdf_objects . UserNotification . Type . TYPE_HUNT_STOPPED , reason , rdf_objects . ObjectReference ( reference_type = rdf_objects . ObjectReference . Type . HUNT , hunt = rdf_objects . HuntReference ( hunt_id = hunt_obj . hunt_id ) ) ) return hunt_obj
Stops a hunt with a given id.
Stops a hunt with a given id .
"""Stops a hunt with a given id.""" # If the hunt was not started or paused, the exception from UpdateFn is # guaranteed to be propagated by UpdateHuntObject implementation.
hunt_id
reason