fluent-plugin-filter-record-map 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 +4 -4
- data/README.md +23 -5
- data/lib/fluent/plugin/filter_record_map.rb +23 -6
- data/lib/fluent_plugin_filter_record_map/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce29ef6d804ade6ca4e6d5eb39d74a0506ffdc79
|
4
|
+
data.tar.gz: 4194a0b3f618d69a50b64d5c2d3c29d2331f9b10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ce0e805718845d26fdea057520868a9bf0431978c2a5f76af6082b54ac7809449b444c96821e0af96356b96f011b352c37583a250c2815b46e6b77d5f2c8ecd
|
7
|
+
data.tar.gz: 5115736f7a6ebbff65108e885b11ee5110a1f1881a79816eb259cc25395bfce567171a198388a77ff9914a3460de548a8b188352d82d017cfd930b98c38e9175
|
data/README.md
CHANGED
@@ -26,7 +26,9 @@ Or install it yourself as:
|
|
26
26
|
```apache
|
27
27
|
<filter>
|
28
28
|
type record_map
|
29
|
-
|
29
|
+
# map1: required
|
30
|
+
map1 new_record["new_foo"] = record["foo"]
|
31
|
+
map2 new_record["new_bar"] = record["bar"]
|
30
32
|
</filter>
|
31
33
|
```
|
32
34
|
|
@@ -37,7 +39,8 @@ Or install it yourself as:
|
|
37
39
|
```apache
|
38
40
|
<filter>
|
39
41
|
type record_map
|
40
|
-
|
42
|
+
map1 new_record["new_foo"] = record["foo"].upcase
|
43
|
+
map2 new_record["new_bar"] = record["bar"].upcase
|
41
44
|
</filter>
|
42
45
|
```
|
43
46
|
|
@@ -51,7 +54,7 @@ $ echo '{"foo":"bar", "bar":"zoo"})' | fluentd test.data
|
|
51
54
|
```apache
|
52
55
|
<filter>
|
53
56
|
type record_map
|
54
|
-
|
57
|
+
map1 record.each {|k, v| new_record[k] = k + "." + v }
|
55
58
|
</filter>
|
56
59
|
```
|
57
60
|
|
@@ -65,7 +68,7 @@ $ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
|
|
65
68
|
```apache
|
66
69
|
<filter>
|
67
70
|
type record_map
|
68
|
-
|
71
|
+
map1 new_record = {"new_foo" => record["foo"]}
|
69
72
|
</filter>
|
70
73
|
```
|
71
74
|
|
@@ -79,7 +82,8 @@ $ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
|
|
79
82
|
```apache
|
80
83
|
<filter>
|
81
84
|
type record_map
|
82
|
-
|
85
|
+
map1 new_record["tag"] = tag
|
86
|
+
map2 new_record["new_foo"] = tag_parts[1] + "." + record["foo"]
|
83
87
|
</filter>
|
84
88
|
```
|
85
89
|
|
@@ -87,3 +91,17 @@ $ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
|
|
87
91
|
$ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
|
88
92
|
#=> 2015-01-01 23:34:45 +0900 test.data: {"tag":"test.data","new_foo":"data.foo"}
|
89
93
|
```
|
94
|
+
|
95
|
+
### Use `hostname`
|
96
|
+
|
97
|
+
```apache
|
98
|
+
<filter>
|
99
|
+
type record_map
|
100
|
+
map1 new_record["hostname"] = hostname
|
101
|
+
</filter>
|
102
|
+
```
|
103
|
+
|
104
|
+
```sh
|
105
|
+
$ echo '{"foo":"bar", "bar":"zoo"}' | fluent-cat test.data
|
106
|
+
#=> 2015-01-01 23:34:45 +0900 test.data: {"hostname":"my-host"}
|
107
|
+
```
|
@@ -1,27 +1,44 @@
|
|
1
1
|
require 'fluent_plugin_filter_record_map/version'
|
2
|
+
require 'socket'
|
2
3
|
|
3
4
|
module Fluent
|
4
5
|
class RecordMapFilter < Filter
|
6
|
+
Plugin.register_filter('record_map', self)
|
7
|
+
|
8
|
+
PARAM_INDICES = 1..9
|
9
|
+
|
10
|
+
PARAM_INDICES.each do |i|
|
11
|
+
options = (i == 1) ? {} : {:default => nil}
|
12
|
+
config_param :"map#{i}", :string, options
|
13
|
+
end
|
14
|
+
|
5
15
|
class Context
|
6
16
|
def context(tag, record)
|
7
17
|
tag_parts = tag.split('.')
|
18
|
+
hostname = Socket.gethostname
|
8
19
|
new_record = {}
|
9
20
|
binding
|
10
21
|
end
|
11
|
-
end
|
12
|
-
|
13
|
-
Plugin.register_filter('record_map', self)
|
14
|
-
|
15
|
-
config_param :map, :string
|
22
|
+
end # Context
|
16
23
|
|
17
24
|
def configure(conf)
|
18
25
|
super
|
19
26
|
@context = Context.new
|
27
|
+
@maps = []
|
28
|
+
|
29
|
+
PARAM_INDICES.each do |i|
|
30
|
+
expr = instance_variable_get("@map#{i}")
|
31
|
+
@maps << expr if expr
|
32
|
+
end
|
20
33
|
end
|
21
34
|
|
22
35
|
def filter(tag, time, record)
|
23
36
|
bind = @context.context(tag, record)
|
24
|
-
|
37
|
+
|
38
|
+
@maps.each do |expr|
|
39
|
+
eval(expr, bind)
|
40
|
+
end
|
41
|
+
|
25
42
|
eval('new_record', bind)
|
26
43
|
end
|
27
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-filter-record-map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|