logstash-filter-device_detector 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4654c9ab2e2eb6e23f7166c5ad18eeb9af885cc33a9556a2541bb82578e9ba6
4
- data.tar.gz: 26199a2e87a7557932ecc837d13a6c063ca770cd4b2e6e0ea28be38701383ecd
3
+ metadata.gz: 8adf455a3814dc53d3fe7bbd018431feda8b9d3a11de34cbc0ace45c3c5e15de
4
+ data.tar.gz: db940ad23ff6e4af90abb03e48bb1ebc5c70885a70a93b75ff7085f65866f2f4
5
5
  SHA512:
6
- metadata.gz: f2301841fd07ee8c4b49d229d00ce49fdd66e505d6f2a0d9ed1125ae1410d50b885478da5e5a528b08fed655a1bdee0d8eb9dad984f7a73a202d4c292f8002c4
7
- data.tar.gz: 53c9c88a4adfee4cd0cb24fa8a3a82b37977074bfb84dd186ba74aa40f0b7dc3e9d6715bc8ea555ef5d8b7ffb6b0b2ed191d9df675d59b2268087afd6f4da6dd
6
+ metadata.gz: ec7c2f8289ddd07244c2eea8d5c779c9d66b33c7a7d64cf812afc71c4bf3a2fbe3e17ab4e7a64332b5f26d056a13b5cf7316e6920495b9d13d7a93a047de04f9
7
+ data.tar.gz: 21a7836272fb2e90f78ddfd994070bbeb2a4e5eed40c006c01dff06978b624ece5db156e8b861c732bff1397a732791303c8752de7be279095f2bb4ee3050205
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
1
  ## 0.1.0
2
2
  - Plugin created with the logstash plugin generator
3
+ ## 0.1.1
4
+ - 增加httpAgentJson输出
5
+ ## 0.1.2
6
+ - 处理在高版本logstash报Detected ambiguous Field Reference问题
data/README.md CHANGED
@@ -9,8 +9,10 @@
9
9
  ### 1. 插件开发环境和测试
10
10
 
11
11
  #### Code
12
+
12
13
  - 首先,您需要安装了Bundler gem的JRuby。
13
14
  - 执行下面的命令安装依赖
15
+
14
16
  ```sh
15
17
  bundle install
16
18
  ```
@@ -33,19 +35,26 @@ bundle exec rspec
33
35
 
34
36
  ### 2. 在logstash中运行未发布的插件
35
37
 
38
+ 以下方式2选一即可
39
+
36
40
  #### 2.1 直接在logstash使用克隆下来的插件代码
37
41
 
38
42
  进入logstash安装目录,一般是`/usr/share/logstash`
39
43
 
40
44
  - 编辑 `Gemfile` ,添加本地插件路径,如下所示:
45
+
41
46
  ```ruby
42
47
  gem "logstash-filter-device_detector", :path => "/path/to/logstash-filter-device-detector"
43
48
  ```
49
+
44
50
  - 安装插件
51
+
45
52
  ```sh
46
53
  bin/logstash-plugin install --no-verify
47
54
  ```
55
+
48
56
  - 运行logstash测试此插件
57
+
49
58
  ```sh
50
59
  cd /etc/logstash/conf.d
51
60
  vim test.conf
@@ -64,28 +73,28 @@ output {
64
73
  # 运行logstash
65
74
  /usr/share/logstash/bin/logstash -f test.conf
66
75
  ```
67
- 然后在屏幕输入useragent就可以看到效果了。
68
76
 
69
- #### 2.2 在logstash使用gem安装插件
77
+ 然后在屏幕输入useragent就可以看到效果了。
70
78
 
71
- You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
79
+ #### 2.2 在logstash安装构建好的gem插件
72
80
 
73
81
  - 构建gem
82
+
74
83
  ```sh
75
84
  gem build logstash-filter-device-detector.gemspec
76
85
  ```
86
+
77
87
  - 进入logstash安装目录,安装gem插件
88
+
78
89
  ```sh
79
- bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
90
+ bin/logstash-plugin install /path/to/logstash-filter-device_detector-0.1.1.gem
80
91
  ```
81
- - Start Logstash and proceed to test the plugin
82
92
 
83
- ## Contributing
93
+ ## 安装在线插件
84
94
 
85
- All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
95
+ ```sh
96
+ bin/logstash-plugin install logstash-filter-device_detector
97
+ ```
86
98
 
87
- Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
88
99
 
89
- It is more important to the community that you are able to contribute.
90
100
 
91
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -53,11 +53,16 @@ class LogStash::Filters::DeviceDetector < LogStash::Filters::Base
53
53
  mozilla = false
54
54
  model = true
55
55
  platform = "Other"
