Class: LogStash::Filters::DeviceDetection
- Inherits:
-
Base
- Object
- Base
- LogStash::Filters::DeviceDetection
- Defined in:
- lib/logstash/filters/device_detection.rb
Overview
- NOTE
-
– This product includes Device Detection data created by 51Degrees, available from 51degrees.com/. This database is licensed under www.mozilla.org/MPL/2.0/[Mozilla Public License 2]. –
Instance Method Summary collapse
Instance Method Details
#apply_match(match, event) ⇒ Object
def filter
91 92 93 94 95 96 97 98 |
# File 'lib/logstash/filters/device_detection.rb', line 91 def apply_match(match, event) @properties.each do |property| field = "[#{@target}][#{property}]" value = match.getValues(property) event.set(field, value.toString()) if value end true end |
#filter(event) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/logstash/filters/device_detection.rb', line 67 def filter(event) begin begin match = @provider.match(event.get(@source)) rescue StandardError => e @logger.error("Error while parsing user agent data", :exception => e, :field => @source, :event => event) return end return unless match apply_match(match, event) #event.set(@target, match.getValues("IsMobile").toString()) rescue Exception=>e @logger.error("Failed to detect device", :exception => e, :field => @source) end # filter_matched should go in the last line of our successful code filter_matched(event) end |
#register ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/logstash/filters/device_detection.rb', line 42 def register if @datafile.nil? @datafile = ::Dir.glob(::File.("../../../vendor/", ::File.dirname(__FILE__))+"/51Degrees-LiteV3.2.dat").first if @datafile.nil? || !::File.exists?(@datafile) raise "You must specify 'datafile => ...' in your device_detection filter (currently is set to '#{@datafile}')" end end if @properties.nil? || @properties.empty? raise "An array of device properties must not be empty." end begin dataset = Java::FiftyoneMobileDetectionFactories::StreamFactory.create(@datafile, false) @provider = Java::FiftyoneMobileDetection::Provider.new(dataset, @cache_size) rescue StandardError => e @logger.error("Error while initializing device detection provider object", :exception => e) return end end |