Skip to content

Commit 72d17fd

Browse files
committed
Add path.data functionality
But maintain reverse compatibility for older versions of Logstash I don't yet know how to test this... Fixes logstash-plugins#133
1 parent 44b87e4 commit 72d17fd

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
## 3.1.0
2+
- Use native `--path.data` for Logstash 5.0 for sincedb files.
13
## 3.0.3
24
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99
3-
45
## 3.0.2
56
- relax constrains of `logstash-devutils` see https://github.com/elastic/logstash-devutils/issues/48
67
## 3.0.1

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Contributors:
1818
* elliot moore (em295)
1919
* yjpa7145
2020
* Guy Boertje (guyboertje)
21+
* Aaron Mildenstein (untergeek)
2122

2223
Note: If you've sent us patches, bug reports, or otherwise contributed to
2324
Logstash, and you aren't on the list above and want to be, please let us know

lib/logstash/inputs/file.rb

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
require "pathname"
77
require "socket" # for Socket.gethostname
8+
require "fileutils"
89

910
# Stream events from files, normally by tailing them in a manner
1011
# similar to `tail -0F` but optionally reading them from the
@@ -170,6 +171,7 @@ def register
170171
require "digest/md5"
171172
@logger.info("Registering file input", :path => @path)
172173
@host = Socket.gethostname.force_encoding(Encoding::UTF_8)
174+
@settings = defined?(LogStash::SETTINGS) ? LogStash::SETTINGS : nil
173175

174176
@tail_config = {
175177
:exclude => @exclude,
@@ -189,6 +191,15 @@ def register
189191
end
190192

191193
if @sincedb_path.nil?
194+
if @settings
195+
datapath = File.join(@settings.get_value("path.data"), "plugins", "inputs", "file")
196+
# Ensure that the filepath exists before writing, since it's deeply nested.
197+
FileUtils::mkdir_p datapath
198+
@sincedb_path = File.join(datapath, ".sincedb_" + Digest::MD5.hexdigest(@path.join(",")))
199+
200+
# This section is going to be deprecated eventually, as path.data will be
201+
# the default, not an environment variable (SINCEDB_DIR or HOME)
202+
if @sincedb_path.nil? # If it is _still_ nil...
192203
if ENV["SINCEDB_DIR"].nil? && ENV["HOME"].nil?
193204
@logger.error("No SINCEDB_DIR or HOME environment variable set, I don't know where " \
194205
"to keep track of the files I'm watching. Either set " \

logstash-input-file.gemspec

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-input-file'
4-
s.version = '3.0.3'
4+
s.version = '3.1.0'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Stream events from files."
77
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"
@@ -32,4 +32,3 @@ Gem::Specification.new do |s|
3232
s.add_development_dependency 'logstash-codec-json'
3333
s.add_development_dependency 'rspec-sequencing'
3434
end
35-

0 commit comments

Comments
 (0)