56
- os = "Other"
56
+ os_full = "Other"
57
57
  engine = ""
58
58
  engine_version = ""
59
59
  browser = ""
60
60
  browser_version = ""
61
+ browser_full = ""
62
+ os_name = ""
63
+ os_version = ""
64
+ device_name = ""
65
+ device_brand = ""
61
66
 
62
67
  if data.device_type =~ /phone/
63
68
  is_mobile = true
@@ -70,18 +75,43 @@ class LogStash::Filters::DeviceDetector < LogStash::Filters::Base
70
75
  if data.device_type
71
76
  platform = data.device_type
72
77
  end
73
- if data.os_full_version
74
- os = "#{data.os_name} #{data.os_full_version}"
78
+ if data.device_brand
79
+ device_brand = data.device_brand
75
80
  end
76
- if data.name
77
- browser = data.name
78
- if data.name =~ /irefox/
79
- mozilla = true
81
+ if data.device_name
82
+ device_name = data.device_name
83
+ end
84
+ if data.os_name && data.os_full_version
85
+ os_name = data.os_name
86
+ os_version = data.os_full_version
87
+ os_full = "#{os_name} #{os_version}"
88
+ else
89
+ if data.os_name
90
+ os_name = data.os_name
91
+ os_full = os_name
92
+ end
93
+ if data.os_full_version
94
+ os_version = data.os_full_version
80
95
  end
81
96
  end
82
- if data.full_version
97
+
98
+ if data.name && data.full_version
99
+ browser = data.name
83
100
  browser_version = data.full_version
101
+ browser_full = "#{browser},#{browser_version}"
102
+ else
103
+ if data.name
104
+ browser = data.name
105
+ browser_full = browser
106
+ end
107
+ if data.full_version
108
+ browser_version = data.full_version
109
+ end
110
+ end
111
+ if browser =~ /firefox/i
112
+ mozilla = true
84
113
  end
114
+
85
115
  # 构造输出哈希表
86
116
  output = {
87
117
  "isMobile" => is_mobile,
@@ -89,25 +119,35 @@ class LogStash::Filters::DeviceDetector < LogStash::Filters::Base
89
119
  "mozilla" => mozilla,
90
120
  "model" => model,
91
121
  "platform" => platform,
92
- "os" => os,
122
+ "os" => os_full,
93
123
  "engine" => engine,
94
124
  "engineVersion" => engine_version,
95
125
  "browser" => browser,
96
126
  "browserVersion" => browser_version
97
127
  }
128
+ target_hash = {
129
+ "browser" => {
130
+ "name" => browser,
131
+ "version" =>browser_version
132
+ },
133
+ "os" => {
134
+ "name" => os_name,
135
+ "version" => os_version
136
+ },
137
+ "device" => {
138
+ "name" => device_name,
139
+ "brand" => device_brand,
140
+ "type" => platform
141
+ }
142
+ }
143
+ if is_bot
144
+ target_hash['bot_name'] = spider
145
+ end
98
146
  event.set("httpUserAgentJson", output.to_json)
99
- event.set("os", os)
100
- event.set("browser", "#{browser},#{browser_version}")
147
+ event.set("os", os_full)
148
+ event.set("browser", browser_full)
101
149
  event.set("spider", spider)
102
- event.set("#{@target}[browser][name]", data.name) if data.name
103
- event.set("#{@target}[browser][version]", data.full_version) if data.full_version
104
- event.set("#{@target}[os][name]", data.os_name) if data.os_name
105
- event.set("#{@target}[os][version]", data.os_full_version) if data.os_full_version
106
- event.set("#{@target}[device][name]", data.device_name) if data.device_name
107
- event.set("#{@target}[device][brand]", data.device_brand) if data.device_brand
108
- event.set("#{@target}[device][type]", data.device_type) if data.device_type
109
- event.set("#{@target}[bot][name]", data.bot_name) if data.bot_name
110
- event.set("#{@target}[bot][name]", data.bot_name) if data.bot_name
150
+ event.set("#{@target}", target_hash)
111
151
  rescue StandardError => e
112
152
  @logger.error("Uknown error while setting device data", :exception => e, :field => @source, :event => event)
113
153
  return
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-device_detector'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = '使用device_detector解析useragent的logstash-filter插件.'
6
6
  s.description = 'Detects a vast amount of different devices automaticly based on regex rules.'
@@ -7,8 +7,8 @@ describe LogStash::Filters::DeviceDetector do
7
7
  let(:config) do <<-CONFIG
8
8
  filter {
9
9
  device_detector {
10
- source => "useragent"
11
- target => "device_detector"
10
+ source => "http_user_agent"
11
+ target => "ua"
12
12
  }
13
13
  }
14
14
  CONFIG
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-device_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dukang