Skip to content

Add path.data functionality #133

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

Closed
wants to merge 3 commits into from
Closed
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: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 3.1.0
- Use native `--path.data` for Logstash 5.0 for sincedb files.
## 3.0.3
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99

## 3.0.2
- relax constrains of `logstash-devutils` see https://github.com/elastic/logstash-devutils/issues/48
## 3.0.1
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Contributors:
* elliot moore (em295)
* yjpa7145
* Guy Boertje (guyboertje)
* Aaron Mildenstein (untergeek)

Note: If you've sent us patches, bug reports, or otherwise contributed to
Logstash, and you aren't on the list above and want to be, please let us know
Expand Down
15 changes: 15 additions & 0 deletions lib/logstash/inputs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require "pathname"
require "socket" # for Socket.gethostname
require "fileutils"

# Stream events from files, normally by tailing them in a manner
# similar to `tail -0F` but optionally reading them from the
Expand Down Expand Up @@ -170,6 +171,9 @@ def register
require "digest/md5"
@logger.info("Registering file input", :path => @path)
@host = Socket.gethostname.force_encoding(Encoding::UTF_8)
# This check is Logstash 5 specific. If the class does not exist, and it
# won't in older versions of Logstash, then we need to set it to nil.
settings = defined?(LogStash::SETTINGS) ? LogStash::SETTINGS : nil

@tail_config = {
:exclude => @exclude,
Expand All @@ -189,6 +193,17 @@ def register
end

if @sincedb_path.nil?
if settings
datapath = File.join(settings.get_value("path.data"), "plugins", "inputs", "file")
# Ensure that the filepath exists before writing, since it's deeply nested.
FileUtils::mkdir_p datapath
@sincedb_path = File.join(datapath, ".sincedb_" + Digest::MD5.hexdigest(@path.join(",")))
end
end

# This section is going to be deprecated eventually, as path.data will be
# the default, not an environment variable (SINCEDB_DIR or HOME)
if @sincedb_path.nil? # If it is _still_ 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 " \
Expand Down
3 changes: 1 addition & 2 deletions 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 = '3.0.3'
s.version = '3.1.0'
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/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down Expand Up @@ -32,4 +32,3 @@ Gem::Specification.new do |s|
s.add_development_dependency 'logstash-codec-json'
s.add_development_dependency 'rspec-sequencing'
end