225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
# File 'lib/logstash/inputs/file.rb', line 225
def register
require "addressable/uri"
require "digest/md5"
@logger.trace("Registering file input", :path => @path)
@host = Socket.gethostname.force_encoding(Encoding::UTF_8)
settings = defined?(LogStash::SETTINGS) ? LogStash::SETTINGS : nil
@filewatch_config = {
:exclude => @exclude,
:stat_interval => @stat_interval,
:discover_interval => @discover_interval,
:sincedb_write_interval => @sincedb_write_interval,
:delimiter => @delimiter,
:ignore_older => @ignore_older,
:close_older => @close_older,
:max_open_files => @max_open_files,
:sincedb_clean_after => @sincedb_clean_after,
:file_chunk_count => @file_chunk_count,
:file_chunk_size => @file_chunk_size,
:file_sort_by => @file_sort_by,
:file_sort_direction => @file_sort_direction,
}
@completed_file_handlers = []
@path.each do |path|
if Pathname.new(path).relative?
raise ArgumentError.new("File paths must be absolute, relative path specified: #{path}")
end
end
if @sincedb_path.nil?
base_sincedb_path = build_sincedb_base_from_settings(settings) || build_sincedb_base_from_env
@sincedb_path = build_random_sincedb_filename(base_sincedb_path)
@logger.info('No sincedb_path set, generating one based on the "path" setting', :sincedb_path => @sincedb_path.to_s, :path => @path)
else
@sincedb_path = Pathname.new(@sincedb_path)
if @sincedb_path.directory?
raise ArgumentError.new("The \"sincedb_path\" argument must point to a file, received a directory: \"#{@sincedb_path}\"")
end
end
@filewatch_config[:sincedb_path] = @sincedb_path
@filewatch_config[:start_new_files_at] = @start_position.to_sym
if @file_completed_action.include?('log')
if @file_completed_log_path.nil?
raise ArgumentError.new('The "file_completed_log_path" setting must be provided when the "file_completed_action" is set to "log" or "log_and_delete"')
else
@file_completed_log_path = Pathname.new(@file_completed_log_path)
unless @file_completed_log_path.exist?
begin
FileUtils.touch(@file_completed_log_path)
rescue
raise ArgumentError.new("The \"file_completed_log_path\" file can't be created: #{@file_completed_log_path}")
end
end
end
end
if tail_mode?
@watcher_class = FileWatch::ObservingTail
else
@watcher_class = FileWatch::ObservingRead
if @file_completed_action.include?('log')
@completed_file_handlers << LogCompletedFileHandler.new(@file_completed_log_path)
end
if @file_completed_action.include?('delete')
@completed_file_handlers << DeleteCompletedFileHandler.new
end
end
@codec = LogStash::Codecs::IdentityMapCodec.new(@codec)
end
|