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: f01a3ed3a9303da14101143f5a9c84299956df9c
4
- data.tar.gz: 4d03cf0691b33ecc441c1f5dacba8c0ea2af644b
3
+ metadata.gz: e582c208330d7349f6b7b3803feb0210fbb38674
4
+ data.tar.gz: 54369be36d824d7e225d266e8f1b43e2f0ad5fb9
5
5
  SHA512:
6
- metadata.gz: 6592ffb28e7008d905704af1af9b3855bd3ab5ff82cf6dae3aed3e7980789346a39e7cd73b013219347ce74e8218117feedefef4f1823a5a93415d967bd2ba50
7
- data.tar.gz: 59244ecbfbb374ee3a464a8e031521cb3121afeaad85ef0564413c2fa96227a8533cf9a85029728f7b13ba54c64837f712e0243e412cb4b3c63d81310db96a6c
6
+ metadata.gz: fd5230aee29627eb7f1f97c90856c4624d2b70e8e9b219c8f262d3cea6bcb9303b6bd5e542d6b632585d17204f2035904ee514e847279529e6b5c7eafc049bbc
7
+ data.tar.gz: 663c4fae667de7cc00d61959ff15b0ce9867bdece38dd321d247a4f353bd2a1028917b70c7d9a53e3cb4cfc505ce661b7700ef4e014a4025389b905f74d4b48f
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.10
@@ -77,7 +77,7 @@ module Fluent
77
77
 
78
78
  @file.pos = 0
79
79
  @file.truncate(0)
80
- @file.write(@cache.values.maps(&:to_file_tracker_entry_format).join)
80
+ @file.write(@cache.values.map(&:to_file_tracker_entry_format).join)
81
81
  end
82
82
  end
83
83
  end
@@ -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
- Fluent::Plugin.register_input("static_file", self)
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
- raise Fluent::ConfigError, "static_file: 'path' parameter is required on static_file input" if @paths.empty?
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 'in_static_file' plugin already use same pos_file path: plugin_id = #{plugin_id_using_this_path}, pos_file path = #{@pos_file}"
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 'static_file' source."
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("static_file: untrack files: #{files_info.keys}")
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("static_file: process files: #{files_info.keys}")
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("static_file: process file: #{file_info.path}")
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
@@ -3,7 +3,7 @@
3
3
  module Fluent
4
4
  module Plugin
5
5
  module InputStaticFile
6
- VERSION = "0.1.1"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
9
9
  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.1
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-30 00:00:00.000000000 Z
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