fluent-plugin-input-static-file 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bdfe4c08f457eded785a80862beb1104cf8fd95
|
4
|
+
data.tar.gz: b8ccfdb81d8ad125d346fdc50824e35640d50fc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206998e202d008ca737b018457afa8fff1ea9e50a994cd172a0e23f4b4cfc521707894ca786a2be519d31bcd18595ae9e4d8dbb4cba7a14d6460bf04fbd6418a
|
7
|
+
data.tar.gz: ccbbb8af45d63974d19de472c8d3137a17d743596fda76a5f2d0b2dfbcf0dd74952b294c73da50f3ae431f21b656187716924e6ab3d8892906387fbf9ea016c9
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.10
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require "fluent/plugin/input"
|
4
4
|
require "fluent/config/error"
|
5
5
|
|
6
|
-
require "
|
6
|
+
require "fluent/plugin/in_static_file/file_tracker"
|
7
7
|
|
8
8
|
if Fluent.windows?
|
9
9
|
require "fluent/plugin/file_wrapper"
|
@@ -15,14 +15,14 @@ module Fluent
|
|
15
15
|
module Plugin
|
16
16
|
# InStaticFile is an input plugin for file with static content
|
17
17
|
class InStaticFile < Fluent::Plugin::Input
|
18
|
-
|
18
|
+
PLUGIN_NAME = "static_file"
|
19
|
+
|
20
|
+
Fluent::Plugin.register_input(PLUGIN_NAME, self)
|
19
21
|
|
20
22
|
helpers :timer, :compat_parameters, :parser
|
21
23
|
|
22
24
|
RESERVED_CHARS = ["/", "*", "%"].freeze
|
23
25
|
|
24
|
-
# FIXME: path_key
|
25
|
-
|
26
26
|
desc "The paths to read. Multiple paths can be specified, separated by comma."
|
27
27
|
config_param :path, :string
|
28
28
|
desc "path delimiter used for spliting path config"
|
@@ -40,12 +40,17 @@ module Fluent
|
|
40
40
|
|
41
41
|
desc "The tag of the event."
|
42
42
|
config_param :tag, :string
|
43
|
+
desc "Add the log path being tailed to records. Specify the field name to be used."
|
44
|
+
config_param :path_key, :string, default: nil
|
43
45
|
|
44
46
|
desc "Fluentd will record the position it last read into this file."
|
45
47
|
config_param :pos_file, :string, default: nil
|
46
48
|
desc "Follow inodes instead of following file names. Guarantees more stable delivery and allows to use * in path pattern with rotating files"
|
47
49
|
config_param :follow_inodes, :bool, default: false
|
48
50
|
|
51
|
+
desc "When processed move to another location"
|
52
|
+
config_param :archive_to, :string, default: nil
|
53
|
+
|
49
54
|
def initialize
|
50
55
|
super
|
51
56
|
|
@@ -70,19 +75,22 @@ module Fluent
|
|
70
75
|
end
|
71
76
|
|
72
77
|
@paths = @path.split(@path_delimiter).map(&:strip).uniq
|
73
|
-
|
78
|
+
if @paths.empty?
|
79
|
+
raise Fluent::ConfigError,
|
80
|
+
"#{PLUGIN_NAME}: 'path' parameter is required on #{PLUGIN_NAME} input"
|
81
|
+
end
|
74
82
|
|
75
83
|
if @pos_file
|
76
84
|
if @variable_store.key?(@pos_file) && !called_in_test?
|
77
85
|
plugin_id_using_this_path = @variable_store[@pos_file]
|
78
86
|
raise Fluent::ConfigError,
|
79
|
-
"Other '
|
87
|
+
"Other '#{PLUGIN_NAME}' plugin already use same pos_file path: plugin_id = #{plugin_id_using_this_path}, pos_file path = #{@pos_file}"
|
80
88
|
end
|
81
89
|
@variable_store[@pos_file] = plugin_id
|
82
90
|
else
|
83
91
|
raise Fluent::ConfigError, "Can't follow inodes without pos_file configuration parameter" if @follow_inodes
|
84
92
|
|
85
|
-
log.warn "'pos_file PATH' parameter is not set to a '
|
93
|
+
log.warn "'pos_file PATH' parameter is not set to a '#{PLUGIN_NAME}' source."
|
86
94
|
log.warn "this parameter is highly recommended to save the file status."
|
87
95
|
end
|
88
96
|
|
@@ -188,31 +196,56 @@ module Fluent
|
|
188
196
|
end
|
189
197
|
|
190
198
|
def untrack_files(files_info)
|
191
|
-
log.debug("
|
199
|
+
log.debug("#{PLUGIN_NAME}: untrack files: #{files_info.keys}")
|
192
200
|
files_info.each do |_id, file_info|
|
193
201
|
@file_tracker.remove(file_info)
|
194
202
|
end
|
195
203
|
end
|
196
204
|
|
197
205
|
def process_files(files_info)
|
198
|
-
log.debug("
|
206
|
+
log.debug("#{PLUGIN_NAME}: process files: #{files_info.keys}")
|
199
207
|
files_info.each do |_id, file_info|
|
200
208
|
process_file(file_info)
|
201
209
|
end
|
202
210
|
end
|
203
211
|
|
204
212
|
def process_file(file_info)
|
205
|
-
log.debug("
|
213
|
+
log.debug("#{PLUGIN_NAME}: process file: #{file_info.path}")
|
206
214
|
|
207
215
|
return if @file_tracker.has?(file_info)
|
208
216
|
|
209
217
|
File.open(file_info.path, "rb") do |f|
|
210
218
|
@parser.parse(f) do |time, record|
|
219
|
+
record[@path_key] ||= file_info.path unless @path_key.nil?
|
211
220
|
router.emit(tag, time, record)
|
212
221
|
end
|
213
222
|
end
|
214
223
|
|
215
224
|
@file_tracker.add(file_info)
|
225
|
+
|
226
|
+
archive(file_info)
|
227
|
+
rescue StandardError => e
|
228
|
+
log.error "#{PLUGIN_NAME}: trying to process unparsable file #{file_info.path}: #{e}"
|
229
|
+
log.debug_backtrace(e.backtrace)
|
230
|
+
end
|
231
|
+
|
232
|
+
def archive(file_info)
|
233
|
+
return if @archive_to.nil?
|
234
|
+
|
235
|
+
file_name = File.basename(file_info.path)
|
236
|
+
target_path = format(@archive_to, file_name)
|
237
|
+
|
238
|
+
target_path_basedir = if target_path.end_with?("/")
|
239
|
+
target_path
|
240
|
+
else
|
241
|
+
File.dirname(target_path)
|
242
|
+
end
|
243
|
+
FileUtils.mkdir_p(target_path_basedir, mode: @dir_perm)
|
244
|
+
|
245
|
+
log.debug("#{PLUGIN_NAME}: archiving #{file_info.path} to #{target_path}")
|
246
|
+
FileUtils.mv(file_info.path, target_path)
|
247
|
+
rescue StandardError => e
|
248
|
+
log.warn("#{PLUGIN_NAME}: can't archive #{file_info.path} to #{target_path}: #{e}")
|
216
249
|
end
|
217
250
|
end
|
218
251
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-input-static-file
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Tych
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
@@ -226,6 +226,7 @@ extra_rdoc_files: []
|
|
226
226
|
files:
|
227
227
|
- ".gitignore"
|
228
228
|
- ".rubocop.yml"
|
229
|
+
- ".ruby-version"
|
229
230
|
- CHANGELOG.md
|
230
231
|
- CODE_OF_CONDUCT.md
|
231
232
|
- Gemfile
|