diff --git a/.travis.yml b/.travis.yml index 7542e5a..f83b5e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ +--- sudo: false language: ruby cache: bundler rvm: - - jruby-1.7.24 +- jruby-1.7.25 script: bundle exec rspec spec && bundle exec rspec spec --tag integration +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/useragent.rb b/lib/logstash/filters/useragent.rb index 94ef1b3..cf817b9 100644 --- a/lib/logstash/filters/useragent.rb +++ b/lib/logstash/filters/useragent.rb @@ -93,7 +93,7 @@ def register end def filter(event) - useragent = event[@source] + useragent = event.get(@source) useragent = useragent.first if useragent.is_a?(Array) return if useragent.nil? || useragent.empty? @@ -135,7 +135,7 @@ def lookup_useragent(useragent) def set_fields(event, ua_data) # UserAgentParser outputs as US-ASCII. - event[@prefixed_name] = ua_data.name.dup.force_encoding(Encoding::UTF_8) + event.set(@prefixed_name, ua_data.name.dup.force_encoding(Encoding::UTF_8)) #OSX, Andriod and maybe iOS parse correctly, ua-agent parsing for Windows does not provide this level of detail @@ -143,23 +143,23 @@ def set_fields(event, ua_data) # and corrupt the cache. See uap source here for details https://github.com/ua-parser/uap-ruby/tree/master/lib/user_agent_parser if (os = ua_data.os) # The OS is a rich object - event[@prefixed_os] = ua_data.os.to_s.dup.force_encoding(Encoding::UTF_8) - event[@prefixed_os_name] = os.name.dup.force_encoding(Encoding::UTF_8) if os.name + event.set(@prefixed_os, ua_data.os.to_s.dup.force_encoding(Encoding::UTF_8)) + event.set(@prefixed_os_name, os.name.dup.force_encoding(Encoding::UTF_8)) if os.name # These are all strings if (os_version = os.version) - event[@prefixed_os_major] = os_version.major.dup.force_encoding(Encoding::UTF_8) if os_version.major - event[@prefixed_os_minor] = os_version.minor.dup.force_encoding(Encoding::UTF_8) if os_version.minor + event.set(@prefixed_os_major, os_version.major.dup.force_encoding(Encoding::UTF_8)) if os_version.major + event.set(@prefixed_os_minor, os_version.minor.dup.force_encoding(Encoding::UTF_8)) if os_version.minor end end - event[@prefixed_device] = ua_data.device.to_s.dup.force_encoding(Encoding::UTF_8) if ua_data.device + event.set(@prefixed_device, ua_data.device.to_s.dup.force_encoding(Encoding::UTF_8)) if ua_data.device if (ua_version = ua_data.version) - event[@prefixed_major] = ua_version.major.dup.force_encoding(Encoding::UTF_8) if ua_version.major - event[@prefixed_minor] = ua_version.minor.dup.force_encoding(Encoding::UTF_8) if ua_version.minor - event[@prefixed_patch] = ua_version.patch.dup.force_encoding(Encoding::UTF_8) if ua_version.patch - event[@prefixed_build] = ua_version.patch_minor.dup.force_encoding(Encoding::UTF_8) if ua_version.patch_minor + event.set(@prefixed_major, ua_version.major.dup.force_encoding(Encoding::UTF_8)) if ua_version.major + event.set(@prefixed_minor, ua_version.minor.dup.force_encoding(Encoding::UTF_8)) if ua_version.minor + event.set(@prefixed_patch, ua_version.patch.dup.force_encoding(Encoding::UTF_8)) if ua_version.patch + event.set(@prefixed_build, ua_version.patch_minor.dup.force_encoding(Encoding::UTF_8)) if ua_version.patch_minor end end end diff --git a/logstash-filter-useragent.gemspec b/logstash-filter-useragent.gemspec index c87ae5f..6745f2c 100644 --- a/logstash-filter-useragent.gemspec +++ b/logstash-filter-useragent.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 'user_agent_parser', ['>= 2.0.0'] s.add_runtime_dependency 'lru_redux', "~> 1.1.0" diff --git a/spec/filters/useragent_spec.rb b/spec/filters/useragent_spec.rb index 6b0f605..1b317a6 100644 --- a/spec/filters/useragent_spec.rb +++ b/spec/filters/useragent_spec.rb @@ -17,10 +17,10 @@ sample "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31" do insist { subject }.include?("ua") - insist { subject["ua"]["name"] } == "Chrome" - insist { subject["ua"]["os"] } == "Linux" - insist { subject["ua"]["major"] } == "26" - insist { subject["ua"]["minor"] } == "0" + insist { subject.get("[ua][name]") } == "Chrome" + insist { subject.get("[ua][os]") } == "Linux" + insist { subject.get("[ua][major]") } == "26" + insist { subject.get("[ua][minor]") } == "0" end end @@ -34,10 +34,10 @@ CONFIG sample "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31" do - insist { subject["name"] } == "Chrome" - insist { subject["os"] } == "Linux" - insist { subject["major"] } == "26" - insist { subject["minor"] } == "0" + insist { subject.get("name") } == "Chrome" + insist { subject.get("os") } == "Linux" + insist { subject.get("major") } == "26" + insist { subject.get("minor") } == "0" end end @@ -91,7 +91,7 @@ }.each do |field, uad_getter| context "for the #{field} field" do let(:value) {uad_getter.call(ua_data)} - let(:target_field) { target[field]} + let(:target_field) { target.get(field)} it "should not have a nil value" do expect(target_field).to be_truthy @@ -120,10 +120,10 @@ sample "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31" do insist { subject.to_hash }.include?("message") - insist { subject["message"]["name"] } == "Chrome" - insist { subject["message"]["os"] } == "Linux" - insist { subject["message"]["major"] } == "26" - insist { subject["message"]["minor"] } == "0" + insist { subject.get("[message][name]") } == "Chrome" + insist { subject.get("[message][os]") } == "Linux" + insist { subject.get("[message][major]") } == "26" + insist { subject.get("[message][minor]") } == "0" end end end