logstash-filter-handsetdetection 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 355ab24a36f7946ff03d4ea424fcb26c18026858
4
+ data.tar.gz: a636e46a1f4f4dd9f565cc3b90015447e0c68134
5
+ SHA512:
6
+ metadata.gz: 287afeb9918f7ff15664437662a5952dd698449ad4676f536cd17c4a4fd2e08a33faff2296d1f07085de3a533fa9e0205e6224d583474eb1bc4edafdba0b816f
7
+ data.tar.gz: 4339bf074c5abe6fcfa0dec97d036373713b2b2314c1abfc7cb3c5784080fef92ddf1dbe88fb399924ccf334bd00f08df00f9acb423048bacc2da530bafae4ba
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 Handset Detection <http://www.handsetdetection.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ [![Build Status](https://travis-ci.org/HandsetDetection/logstash-filter-handsetdetection.svg?branch=master)](https://travis-ci.org/HandsetDetection/logstash-filter-handsetdetection)
2
+ [![Gem Version](https://badge.fury.io/rb/handset_detection.svg)](https://badge.fury.io/rb/handset_detection)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+
5
+ # Handset Detection for Logstash
6
+
7
+ This is the [Handset Detection](http://www.handsetdetection.com/) plugin for [Logstash](https://github.com/elastic/logstash).
8
+
9
+ ## Example
10
+
11
+ Extract the User-Agent header from an Apache log with Grok, and then enrich the log with Headset Detection data:
12
+
13
+ ```
14
+ filter {
15
+ grok {
16
+ match => {
17
+ "message" => "%{COMBINEDAPACHELOG}"
18
+ }
19
+ }
20
+ handsetdetection {
21
+ username => "xxxxxxxxxx"
22
+ password => "xxxxxxxxxxxxxxxx"
23
+ site_id => 000000
24
+ online_api => false
25
+ match => {
26
+ "agent" => "user-agent"
27
+ }
28
+ filter => [
29
+ "general_vendor", "general_model", "general_type"
30
+ ]
31
+ }
32
+ }
33
+ ```
34
+
35
+ ## Configuration Fields
36
+
37
+ | Field | Description | Default |
38
+ | --- | --- | --- |
39
+ | `online_api` | Set to `true` in order to do **online** lookups against the Handset Detection API | `false` |
40
+ | `username` | Your Handset Detection API username | |
41
+ | `password` | Your Handset Detection API password | |
42
+ | `site_id` | The Handset Detection API site ID to use | |
43
+ | `match` | An associative array mapping input field names to header names used for handset detection. For example: Extract the `user-agent` header from the `agent` input field. | `{ "agent" => "user-agent" }` |
44
+ | `filter` | Optionally, define an array of the handset spec properties to be included in the output. By default, all properties are included in the output. | [] |
45
+ | `use_proxy` | Set to `true` if accessing the web through a proxy | `false` |
46
+ | `proxy_server` | The proxy server address, if using a proxy ||
47
+ | `proxy_port` | The proxy server port, if using a proxy ||
48
+ | `proxy_user` | Your proxy server username, if authenticating to a proxy ||
49
+ | `proxy_password` | Your proxy server password, if authenticating to a proxy ||
50
+
51
+ ## Installation
52
+
53
+ ```
54
+ # Logstash 2.3 and higher
55
+ bin/logstash-plugin install logstash-filter-handsetdetection-1.1.0.gem
56
+
57
+ # Prior to Logstash 2.3
58
+ bin/plugin install logstash-filter-handsetdetection-1.1.0.gem
59
+ ```
60
+
61
+ ## Building from source
62
+
63
+ ```
64
+ gem build logstash-filter-handsetdetection.gemspec
65
+ ```
@@ -0,0 +1,112 @@
1
+ #--
2
+ # Copyright (c) Richard Uren 2016 <richard@teleport.com.au>
3
+ # All Rights Reserved
4
+ #
5
+ # LICENSE: Redistribution and use in source and binary forms, with or
6
+ # without modification, are permitted provided that the following
7
+ # conditions are met: Redistributions of source code must retain the
8
+ # above copyright notice, this list of conditions and the following
9
+ # disclaimer. Redistributions in binary form must reproduce the above
10
+ # copyright notice, this list of conditions and the following disclaimer
11
+ # in the documentation and/or other materials provided with the
12
+ # distribution.
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
15
+ # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
+ # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17
+ # NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
20
+ # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
22
+ # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23
+ # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
24
+ # DAMAGE.
25
+ #++
26
+
27
+ require 'logstash/filters/base'
28
+ require 'logstash/namespace'
29
+ require 'handset_detection'
30
+
31
+ class LogStash::Filters::HandsetDetection < LogStash::Filters::Base
32
+
33
+ config_name 'handsetdetection'
34
+
35
+ config :online_api, :validate => :boolean, :default => false
36
+ config :username, :validate => :string, :default => ''
37
+ config :password, :validate => :string, :default => ''
38
+ config :site_id, :validate => :number, :default => 0
39
+ config :apiserver, :validate => :string, :default => 'api.handsetdetection.com'
40
+ config :match, :validate => :hash, :default => { 'agent' => 'user-agent' }
41
+ config :filter, :validate => :array, :default => []
42
+ config :use_proxy, :validate => :boolean, :default => false
43
+ config :proxy_server, :validate => :string, :default => ''
44
+ config :proxy_port, :validate => :number, :default => 3128
45
+ config :proxy_user, :validate => :string, :default => ''
46
+ config :proxy_pass, :validate => :string, :default => ''
47
+ config :local_archive_source, :validate => :string, :default => nil
48
+
49
+ public
50
+ def register
51
+ @hd_config = {}
52
+ @hd_config['username'] = @username
53
+ @hd_config['secret'] = @password
54
+ @hd_config['site_id'] = @site_id
55
+ @hd_config['use_local'] = @online_api ? false : true
56
+ @hd_config['filesdir'] = '/tmp'
57
+ @hd_config['cache'] = {'none' => {}}
58
+ @hd_config['debug'] = false
59
+ @hd_config['api_server'] = @apiserver
60
+ @hd_config['cache_requests'] = false
61
+ @hd_config['geoip'] = true
62
+ @hd_config['timeout'] = 30
63
+ @hd_config['use_proxy'] = @use_proxy
64
+ @hd_config['proxy_server'] = @proxy_server
65
+ @hd_config['proxy_port'] = @proxy_port
66
+ @hd_config['proxy_user'] = @proxy_user
67
+ @hd_config['proxy_pass'] = @proxy_pass
68
+ @hd_config['retries'] = 3
69
+ @hd_config['log_unknown'] = true
70
+ @hd_config['local_archive_source'] = @local_archive_source
71
+
72
+ @@pool = []
73
+ unless @online_api
74
+ hd = HD4.new @hd_config
75
+ hd.set_timeout 500
76
+ hd.device_fetch_archive
77
+ hd.set_timeout 30
78
+ @@pool << hd
79
+ end
80
+ end
81
+
82
+ public
83
+ def filter(event)
84
+ data = {}
85
+ @match.each do |src, dest|
86
+ if event.include? src
87
+ data[dest] = event[src]
88
+ end
89
+ end
90
+ hd = @@pool.pop
91
+ hd = HD4.new @hd_config if hd.nil?
92
+ hd.device_detect data
93
+ r = hd.get_reply
94
+ @@pool << hd
95
+ if r.key? 'class'
96
+ event['handset_class'] = r['class']
97
+ end
98
+ if r.key? 'hd_specs'
99
+ if @filter.empty?
100
+ event['handset_specs'] = r['hd_specs']
101
+ else
102
+ event['handset_specs'] = {}
103
+ @filter.each do |f|
104
+ if r['hd_specs'].key? f
105
+ event['handset_specs'][f] = r['hd_specs'][f]
106
+ end
107
+ end
108
+ end
109
+ end
110
+ filter_matched event
111
+ end
112
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-handsetdetection'
3
+ s.version = '4.1.1'
4
+ s.licenses = ['MIT']
5
+ s.summary = "Handset Detection filter plugin for Logstash"
6
+ 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"
7
+ s.authors = ["Handset Detection"]
8
+ s.email = 'hello@handsetdetection.com'
9
+ s.homepage = "http://www.handsetdetection.com/"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
22
+ s.add_runtime_dependency "json", "~> 1.8"
23
+ s.add_runtime_dependency "handset_detection", "~> 4.1"
24
+
25
+ #s.add_development_dependency 'logstash-devutils'
26
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require "logstash/filters/handsetdetection"
4
+
5
+ describe LogStash::Filters::Example do
6
+ describe "Simple detection" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ handsetdetection {
10
+ }
11
+ }
12
+ CONFIG
13
+ end
14
+
15
+ sample("agent" => "Nokia6085/2.0 (06.00) Profile/MIDP-2.0 Configuration/CLDC-1.1 nokia6085/UC Browser7.9.0.102/69/352 UNTRUSTED/1.0",) do
16
+ expect(subject).to include("handset_specs")
17
+ expect(subject["handset_specs"]["general_vendor"]).to eq("Nokia")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-handsetdetection
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Handset Detection
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 2.0.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '1.8'
39
+ name: json
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.8'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '4.1'
53
+ name: handset_detection
54
+ prerelease: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '4.1'
61
+ 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
62
+ email: hello@handsetdetection.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - lib/logstash/filters/handsetdetection.rb
71
+ - logstash-filter-handsetdetection.gemspec
72
+ - spec/filters/handsetdetection_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: http://www.handsetdetection.com/
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ logstash_plugin: 'true'
79
+ logstash_group: filter
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Handset Detection filter plugin for Logstash
100
+ test_files:
101
+ - spec/filters/handsetdetection_spec.rb
102
+ - spec/spec_helper.rb