Skip to content

Adding configurable sincedb directory and file prefix #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.1.4
- Add configurable path for sincedb file and custom file name prefix

## 2.1.3
- Use ruby-filewatch 0.7.1, re-enable close after file is modified again

Expand Down
36 changes: 26 additions & 10 deletions lib/logstash/inputs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ class LogStash::Inputs::File < LogStash::Inputs::Base
# NOTE: it must be a file path and not a directory path
config :sincedb_path, :validate => :string

# Directory path of where the sincedb file will be written. sincedb_path
# overrides this value so they should not be used together. This has
# the same effect of setting $HOME or $SINCEDB_DIR environment variables.
config :sincedb_dir, :validate => :string

# Prefix for the sincedb file name. By default the sincedb file is named
# .sincedb*. This allows you to customize the filename but keep the hash
# that is appended to it.
config :sincedb_file_prefix, :validate => :string, :default => ".sincedb_"

# How often (in seconds) to write a since database with the current position of
# monitored log files.
config :sincedb_write_interval, :validate => :number, :default => 15
Expand Down Expand Up @@ -175,21 +185,27 @@ def register
end

if @sincedb_path.nil?
if ENV["SINCEDB_DIR"].nil? && ENV["HOME"].nil?
@logger.error("No SINCEDB_DIR or HOME environment variable set, I don't know where " \
"to keep track of the files I'm watching. Either set " \
"HOME or SINCEDB_DIR in your environment, or set sincedb_path in " \
"in your Logstash config for the file input with " \
"path '#{@path.inspect}'")
raise # TODO(sissel): HOW DO I FAIL PROPERLY YO
if @sincedb_dir.nil?
if ENV["SINCEDB_DIR"].nil? && ENV["HOME"].nil?
@logger.error("No SINCEDB_DIR or HOME environment variable set, I don't know where " \
"to keep track of the files I'm watching. Either set " \
"HOME or SINCEDB_DIR in your environment, or set sincedb_path in " \
"in your Logstash config for the file input with " \
"path '#{@path.inspect}'")
raise # TODO(sissel): HOW DO I FAIL PROPERLY YO
end
end

#pick SINCEDB_DIR if available, otherwise use HOME
sincedb_dir = ENV["SINCEDB_DIR"] || ENV["HOME"]
#pick sincedb_path if set, then SINCEDB_DIR if available, otherwise use HOME
sincedb_dir = @sincedb_dir || ENV["SINCEDB_DIR"] || ENV["HOME"]

# Join by ',' to make it easy for folks to know their own sincedb
# generated path (vs, say, inspecting the @path array)
@sincedb_path = File.join(sincedb_dir, ".sincedb_" + Digest::MD5.hexdigest(@path.join(",")))
path_hex = Digest::MD5.hexdigest(@path.join(","))

sincedb_file = @sincedb_file_prefix + path_hex

@sincedb_path = File.join(sincedb_dir, sincedb_file)

# Migrate any old .sincedb to the new file (this is for version <=1.1.1 compatibility)
old_sincedb = File.join(sincedb_dir, ".sincedb")
Expand Down
2 changes: 1 addition & 1 deletion logstash-input-file.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-input-file'
s.version = '2.1.3'
s.version = '2.1.4'
s.licenses = ['Apache License (2.0)']
s.summary = "Stream events from files."
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
Expand Down