(self, params)
return
Search for results using provided parameter(s)
        - Only 1 page of results are displayed.
Search for results using provided parameter(s)
        - Only 1 page of results are displayed.
Search for results using provided parameter ( s ) - Only 1 page of results are displayed .
def sample_search(self, params):
        """
        Search for results using provided parameter(s)
        - Only 1 page of results are displayed.
        """
        # Set API query parameters and conduct query
        recent_id = 0
        response = self.api_request('/api/v2/samples', params, 'get')
        if response:
            result_count = response.get('data', {}).get('current_item_count', 0)
            if result_count > 0:
                # Handle search by ID
                if 'id' in params.keys():
                    item = response.get('data', {}).get('items')
                    if len(item) == 1:
                        # Detect analysis state
                        state = item[0].get('state', '')
                        if state in ['pending', 'running', 'proc', 'wait', 'prep']:
                            return
                        elif state in ['job_done', 'succ']:
                            result = {
                                    'id':               item[0].get('id'),
                                    'submitted_at':     item[0].get('submitted_at'),
                                    'tags':             ''.join(item[0].get('tags', [])),
                                    'login':            item[0].get('login'),
                                    'state':            item[0].get('state'),
                                    'status':           item[0].get('status'),
                                    }
                            self._add_result('threatgrid_job', item[0].get('filename', ''), result)
                            self._notify()
                            return item[0].get('id')
                        elif state == 'fail':
                            result = {
                                    'id':               item[0].get('id'),
                                    'submitted_at':     item[0].get('submitted_at'),
                                    'tags':             ''.join(item[0].get('tags', [])),
                                    'login':            item[0].get('login'),
                                    'state':            item[0].get('state'),
                                    'status':           item[0].get('status'),
                                    }
                            self._add_result('threatgrid_job', 'Failed', result)
                            self._notify()
                            self._info('ThreatGRID analysis failed ({}).'.format(item[0].get('status', '')))
                            return -1
                        else:
                            self._info('ThreatGRID returned unknown state type ({}).'.format(item[0].get('state', '')))
                            return
                    else:
                        self._error('ThreatGRID returned unexpeced number of results for the sample ID.')
                else:
                    # Handle other search types (MD5 etc.)
                    for item in response.get('data', {}).get('items'):
                        result = {
                                'id':               item.get('id'),
                                'submitted_at':     item.get('submitted_at'),
                                'tags':             ''.join(item.get('tags', [])),
                                'login':            item.get('login'),
                                'state':            item.get('state'),
                                'status':           item.get('status'),
                                }
                        self._add_result('threatgrid_job', item.get('filename', ''), result)
                        recent_id = item.get('id')
                    self._notify()
                    self._info('{} results returned from ThreatGRID search.'.format(result_count))
                    # Return one of the analysis IDs (used to show further results)
                    return recent_id
        else:
            self._error('An error occured while looking for sample.')
        return
def sample_search ( self , params ) : # Set API query parameters and conduct query recent_id = 0 response = self . api_request ( '/api/v2/samples' , params , 'get' ) if response : result_count = response . get ( 'data' , { } ) . get ( 'current_item_count' , 0 ) if result_count > 0 : # Handle search by ID if 'id' in params . keys ( ) : item = response . get ( 'data' , { } ) . get ( 'items' ) if len ( item ) == 1 : # Detect analysis state state = item [ 0 ] . get ( 'state' , '' ) if state in [ 'pending' , 'running' , 'proc' , 'wait' , 'prep' ] : return elif state in [ 'job_done' , 'succ' ] : result = { 'id' : item [ 0 ] . get ( 'id' ) , 'submitted_at' : item [ 0 ] . get ( 'submitted_at' ) , 'tags' : '' . join ( item [ 0 ] . get ( 'tags' , [ ] ) ) , 'login' : item [ 0 ] . get ( 'login' ) , 'state' : item [ 0 ] . get ( 'state' ) , 'status' : item [ 0 ] . get ( 'status' ) , } self . _add_result ( 'threatgrid_job' , item [ 0 ] . get ( 'filename' , '' ) , result ) self . _notify ( ) return item [ 0 ] . get ( 'id' ) elif state == 'fail' : result = { 'id' : item [ 0 ] . get ( 'id' ) , 'submitted_at' : item [ 0 ] . get ( 'submitted_at' ) , 'tags' : '' . join ( item [ 0 ] . get ( 'tags' , [ ] ) ) , 'login' : item [ 0 ] . get ( 'login' ) , 'state' : item [ 0 ] . get ( 'state' ) , 'status' : item [ 0 ] . get ( 'status' ) , } self . _add_result ( 'threatgrid_job' , 'Failed' , result ) self . _notify ( ) self . _info ( 'ThreatGRID analysis failed ({}).' . format ( item [ 0 ] . get ( 'status' , '' ) ) ) return - 1 else : self . _info ( 'ThreatGRID returned unknown state type ({}).' . format ( item [ 0 ] . get ( 'state' , '' ) ) ) return else : self . _error ( 'ThreatGRID returned unexpeced number of results for the sample ID.' ) else : # Handle other search types (MD5 etc.) for item in response . get ( 'data' , { } ) . get ( 'items' ) : result = { 'id' : item . get ( 'id' ) , 'submitted_at' : item . get ( 'submitted_at' ) , 'tags' : '' . join ( item . get ( 'tags' , [ ] ) ) , 'login' : item . get ( 'login' ) , 'state' : item . get ( 'state' ) , 'status' : item . get ( 'status' ) , } self . _add_result ( 'threatgrid_job' , item . get ( 'filename' , '' ) , result ) recent_id = item . get ( 'id' ) self . _notify ( ) self . _info ( '{} results returned from ThreatGRID search.' . format ( result_count ) ) # Return one of the analysis IDs (used to show further results) return recent_id else : self . _error ( 'An error occured while looking for sample.' ) return