diff --git a/CHANGELOG.md b/CHANGELOG.md index 681ae71..cb973b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.1.1 + - Refactor: unified ECS target + validate field reference [#86](https://github.com/logstash-plugins/logstash-filter-csv/pull/86) + ## 3.1.0 - Add ECS support [#85](https://github.com/logstash-plugins/logstash-filter-csv/pull/85) diff --git a/VERSION b/VERSION index fd2a018..94ff29c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.0 +3.1.1 diff --git a/lib/logstash/filters/csv.rb b/lib/logstash/filters/csv.rb index 5a6d2c3..e259b8b 100644 --- a/lib/logstash/filters/csv.rb +++ b/lib/logstash/filters/csv.rb @@ -1,7 +1,9 @@ # encoding: utf-8 require "logstash/filters/base" require "logstash/namespace" -require "logstash/plugin_mixins/ecs_compatibility_support" +require 'logstash/plugin_mixins/ecs_compatibility_support' +require 'logstash/plugin_mixins/ecs_compatibility_support/target_check' +require 'logstash/plugin_mixins/validator_support/field_reference_validation_adapter' require "csv" @@ -10,6 +12,9 @@ # This filter can also parse data with any separator, not just commas. class LogStash::Filters::CSV < LogStash::Filters::Base include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1) + include LogStash::PluginMixins::ECSCompatibilitySupport::TargetCheck + + extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter config_name "csv" @@ -38,7 +43,7 @@ class LogStash::Filters::CSV < LogStash::Filters::Base # Define target field for placing the data. # Defaults to writing to the root of the event. - config :target, :validate => :string + config :target, :validate => :field_reference # Define whether column names should autogenerated or not. # Defaults to true. If set to false, columns not having a header specified will not be parsed. @@ -105,15 +110,6 @@ class LogStash::Filters::CSV < LogStash::Filters::Base CONVERTERS.default = lambda {|v| v} CONVERTERS.freeze - def initialize(params) - super - if ecs_compatibility != :disabled && @target.nil? - logger.info('ECS compatibility is enabled but no ``target`` option was specified, it is recommended'\ - ' to set the option to avoid potential schema conflicts (if your data is ECS compliant or'\ - ' non-conflicting feel free to ignore this message)') - end - end - def register # validate conversion types to be the valid ones. bad_types = @convert.values.select do |type| @@ -125,7 +121,7 @@ def register # @convert_symbols contains the symbolized types to avoid symbol conversion in the transform method @convert_symbols = @convert.inject({}){|result, (k, v)| result[k] = v.to_sym; result} - # make sure @target is in the format [field name] if defined, i.e. surrounded by brakets + # make sure @target is in the format [field name] if defined, i.e. surrounded by brackets @target = "[#{@target}]" if @target && !@target.start_with?("[") # if the zero byte character is entered in the config, set the value @@ -137,7 +133,7 @@ def register end def filter(event) - @logger.debug? && @logger.debug("Running csv filter", :event => event) + @logger.debug? && @logger.debug("Running csv filter", :event => event.to_hash) if (source = event.get(@source)) begin @@ -178,7 +174,7 @@ def filter(event) end end - @logger.debug? && @logger.debug("Event after csv filter", :event => event) + @logger.debug? && @logger.debug("Event after csv filter", :event => event.to_hash) end private diff --git a/logstash-filter-csv.gemspec b/logstash-filter-csv.gemspec index 6f934d7..7e4ea4a 100644 --- a/logstash-filter-csv.gemspec +++ b/logstash-filter-csv.gemspec @@ -23,7 +23,9 @@ Gem::Specification.new do |s| # Gem dependencies s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99" + s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~> 1.3' + s.add_runtime_dependency 'logstash-mixin-validator_support', '~> 1.0' + s.add_development_dependency 'logstash-devutils' - s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.2' end