Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Add convenience fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
thdls55 committed Feb 16, 2017
1 parent 1e5360c commit 6bb58fc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/logstash/filters/handsetdetection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 6bb58fc

Please sign in to comment.