Skip to content

Commit

Permalink
Update with new Event APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
suyograo committed May 3, 2016
1 parent 6b2ddbf commit 40ee5d7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
source 'https://rubygems.org'
gemspec
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"
14 changes: 7 additions & 7 deletions lib/logstash/filters/fingerprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion logstash-filter-fingerprint.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions spec/filters/fingerprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,7 +31,7 @@
CONFIG

sample("clientip" => "123.52.122.33") do
insist { subject["fingerprint"] } == 1541804874
insist { subject.get("fingerprint") } == 1541804874
end
end

Expand All @@ -47,7 +47,7 @@
CONFIG

sample("clientip" => "123.123.123.123") do
insist { subject["fingerprint"] } == "fdc60acc4773dc5ac569ffb78fcb93c9630797f4"
insist { subject.get("fingerprint") } == "fdc60acc4773dc5ac569ffb78fcb93c9630797f4"
end
end

Expand All @@ -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

Expand All @@ -80,7 +80,7 @@
CONFIG

sample("clientip" => "123.123.123.123") do
insist { subject["fingerprint"] } == "345bec3eff242d53b568916c2610b3e393d885d6b96d643f38494fd74bf4a9ca"
insist { subject.get("fingerprint") } == "345bec3eff242d53b568916c2610b3e393d885d6b96d643f38494fd74bf4a9ca"
end
end

Expand All @@ -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

Expand All @@ -113,7 +113,7 @@
CONFIG

sample("clientip" => "123.123.123.123") do
insist { subject["fingerprint"] } == "22d4c0e8c4fbcdc4887d2038fca7650f0e2e0e2457ff41c06eb2a980dded6749561c814fe182aff93e2538d18593947a"
insist { subject.get("fingerprint") } == "22d4c0e8c4fbcdc4887d2038fca7650f0e2e0e2457ff41c06eb2a980dded6749561c814fe182aff93e2538d18593947a"
end
end

Expand All @@ -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

Expand All @@ -146,7 +146,7 @@
CONFIG

sample("clientip" => "123.123.123.123") do
insist { subject["fingerprint"] } == "11c19b326936c08d6c50a3c847d883e5a1362e6a64dd55201a25f2c1ac1b673f7d8bf15b8f112a4978276d573275e3b14166e17246f670c2a539401c5bfdace8"
insist { subject.get("fingerprint") } == "11c19b326936c08d6c50a3c847d883e5a1362e6a64dd55201a25f2c1ac1b673f7d8bf15b8f112a4978276d573275e3b14166e17246f670c2a539401c5bfdace8"
end
end

Expand All @@ -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

Expand All @@ -179,7 +179,7 @@
CONFIG

sample("clientip" => "123.123.123.123") do
insist { subject["fingerprint"] } == "9336c879e305c9604a3843fc3e75948f"
insist { subject.get("fingerprint") } == "9336c879e305c9604a3843fc3e75948f"
end
end

Expand All @@ -196,7 +196,7 @@
CONFIG

sample("clientip" => "123.123.123.123") do
insist { subject["fingerprint"] } == "kzbIeeMFyWBKOEP8PnWUjw=="
insist { subject.get("fingerprint") } == "kzbIeeMFyWBKOEP8PnWUjw=="
end
end

Expand All @@ -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

Expand All @@ -228,7 +228,7 @@
CONFIG

sample("field1" => "test1", "field2" => "test2") do
insist { subject["fingerprint"]} == "872da745e45192c2a1d4bf7c1ff8a370"
insist { subject.get("fingerprint")} == "872da745e45192c2a1d4bf7c1ff8a370"
end
end

Expand All @@ -243,11 +243,11 @@
CONFIG

sample("field1" => "PHP Warning: json_encode() [<a href='function.json-encode'>function.json-encode</a>]: 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

Expand All @@ -266,7 +266,7 @@
CONFIG

sample("@timestamp" => epoch_time) do
insist { subject["fingerprint"] } == '1d5379ec92d86a67cfc642d55aa050ca312d3b9a'
insist { subject.get("fingerprint") } == '1d5379ec92d86a67cfc642d55aa050ca312d3b9a'
end
end

Expand All @@ -281,7 +281,7 @@
CONFIG

sample("@timestamp" => epoch_time) do
insist { subject["fingerprint"] } == 743372282
insist { subject.get("fingerprint") } == 743372282
end
end
end
Expand Down

0 comments on commit 40ee5d7

Please sign in to comment.