#NEWLINE# @ classmethod #NEWLINE# def StartHunt( cls , args = None , runner_args = None , **kwargs ) : #NEWLINE# #INDENT# 'This class method creates new hunts.' #NEWLINE# if ( runner_args is None ) : #NEWLINE# #INDENT# runner_args = HuntRunnerArgs ( ) #NEWLINE# #UNINDENT# cls . FilterArgsFromSemanticProtobuf ( runner_args , kwargs ) #NEWLINE# if ( ( runner . hunt_name not in cls . classes ) or ( not aff4 . issubclass ( cls . classes [ runner_args . hunt_name ] , GRRHunt ) ) ) : #NEWLINE# #INDENT# raise RuntimeError ( ( 'Unable to locate hunt %s' % runner_args . hunt_name ) ) #NEWLINE# #UNINDENT# hunt_obj = aff4 . FACTORY . Create ( None , runner_args . hunt_name , mode = 'w' , token = runner_args . token ) #NEWLINE# if ( hunt_obj . args_type and ( args is None ) ) : #NEWLINE# #INDENT# args = hunt_obj . args_type ( ) #NEWLINE# cls . FilterArgsFromSemanticProtobuf ( args , kwargs ) #NEWLINE# #UNINDENT# if ( hunt_obj . args_type and ( not isinstance ( args , hunt_obj . args_type ) ) ) : #NEWLINE# #INDENT# raise RuntimeError ( ( 'Hunt args must be instance of %s' % hunt_obj . args_type ) ) #NEWLINE# #UNINDENT# if kwargs : #NEWLINE# #INDENT# raise type_info . UnknownArg ( ( 'Unknown parameters to StartHunt: %s' % kwargs ) ) #NEWLINE# #UNINDENT# hunt_obj . state . Register ( 'args' , args ) #NEWLINE# hunt_obj . Set ( hunt_obj . Schema . STATE ( 'PAUSED' ) ) #NEWLINE# runner = hunt_obj . CreateRunner ( runner_args = runner_args ) #NEWLINE# runner . RunStateMethod ( 'Start' ) #NEWLINE# hunt_obj . Flush ( ) #NEWLINE# try : #NEWLINE# #INDENT# flow_name = args . flow_runner_args . flow_name #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# flow_name = '' #NEWLINE# #UNINDENT# event = flow . AuditEvent ( user = runner_args . token . username , action = 'HUNT_CREATED' , urn = hunt_obj . urn , flow_name = flow_name , description = runner_args . description ) #NEWLINE# flow . Events . PublishEvent ( 'Audit' , event , token = runner_args . token ) #NEWLINE# return hunt_obj