logstash-filter-device_detector 0.1.1 → 0.1.2
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +19 -10
- data/lib/logstash/filters/device_detector.rb +60 -20
- data/logstash-filter-device-detector.gemspec +1 -1
- data/spec/filters/device_detector_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8adf455a3814dc53d3fe7bbd018431feda8b9d3a11de34cbc0ace45c3c5e15de
|
4
|
+
data.tar.gz: db940ad23ff6e4af90abb03e48bb1ebc5c70885a70a93b75ff7085f65866f2f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec7c2f8289ddd07244c2eea8d5c779c9d66b33c7a7d64cf812afc71c4bf3a2fbe3e17ab4e7a64332b5f26d056a13b5cf7316e6920495b9d13d7a93a047de04f9
|
7
|
+
data.tar.gz: 21a7836272fb2e90f78ddfd994070bbeb2a4e5eed40c006c01dff06978b624ece5db156e8b861c732bff1397a732791303c8752de7be279095f2bb4ee3050205
|
data/CHANGELOG.md
CHANGED
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
|
-
|
77
|
+
然后在屏幕输入useragent就可以看到效果了。
|
70
78
|
|
71
|
-
|
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 /
|
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
|
-
##
|
93
|
+
## 安装在线插件
|
84
94
|
|
85
|
-
|
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
|
-
|
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.
|
74
|
-
|
78
|
+
if data.device_brand
|
79
|
+
device_brand = data.device_brand
|
75
80
|
end
|
76
|
-
if data.
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
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" =>
|
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",
|
100
|
-
event.set("browser",
|
147
|
+
event.set("os", os_full)
|
148
|
+
event.set("browser", browser_full)
|
101
149
|
event.set("spider", spider)
|
102
|
-
event.set("#{@target}
|
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.
|
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.'
|