diff --git a/lib/logstash/filters/handsetdetection.rb b/lib/logstash/filters/handsetdetection.rb index c5e4d4f..40ecc2f 100644 --- a/lib/logstash/filters/handsetdetection.rb +++ b/lib/logstash/filters/handsetdetection.rb @@ -1,9 +1,33 @@ -# encoding: utf-8 +#-- +# Copyright (c) Richard Uren 2016 +# All Rights Reserved +# +# LICENSE: Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: Redistributions of source code must retain the +# above copyright notice, this list of conditions and the following +# disclaimer. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN +# NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +# DAMAGE. +#++ + require 'logstash/filters/base' require 'logstash/namespace' require 'handset_detection' - class LogStash::Filters::HandsetDetection < LogStash::Filters::Base config_name 'handsetdetection' @@ -45,13 +69,14 @@ def register @hd_config['log_unknown'] = true @hd_config['local_archive_source'] = @local_archive_source + @@pool = [] unless @online_api hd = HD4.new @hd_config hd.set_timeout 500 hd.device_fetch_archive hd.set_timeout 30 + @@pool << hd end - @pool = [ hd ] end public @@ -62,11 +87,11 @@ def filter(event) data[dest] = event[src] end end - hd = @pool.pop + hd = @@pool.pop hd = HD4.new @hd_config if hd.nil? hd.device_detect data r = hd.get_reply - @pool << hd + @@pool << hd if r.key? 'class' event['handset_class'] = r['class'] end diff --git a/logstash-filter-handsetdetection.gemspec b/logstash-filter-handsetdetection.gemspec index bc6b35c..7a755da 100644 --- a/logstash-filter-handsetdetection.gemspec +++ b/logstash-filter-handsetdetection.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| # Gem dependencies s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0" s.add_runtime_dependency "json", "~> 1.8" - s.add_runtime_dependency "handset_detection", "~> 0.1", ">= 0.1.7" + s.add_runtime_dependency "handset_detection", "~> 0.1", ">= 0.1.8" #s.add_development_dependency 'logstash-devutils' end