Service for collecting and processing files (with hooks)
pip install filecollector
It has 2 main components right now: collector and server. Collector is responsible to collect/anonymize the files and run hook scripts on those. Server is only a browser for the collected files.
At the start you need to create a yaml configuration file for the collector.
Only this configuration is required as an input for filecollector.
filecollector collector start --config filecollector.yaml -p /my/pid/dir
filecollector server start --config filecollector.yaml -p /my/pid/dir
server:
port: 1999
folder: "../example/files"
collector:
files:
- path: "example/example*.txt"
label: "example"
rules:
- pattern: \d{4}[^\w]\d{4}[^\w]\d{4}[^\w]\d{4}
replacement: "[REDACTED]"
processFileScript: example/scripts/process_file.sh
compress: true
useFullPath: true
outputScript: example/scripts/output_file.sh
processFilesFolderScript: example/scripts/tmp_folder.sh
deleteProcessedTemplateFiles: true
outputLocation: "example/files"
Running simple example:
# start collector
filecollector collector start --config example/filecollector.yaml -p /my/pid/dir
# start server for browsing
filecollector server start --config example/filecollector.yaml -p /my/pid/dir
Running with docker:
# collector only
docker run --rm -v /my/path/to/config:/my/path/to/config oleewere/filecollector:latest --config /my/path/to/config/filecollector.yaml
collector:
files:
- path: "example/example*.txt"
label: "txt"
rules:
- pattern: \d{4}[^\w]\d{4}[^\w]\d{4}[^\w]\d{4}
replacement: "[REDACTED]"
compress: false
useFullPath: true
deleteProcessedTempFilesOneByOne: true
outputLocation: "example/files"
fluentProcessor:
host: "localhost"
port: 24224
tag: example
Fluentd configuration:
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<match example.**>
@type stdout
</match>
Running fluentd example:
# start fluentd
fluentd --config example/fluentd.conf
# start collector
filecollector collector start --config example/fluentd-filecollector.yaml -p /my/pid/dir
serverThe server block, it contains configurations related with the filecollector server component.
server.portPort that will be used by the filecollector server.
server.folderThe folder that is server by the file server.
collectorThe collector block, it contains configurations related with the filecollector collector component.
collector.filesList of files (with path and label fields are required) that needs to be collected.
collector.files.pathFilename or wildcard that represents the files that is needed to be collected.
collector.files.labelIt will be used as a first level folder inside outputLocation for the file collection. E.g. if this value is mylabel, the output will go into <outputLocation>/mylabel
collector.files.folderPrefixIf it's set, the filecollector will put the files into this folder (inside outputLocation, but before label)
collector.files.useFullPathUse full path for processed files (inside outputLocation). Can be useful if because of the wildcard patterns, the base file name are the same for different files from different folders. It overrides the collector.useFullPath option.
collector.files.excludesThe path options can be used as wildcards.
There are other options like: useFullPath or excludes. The useFullPath option is the same as the below one, but it overrides the global behavior (default: false). The excludes option is a list of path patterns that should be excluded from path pattern matches.
collector.files.skipLabelFromPathIf that is set to true. In the output location, the processed files are not going to contain thier labels as a prefix. Default value is false.
collector.rulesList of anonymization rules that can be run against the file inputs. (pattern field for matching, replacement for the replacement on match)
collector.compressAt the end of the filecollection, the output folder is compressed. Default value is true.
collector.compressFormatCompression format, possible values: zip, tar, gztar, bztar. Default value is zip.
collector.outputLocationOutput location (directory), where the processed file(s) will be stored.
collector.useFullPathUse full path for processed files (inside outputLocation). Can be useful if because of the wildcard patterns, the base file name are the same for different files from different folders. Default value is true.
collector.checkDiskSpaceIF this option is set, before file processing - based on the file size and requiredDiskSpaceRatio option - it will check you have enough space for copying those files into your working directory or not. Default value is true.
collector.requiredDiskSpaceRatioThis value is used for checkDiskSpace option. The required disk space will be calculated with this value (as a multiplier, e.g. if my files full size is 100MB and this setting is 1.6, the processing will require 160MB free space). Default value is 1.0.
collector.processFileScriptScript that runs agains 1 processed file. It gets the filename and the label for a processed file.
collector.processFilesFolderScriptScript that runs once after the files are collected. It gets the folder name (where the files are processed) as an input.
collector.preProcessScriptScript that runs before the files are collected. It gets the folder name (where the files are processed) as an input.
collector.outputScriptScript that runs once with the compressed output file name as an input.
collector.deleteCompressedFileDelete compressed file at the end of the file collection. That can be useful e.g. if an output script upload the compressed file somewhere adn it is needed to do a cleanup. Default value is false.
collector.deleteProcessedTempFilesAfter collection of the files + compression, the collected files are deleted. Can be useful to disable this behaviour compress option is disabled. Default value is true.
collector.deleteProcessedTempFilesOneByOneIf this option is set, files are deleted right after processed (one at a time). That can be useful if compression is disabled, and you would like to stream large files to fluentd. Default value is false.
collector.fluentProcessorFluentd related section for processing files line by line - streaming data by fluentd forward protocol.
collector.fluentProcessor.hostFluentd host (for forward protocol). Default value: localhost.
collector.fluentProcessor.portFluentd port (for forward protocol). Default value: 24224.
collector.fluentProcessor.tagFluentd tag for streaming lines. The generated tag for forward protocol is <collector.fluentProcessor.tag>.<file label for monitored file>.
collector.fluentProcessor.messageFieldThe processed lines are mapped for this field before data has been sent to Fluentd. Default value: message.
collector.fluentProcessor.includeTimeIf this is enabled, current time is included in the fluentd data event. (as time field). Default value: false.
collector.loggerLogger related configurations for the collector.
collector.logger.levelLogger level that is used during logging.
collector.logger.formatFormat of the log events. Default value is %(message)s.
collector.logger.fileFile where the log will write the logging events, if it is not set, only stdout will be used.
git checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)Content type
Image
Digest
Size
26.1 MB
Last updated
about 6 years ago
docker pull oleewere/filecollector