diff --git a/.travis.yml b/.travis.yml index 350c4eb..6b858e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,11 @@ +--- sudo: false language: ruby cache: bundler rvm: - - jruby-1.7.23 -script: - - bundle exec rspec spec +- jruby-1.7.25 +script: +- bundle exec rspec spec +jdk: oraclejdk8 +before_install: +- git clone -b feature/event_interface https://github.com/elastic/logstash diff --git a/Gemfile b/Gemfile index d926697..c781dcb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,6 @@ source 'https://rubygems.org' -gemspec \ No newline at end of file +gemspec +gem "logstash-core", :path => "./logstash/logstash-core" +gem "logstash-core-plugin-api", :path => "./logstash/logstash-core-plugin-api" +gem "logstash-core-event-java", :path => "./logstash/logstash-core-event-java" +gem "logstash-devutils", :github => "elastic/logstash-devutils", :branch => "feature/plugin-api-2_0" diff --git a/lib/logstash/filters/fingerprint.rb b/lib/logstash/filters/fingerprint.rb index d58a678..eb65d7b 100644 --- a/lib/logstash/filters/fingerprint.rb +++ b/lib/logstash/filters/fingerprint.rb @@ -72,31 +72,31 @@ class << self; alias_method :anonymize, :anonymize_openssl; end def filter(event) case @method when :UUID - event[@target] = SecureRandom.uuid + event.set(@target, SecureRandom.uuid) when :PUNCTUATION @source.sort.each do |field| next unless event.include?(field) # In order to keep some backwards compatibility we should use the unicode version # of the regexp because the POSIX one ([[:punct:]]) left some unwanted characters unfiltered (Symbols). # gsub(/[^[:punct:]]/,'') should be equivalent to gsub(/[^[\p{P}\p{S}]]/,''), but not 100% in JRuby. - event[@target] = event[field].gsub(/[^[\p{P}\p{S}]]/,'') + event.set(@target, event.get(field).gsub(/[^[\p{P}\p{S}]]/,'')) end else if @concatenate_sources to_string = "" @source.sort.each do |k| - to_string << "|#{k}|#{event[k]}" + to_string << "|#{k}|#{event.get(k)}" end to_string << "|" @logger.debug? && @logger.debug("String built", :to_checksum => to_string) - event[@target] = anonymize(to_string) + event.set(@target, anonymize(to_string)) else @source.each do |field| next unless event.include?(field) - if event[field].is_a?(Array) - event[@target] = event[field].collect { |v| anonymize(v) } + if event.get(field).is_a?(Array) + event.set(@target, event.get(field).collect { |v| anonymize(v) }) else - event[@target] = anonymize(event[field]) + event.set(@target, anonymize(event.get(field))) end end end diff --git a/logstash-filter-fingerprint.gemspec b/logstash-filter-fingerprint.gemspec index aa4ed88..aa2be62 100644 --- a/logstash-filter-fingerprint.gemspec +++ b/logstash-filter-fingerprint.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" } # Gem dependencies - s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0" + s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0" s.add_runtime_dependency "murmurhash3" #(MIT license) s.add_development_dependency 'logstash-devutils' end diff --git a/spec/filters/fingerprint_spec.rb b/spec/filters/fingerprint_spec.rb index 94fc71f..ab6ad06 100644 --- a/spec/filters/fingerprint_spec.rb +++ b/spec/filters/fingerprint_spec.rb @@ -16,7 +16,7 @@ CONFIG sample("clientip" => "233.255.13.44") do - insist { subject["fingerprint"] } == "233.255.13.0" + insist { subject.get("fingerprint") } == "233.255.13.0" end end @@ -31,7 +31,7 @@ CONFIG sample("clientip" => "123.52.122.33") do - insist { subject["fingerprint"] } == 1541804874 + insist { subject.get("fingerprint") } == 1541804874 end end @@ -47,7 +47,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "fdc60acc4773dc5ac569ffb78fcb93c9630797f4" + insist { subject.get("fingerprint") } == "fdc60acc4773dc5ac569ffb78fcb93c9630797f4" end end @@ -64,7 +64,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "/cYKzEdz3FrFaf+3j8uTyWMHl/Q=" + insist { subject.get("fingerprint") } == "/cYKzEdz3FrFaf+3j8uTyWMHl/Q=" end end @@ -80,7 +80,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "345bec3eff242d53b568916c2610b3e393d885d6b96d643f38494fd74bf4a9ca" + insist { subject.get("fingerprint") } == "345bec3eff242d53b568916c2610b3e393d885d6b96d643f38494fd74bf4a9ca" end end @@ -97,7 +97,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "NFvsPv8kLVO1aJFsJhCz45PYhda5bWQ/OElP10v0qco=" + insist { subject.get("fingerprint") } == "NFvsPv8kLVO1aJFsJhCz45PYhda5bWQ/OElP10v0qco=" end end @@ -113,7 +113,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "22d4c0e8c4fbcdc4887d2038fca7650f0e2e0e2457ff41c06eb2a980dded6749561c814fe182aff93e2538d18593947a" + insist { subject.get("fingerprint") } == "22d4c0e8c4fbcdc4887d2038fca7650f0e2e0e2457ff41c06eb2a980dded6749561c814fe182aff93e2538d18593947a" end end @@ -130,7 +130,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "ItTA6MT7zcSIfSA4/KdlDw4uDiRX/0HAbrKpgN3tZ0lWHIFP4YKv+T4lONGFk5R6" + insist { subject.get("fingerprint") } == "ItTA6MT7zcSIfSA4/KdlDw4uDiRX/0HAbrKpgN3tZ0lWHIFP4YKv+T4lONGFk5R6" end end @@ -146,7 +146,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "11c19b326936c08d6c50a3c847d883e5a1362e6a64dd55201a25f2c1ac1b673f7d8bf15b8f112a4978276d573275e3b14166e17246f670c2a539401c5bfdace8" + insist { subject.get("fingerprint") } == "11c19b326936c08d6c50a3c847d883e5a1362e6a64dd55201a25f2c1ac1b673f7d8bf15b8f112a4978276d573275e3b14166e17246f670c2a539401c5bfdace8" end end @@ -163,7 +163,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "EcGbMmk2wI1sUKPIR9iD5aE2Lmpk3VUgGiXywawbZz99i/FbjxEqSXgnbVcydeOxQWbhckb2cMKlOUAcW/2s6A==" + insist { subject.get("fingerprint") } == "EcGbMmk2wI1sUKPIR9iD5aE2Lmpk3VUgGiXywawbZz99i/FbjxEqSXgnbVcydeOxQWbhckb2cMKlOUAcW/2s6A==" end end @@ -179,7 +179,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "9336c879e305c9604a3843fc3e75948f" + insist { subject.get("fingerprint") } == "9336c879e305c9604a3843fc3e75948f" end end @@ -196,7 +196,7 @@ CONFIG sample("clientip" => "123.123.123.123") do - insist { subject["fingerprint"] } == "kzbIeeMFyWBKOEP8PnWUjw==" + insist { subject.get("fingerprint") } == "kzbIeeMFyWBKOEP8PnWUjw==" end end @@ -212,7 +212,7 @@ CONFIG sample("clientip" => [ "123.123.123.123", "223.223.223.223" ]) do - insist { subject["fingerprint"]} == [ "9336c879e305c9604a3843fc3e75948f", "7a6c66b8d3f42a7d650e3354af508df3" ] + insist { subject.get("fingerprint")} == [ "9336c879e305c9604a3843fc3e75948f", "7a6c66b8d3f42a7d650e3354af508df3" ] end end @@ -228,7 +228,7 @@ CONFIG sample("field1" => "test1", "field2" => "test2") do - insist { subject["fingerprint"]} == "872da745e45192c2a1d4bf7c1ff8a370" + insist { subject.get("fingerprint")} == "872da745e45192c2a1d4bf7c1ff8a370" end end @@ -243,11 +243,11 @@ CONFIG sample("field1" => "PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in /var/www/htdocs/test.php on line 233") do - insist { subject["fingerprint"] } == ":_()[<='.-'>.-]:-////." + insist { subject.get("fingerprint") } == ":_()[<='.-'>.-]:-////." end sample("field1" => "Warning: Ruby(ルビ) is an awesome language.") do - insist { subject["fingerprint"] } == ":()." + insist { subject.get("fingerprint") } == ":()." end end @@ -266,7 +266,7 @@ CONFIG sample("@timestamp" => epoch_time) do - insist { subject["fingerprint"] } == '1d5379ec92d86a67cfc642d55aa050ca312d3b9a' + insist { subject.get("fingerprint") } == '1d5379ec92d86a67cfc642d55aa050ca312d3b9a' end end @@ -281,7 +281,7 @@ CONFIG sample("@timestamp" => epoch_time) do - insist { subject["fingerprint"] } == 743372282 + insist { subject.get("fingerprint") } == 743372282 end end end