diff --git a/lib/logstash/filters/handsetdetection.rb b/lib/logstash/filters/handsetdetection.rb index 62dff13..b833f9b 100644 --- a/lib/logstash/filters/handsetdetection.rb +++ b/lib/logstash/filters/handsetdetection.rb @@ -117,6 +117,7 @@ def filter(event) event.set '[handset_detection][message]', r['message'] end if r.key? 'hd_specs' + r['hd_specs'] = add_convenience_fields r['hd_specs'] if @filter.empty? event.set '[handset_detection][specs]', r['hd_specs'] else @@ -134,4 +135,24 @@ def filter(event) end filter_matched event end + + def add_convenience_fields(specs) + unless specs.key? 'general_device_name' + if specs.key? 'general_aliases' and specs['general_aliases'].is_a? Array and specs['general_aliases'].count > 0 + specs['general_device_name'] = specs['general_aliases'][0].strip + else + specs['general_device_name'] = "#{specs.fetch('general_vendor', '')} #{specs.fetch('general_model', '')}".strip + end + end + unless specs.key? 'general_platform_name' + specs['general_platform_name'] = "#{specs.fetch('general_platform', '')} #{specs.fetch('general_platform_version', '')}".strip + end + unless specs.key? 'general_browser_name' + specs['general_browser_name'] = "#{specs.fetch('general_browser', '')} #{specs.fetch('general_browser_version', '')}".strip + end + unless specs.key? 'general_app_name' + specs['general_app_name'] = "#{specs.fetch('general_app', '')} #{specs.fetch('general_app_version', '')}".strip + end + specs + end end diff --git a/logstash-filter-handsetdetection.gemspec b/logstash-filter-handsetdetection.gemspec index 15bbda6..a94a47a 100644 --- a/logstash-filter-handsetdetection.gemspec +++ b/logstash-filter-handsetdetection.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'logstash-filter-handsetdetection' - s.version = '4.1.6' + s.version = '4.1.7' s.licenses = ['MIT'] s.summary = "Handset Detection filter plugin for Logstash" s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"