fluent-plugin-input-static-file 0.1.1 → 0.2.0
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: e582c208330d7349f6b7b3803feb0210fbb38674
|
4
|
+
data.tar.gz: 54369be36d824d7e225d266e8f1b43e2f0ad5fb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5230aee29627eb7f1f97c90856c4624d2b70e8e9b219c8f262d3cea6bcb9303b6bd5e542d6b632585d17204f2035904ee514e847279529e6b5c7eafc049bbc
|
7
|
+
data.tar.gz: 663c4fae667de7cc00d61959ff15b0ce9867bdece38dd321d247a4f353bd2a1028917b70c7d9a53e3cb4cfc505ce661b7700ef4e014a4025389b905f74d4b48f
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.10
|
@@ -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,53 @@ 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
|
+
end
|
228
|
+
|
229
|
+
def archive(file_info)
|
230
|
+
return if @archive_to.nil?
|
231
|
+
|
232
|
+
file_name = File.basename(file_info.path)
|
233
|
+
target_path = format(@archive_to, file_name)
|
234
|
+
|
235
|
+
target_path_basedir = if target_path.end_with?("/")
|
236
|
+
target_path
|
237
|
+
else
|
238
|
+
File.dirname(target_path)
|
239
|
+
end
|
240
|
+
FileUtils.mkdir_p(target_path_basedir, mode: @dir_perm)
|
241
|
+
|
242
|
+
log.debug("#{PLUGIN_NAME}: archiving #{file_info.path} to #{target_path}")
|
243
|
+
FileUtils.mv(file_info.path, target_path)
|
244
|
+
rescue StandardError => e
|
245
|
+
log.warn("#{PLUGIN_NAME}: can't archive #{file_info.path} to #{target_path}: #{e}")
|
216
246
|
end
|
217
247
|
end
|
218
248
|
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.
|
4
|
+
version: 0.2.0
|
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-05-
|
11
|
+
date: 2022-05-31 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
|