(self, end_stream, retry_count=0)
return None
Upload data to Timesketch.

        Args:
            end_stream: boolean indicating whether this is the last chunk of
                the stream.
            retry_count: optional int that is only set if this is a retry
                of the upload.

        Raises:
            RuntimeError: If the data buffer is not successfully uploaded.
Upload data to Timesketch.
Upload data to Timesketch .
def _upload_data_buffer(self, end_stream, retry_count=0):
        """Upload data to Timesketch.

        Args:
            end_stream: boolean indicating whether this is the last chunk of
                the stream.
            retry_count: optional int that is only set if this is a retry
                of the upload.

        Raises:
            RuntimeError: If the data buffer is not successfully uploaded.
        """
        if not self._data_lines:
            return None

        start_time = time.time()
        data = {
            'name': self._timeline_name,
            'sketch_id': self._sketch.id,
            'enable_stream': not end_stream,
            'data_label': self._data_label,
            'provider': self._provider,
            'events': '\n'.join([json.dumps(x) for x in self._data_lines]),
        }
        if self._index:
            data['index_name'] = self._index

        if self._upload_context:
            data['context'] = self._upload_context

        logger.debug(
            'Data buffer ready for upload, took {0:.2f} seconds to '
            'prepare.'.format(time.time() - start_time))

        response = self._sketch.api.session.post(self._resource_url, data=data)

        # TODO: Investigate why the sleep is needed, fix the underlying issue
        # and get rid of it here.
        # To prevent unexpected errors with connection refusal adding a quick
        # sleep.
        time.sleep(2)

        if response.status_code not in definitions.HTTP_STATUS_CODE_20X:
            if retry_count >= self.DEFAULT_RETRY_LIMIT:
                raise RuntimeError(
                    'Error uploading data: [{0:d}] {1!s} {2!s}, '
                    'index {3:s}'.format(
                        response.status_code, response.reason, response.text,
                        self._index))

            logger.warning(
                'Unable to upload data buffer: {0:d}, retrying (attempt '
                '{1:d}/{2:d})'.format(
                    self._chunk, retry_count + 1, self.DEFAULT_RETRY_LIMIT))

            return self._upload_data_buffer(
                end_stream=end_stream, retry_count=retry_count + 1)

        logger.debug(
            'Data buffer nr. {0:d} uploaded, total time: {1:.2f}s'.format(
                self._chunk, time.time() - start_time))
        self._chunk += 1
        response_dict = response.json()
        object_dict = response_dict.get('objects', [{}])[0]
        meta_dict = response_dict.get('meta', {})
        self._celery_task_id = meta_dict.get('task_id', '')

        self._timeline_id = object_dict.get('id')
        self._index = object_dict.get('searchindex', {}).get('index_name')
        self._last_response = response_dict

        return None
def _upload_data_buffer ( self , end_stream , retry_count = 0 ) : if not self . _data_lines : return None start_time = time . time ( ) data = { 'name' : self . _timeline_name , 'sketch_id' : self . _sketch . id , 'enable_stream' : not end_stream , 'data_label' : self . _data_label , 'provider' : self . _provider , 'events' : '\n' . join ( [ json . dumps ( x ) for x in self . _data_lines ] ) , } if self . _index : data [ 'index_name' ] = self . _index if self . _upload_context : data [ 'context' ] = self . _upload_context logger . debug ( 'Data buffer ready for upload, took {0:.2f} seconds to ' 'prepare.' . format ( time . time ( ) - start_time ) ) response = self . _sketch . api . session . post ( self . _resource_url , data = data ) # TODO: Investigate why the sleep is needed, fix the underlying issue # and get rid of it here. # To prevent unexpected errors with connection refusal adding a quick # sleep. time . sleep ( 2 ) if response . status_code not in definitions . HTTP_STATUS_CODE_20X : if retry_count >= self . DEFAULT_RETRY_LIMIT : raise RuntimeError ( 'Error uploading data: [{0:d}] {1!s} {2!s}, ' 'index {3:s}' . format ( response . status_code , response . reason , response . text , self . _index ) ) logger . warning ( 'Unable to upload data buffer: {0:d}, retrying (attempt ' '{1:d}/{2:d})' . format ( self . _chunk , retry_count + 1 , self . DEFAULT_RETRY_LIMIT ) ) return self . _upload_data_buffer ( end_stream = end_stream , retry_count = retry_count + 1 ) logger . debug ( 'Data buffer nr. {0:d} uploaded, total time: {1:.2f}s' . format ( self . _chunk , time . time ( ) - start_time ) ) self . _chunk += 1 response_dict = response . json ( ) object_dict = response_dict . get ( 'objects' , [ { } ] ) [ 0 ] meta_dict = response_dict . get ( 'meta' , { } ) self . _celery_task_id = meta_dict . get ( 'task_id' , '' ) self . _timeline_id = object_dict . get ( 'id' ) self . _index = object_dict . get ( 'searchindex' , { } ) . get ( 'index_name' ) self . _last_response = response_dict return None