grr/server/grr_response_server/hunt.py
def StartHunt(hunt_id):
  """Starts a hunt with a given id."""

  hunt_obj = data_store.REL_DB.ReadHuntObject(hunt_id)
  output_plugins_states = None
  if hunt_obj.output_plugins and not hunt_obj.output_plugins_states:
    output_plugins_states = flow.GetOutputPluginStates(
        hunt_obj.output_plugins,
        source="hunts/%s" % hunt_obj.hunt_id,
        token=access_control.ACLToken(username=hunt_obj.creator))
    for ops in output_plugins_states:
      ops.plugin_state["success_count"] = 0
      ops.plugin_state["error_count"] = 0

  def UpdateFn(h):
    """Updates given hunt in a transaction."""

    if h.hunt_state != h.HuntState.PAUSED:
      raise OnlyPausedHuntCanBeStartedError(h)

    if (output_plugins_states is not None and
        not hunt_obj.output_plugins_states):
      h.output_plugins_states = output_plugins_states
    h.hunt_state = h.HuntState.STARTED
    h.hunt_state_comment = None
    h.next_client_due = rdfvalue.RDFDatetime.Now()
    return h

  hunt_obj = data_store.REL_DB.UpdateHuntObject(hunt_id, UpdateFn)
  if hunt_obj.hunt_state != hunt_obj.HuntState.STARTED:
    return

  foreman_condition = foreman_rules.ForemanCondition(
      creation_time=rdfvalue.RDFDatetime.Now(),
      expiration_time=hunt_obj.expiry_time,
      description="Hunt %s %s" % (hunt_obj.hunt_id, hunt_obj.args.hunt_type),
      client_rule_set=hunt_obj.client_rule_set,
      hunt_id=hunt_obj.hunt_id)

  # Make sure the rule makes sense.
  foreman_condition.Validate()

  data_store.REL_DB.WriteForemanRule(foreman_condition)

  return hunt_obj
Starts a hunt with a given id.
Starts a hunt with a given id.
Starts a hunt with a given id .
def StartHunt(hunt_id):
  hunt_obj = data_store.REL_DB.ReadHuntObject(hunt_id)
  output_plugins_states = None
  if hunt_obj.output_plugins and not hunt_obj.output_plugins_states:
    output_plugins_states = flow.GetOutputPluginStates(
        hunt_obj.output_plugins,
        source="hunts/%s" % hunt_obj.hunt_id,
        token=access_control.ACLToken(username=hunt_obj.creator))
    for ops in output_plugins_states:
      ops.plugin_state["success_count"] = 0
      ops.plugin_state["error_count"] = 0
  def UpdateFn(h):
    if h.hunt_state != h.HuntState.PAUSED:
      raise OnlyPausedHuntCanBeStartedError(h)
    if (output_plugins_states is not None and
        not hunt_obj.output_plugins_states):
      h.output_plugins_states = output_plugins_states
    h.hunt_state = h.HuntState.STARTED
    h.hunt_state_comment = None
    h.next_client_due = rdfvalue.RDFDatetime.Now()
    return h
  hunt_obj = data_store.REL_DB.UpdateHuntObject(hunt_id, UpdateFn)
  if hunt_obj.hunt_state != hunt_obj.HuntState.STARTED:
    return
  foreman_condition = foreman_rules.ForemanCondition(
      creation_time=rdfvalue.RDFDatetime.Now(),
      expiration_time=hunt_obj.expiry_time,
      description="Hunt %s %s" % (hunt_obj.hunt_id, hunt_obj.args.hunt_type),
      client_rule_set=hunt_obj.client_rule_set,
      hunt_id=hunt_obj.hunt_id)
  foreman_condition.Validate()
  data_store.REL_DB.WriteForemanRule(foreman_condition)
  return hunt_obj
def StartHunt ( hunt_id ) : hunt_obj = data_store . REL_DB . ReadHuntObject ( hunt_id ) output_plugins_states = None if hunt_obj . output_plugins and not hunt_obj . output_plugins_states : output_plugins_states = flow . GetOutputPluginStates ( hunt_obj . output_plugins , source = "hunts/%s" % hunt_obj . hunt_id , token = access_control . ACLToken ( username = hunt_obj . creator ) ) for ops in output_plugins_states : ops . plugin_state [ "success_count" ] = 0 ops . plugin_state [ "error_count" ] = 0 def UpdateFn ( h ) : """Updates given hunt in a transaction.""" if h . hunt_state != h . HuntState . PAUSED : raise OnlyPausedHuntCanBeStartedError ( h ) if ( output_plugins_states is not None and not hunt_obj . output_plugins_states ) : h . output_plugins_states = output_plugins_states h . hunt_state = h . HuntState . STARTED h . hunt_state_comment = None h . next_client_due = rdfvalue . RDFDatetime . Now ( ) return h hunt_obj = data_store . REL_DB . UpdateHuntObject ( hunt_id , UpdateFn ) if hunt_obj . hunt_state != hunt_obj . HuntState . STARTED : return foreman_condition = foreman_rules . ForemanCondition ( creation_time = rdfvalue . RDFDatetime . Now ( ) , expiration_time = hunt_obj . expiry_time , description = "Hunt %s %s" % ( hunt_obj . hunt_id , hunt_obj . args . hunt_type ) , client_rule_set = hunt_obj . client_rule_set , hunt_id = hunt_obj . hunt_id ) foreman_condition . Validate ( ) data_store . REL_DB . WriteForemanRule ( foreman_condition ) return hunt_obj
Starts a hunt with a given id.
Starts a hunt with a given id .
"""Starts a hunt with a given id.""" """Updates given hunt in a transaction.""" # Make sure the rule makes sense.
hunt_id