def convert(logfile, tmpdir, opts='', prefix=None): ''' Copy log file to the local staging area. :param logfile: Path of log file. :param tmpdir : Path of local staging area. :param opts : A set of options for the `cp` command. :param prefix : If `prefix` is specified, the file name will begin with that; otherwise, a default `prefix` is used. :returns : Path of log file in local staging area. :rtype : ``str`` ''' logger = logging.getLogger('SPOT.INGEST.PROXY.PROCESS') with tempfile.NamedTemporaryFile(prefix=prefix, dir=tmpdir, delete=False) as fp: command = COMMAND.format(opts, logfile, fp.name) logger.debug('Execute command: {0}'.format(command)) Util.popen(command, raises=True) return fp.name
def convert(netflow, tmpdir, opts='', prefix=None): ''' Convert `nfcapd` file to a comma-separated output format. :param netflow : Path of binary file. :param tmpdir : Path of local staging area. :param opts : A set of options for `nfdump` command. :param prefix : If `prefix` is specified, the file name will begin with that; otherwise, a default `prefix` is used. :returns : Path of CSV-converted file. :rtype : ``str`` :raises OSError: If an error occurs while executing the `nfdump` command. ''' logger = logging.getLogger('SPOT.INGEST.FLOW.PROCESS') with tempfile.NamedTemporaryFile(prefix=prefix, dir=tmpdir, delete=False) as fp: command = COMMAND.format(netflow, opts, fp.name) logger.debug('Execute command: {0}'.format(command)) Util.popen(command, raises=True) return fp.name