def filter_data(self, data, value=None, args=None):
        """Morph log data by preceeding time period (single log)"""
        if args:
            if not args.last:
                return data
        if not value: value = args.last
        # Set the units and number from the option:
        lastunit = value[-1]
        lastnum = value[:-1]
        
        # Set the start time:
        if lastunit == 's':
            starttime = datetime.utcnow() - \
                    timedelta(seconds=int(lastnum))
        if lastunit == 'm':
            starttime = datetime.utcnow() - \
                    timedelta(minutes=int(lastnum))
        if lastunit == 'h':
            starttime = datetime.utcnow() - \
                    timedelta(hours=int(lastnum))
        if lastunit == 'd':
            starttime = datetime.utcnow() - \
                    timedelta(days=int(lastnum))
        ourstart = int(starttime.strftime('%Y%m%d%H%M%S'))
        
        # Pull out the specified time period:
        newdata = {}
        if 'parser' in data.keys():
            newdata['parser'] = data['parser']
            newdata['source_path'] = data['source_path']
            newdata['source_file'] = data['source_file']
            newdata['source_file_mtime'] = data['source_file_mtime']
            newdata['source_file_year'] = data['source_file_year']
        newdata['entries'] = []

        for entry in data['entries']:
            if 'numeric_date_stamp_utc' in entry.keys():
                if '.' in entry['numeric_date_stamp_utc']:
                    dstamp = int(entry['numeric_date_stamp_utc'].split('.')[0])
                else:
                    dstamp = int(entry['numeric_date_stamp_utc'])
                if dstamp >= ourstart: 
                    newdata['entries'].append(entry)

        return newdata
def filter_data ( self , data , value = None , args = None ) : if args : if not args . last : return data if not value : value = args . last lastunit = value [ - 1 ] lastnum = value [ : - 1 ] if lastunit == 's' : starttime = datetime . utcnow ( ) - timedelta ( seconds = int ( lastnum ) ) if lastunit == 'm' : starttime = datetime . utcnow ( ) - timedelta ( minutes = int ( lastnum ) ) if lastunit == 'h' : starttime = datetime . utcnow ( ) - timedelta ( hours = int ( lastnum ) ) if lastunit == 'd' : starttime = datetime . utcnow ( ) - timedelta ( days = int ( lastnum ) ) ourstart = int ( starttime . strftime ( '%Y%m%d%H%M%S' ) ) newdata = { } if 'parser' in data . keys ( ) : newdata [ 'parser' ] = data [ 'parser' ] newdata [ 'source_path' ] = data [ 'source_path' ] newdata [ 'source_file' ] = data [ 'source_file' ] newdata [ 'source_file_mtime' ] = data [ 'source_file_mtime' ] newdata [ 'source_file_year' ] = data [ 'source_file_year' ] newdata [ 'entries' ] = [ ] for entry in data [ 'entries' ] : if 'numeric_date_stamp_utc' in entry . keys ( ) : if '.' in entry [ 'numeric_date_stamp_utc' ] : dstamp = int ( entry [ 'numeric_date_stamp_utc' ] . split ( '.' ) [ 0 ] ) else : dstamp = int ( entry [ 'numeric_date_stamp_utc' ] ) if dstamp >= ourstart : newdata [ 'entries' ] . append ( entry ) return newdata
Morph log data by preceeding time period (single log)