fluent-plugin-ua-parser 0.2.2 → 0.3.0
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/README.md +36 -1
- data/fluent-plugin-ua-parser.gemspec +1 -1
- data/lib/fluent/plugin/filter_ua_parser.rb +20 -2
- data/test/plugin/test_filter_ua_parser.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 798fd3a07e20680afeb795bce63afd87c1d0ea50
|
4
|
+
data.tar.gz: a254e9205acd22070d3ddbd8cfeab569dd0afaf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef90a396baadafd69ca1e5743980b8e5b5c0a99ba0b296dab16d0e90b1052a68dcce69cb4ec2fa968ef7a7fbe5d59d380f6e223d7510e005e9108b06dcbd6e2f
|
7
|
+
data.tar.gz: f2a5211d157b3f754d64e3ffaa8f1f62a0c95ad8620a77c6185ec5e7e310e0da9e99e9685f61a95981e45c57bb7255b0b77842db6d003832e98e7b6ae6ceb079
|
data/README.md
CHANGED
@@ -112,6 +112,38 @@ access.apache: {
|
|
112
112
|
}
|
113
113
|
```
|
114
114
|
|
115
|
+
### Example 3:
|
116
|
+
|
117
|
+
```xml
|
118
|
+
<filter access.apache.**>
|
119
|
+
@type ua_parser
|
120
|
+
key_name ua_string
|
121
|
+
flatten
|
122
|
+
</filter>
|
123
|
+
```
|
124
|
+
|
125
|
+
Assuming following inputs are coming:
|
126
|
+
|
127
|
+
```json
|
128
|
+
access.apache: {
|
129
|
+
"ua_string":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7"
|
130
|
+
}
|
131
|
+
```
|
132
|
+
|
133
|
+
then output bocomes as belows:
|
134
|
+
|
135
|
+
```json
|
136
|
+
access.apache: {
|
137
|
+
"ua_string":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7",
|
138
|
+
"ua_browser_family":"Safari",
|
139
|
+
"ua_browser_version":"9.0.1",
|
140
|
+
"ua_browser_major_version":9,
|
141
|
+
"ua_os_family":"Mac OS X",
|
142
|
+
"ua_os_version":"10.11.1",
|
143
|
+
"ua_os_major_version":10,
|
144
|
+
"ua_device":"Other"
|
145
|
+
}
|
146
|
+
```
|
115
147
|
|
116
148
|
|
117
149
|
## Parameters
|
@@ -132,10 +164,13 @@ access.apache: {
|
|
132
164
|
Patterns file(regexes.yaml) path.
|
133
165
|
Get from [uap-core](https://github.com/ua-parser/uap-core)
|
134
166
|
|
167
|
+
- flatten *bool*
|
168
|
+
join hashed data by '_'. default false.
|
169
|
+
|
135
170
|
|
136
171
|
## TODO
|
137
172
|
|
138
|
-
*
|
173
|
+
* patches welcome!
|
139
174
|
|
140
175
|
|
141
176
|
## Contributing
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-ua-parser"
|
7
|
-
spec.version = "0.
|
7
|
+
spec.version = "0.3.0"
|
8
8
|
spec.authors = ["Yuri Umezaki"]
|
9
9
|
spec.email = ["bungoume@gmail.com"]
|
10
10
|
spec.homepage = "https://github.com/bungoume/fluent-plugin-ua-parser"
|
@@ -13,7 +13,7 @@ module Fluent
|
|
13
13
|
config_param :key_name, :string, :default => 'user_agent'
|
14
14
|
config_param :delete_key, :bool, :default => false
|
15
15
|
config_param :out_key, :string, :default => 'ua'
|
16
|
-
|
16
|
+
config_param :flatten, :bool, :default => false
|
17
17
|
config_param :patterns_path, :string, :default => nil
|
18
18
|
|
19
19
|
def configure(conf)
|
@@ -32,7 +32,11 @@ module Fluent
|
|
32
32
|
record.delete(@key_name) if @delete_key
|
33
33
|
unless ua_string.nil?
|
34
34
|
user_agent_detail = @ua_cache.getset(ua_string) { get_ua_detail(ua_string) }
|
35
|
-
|
35
|
+
if flatten
|
36
|
+
record.merge! hash_flatten(user_agent_detail, [@out_key])
|
37
|
+
else
|
38
|
+
record[@out_key] = user_agent_detail
|
39
|
+
end
|
36
40
|
end
|
37
41
|
record
|
38
42
|
end
|
@@ -52,5 +56,19 @@ module Fluent
|
|
52
56
|
data['device'] = ua.device.to_s
|
53
57
|
data
|
54
58
|
end
|
59
|
+
|
60
|
+
def hash_flatten(a, keys=[])
|
61
|
+
ret = {}
|
62
|
+
a.each{|k,v|
|
63
|
+
ks = keys + [k]
|
64
|
+
if v.class == Hash
|
65
|
+
ret.merge!(hash_flatten(v, ks))
|
66
|
+
else
|
67
|
+
ret.merge!({ks.join('_')=> v})
|
68
|
+
end
|
69
|
+
}
|
70
|
+
ret
|
71
|
+
end
|
72
|
+
|
55
73
|
end if defined?(Filter) # Support only >= v0.12
|
56
74
|
end
|
@@ -41,4 +41,26 @@ class UaParserFilterTest < Test::Unit::TestCase
|
|
41
41
|
assert_equal 'Other', ua_object['device']
|
42
42
|
end
|
43
43
|
|
44
|
+
def test_emit_flatten
|
45
|
+
d1 = d1 = create_driver(%[
|
46
|
+
type ua_parser
|
47
|
+
flatten
|
48
|
+
], 'test')
|
49
|
+
ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36'
|
50
|
+
|
51
|
+
d1.run do
|
52
|
+
d1.emit({'user_agent' => ua})
|
53
|
+
end
|
54
|
+
emits = d1.emits
|
55
|
+
assert_equal 1, emits.length
|
56
|
+
assert_equal 'test', emits[0][0] # tag
|
57
|
+
ua_object = emits[0][2]
|
58
|
+
assert_equal 'Chrome', ua_object['ua_browser_family']
|
59
|
+
assert_equal 46, ua_object['ua_browser_major_version']
|
60
|
+
assert_equal '46.0.2490', ua_object['ua_browser_version']
|
61
|
+
assert_equal 'Windows 7', ua_object['ua_os_family']
|
62
|
+
assert_equal '', ua_object['ua_os_version']
|
63
|
+
assert_equal 'Other', ua_object['ua_device']
|
64
|
+
end
|
65
|
+
|
44
66
|
end
|