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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3cc9ccf5e8a0bd317bc5728a5866e398913569b
4
- data.tar.gz: ce935a8c184a51ba89eebf48851ce33c441188e8
3
+ metadata.gz: ce29ef6d804ade6ca4e6d5eb39d74a0506ffdc79
4
+ data.tar.gz: 4194a0b3f618d69a50b64d5c2d3c29d2331f9b10
5
5
  SHA512:
6
- metadata.gz: 074dc87359695fbecc555422800d6f48b996587c968a324d9ab1e65a51fa4155b60cb1a6e0236c575fb89e9c0558b253c72a26daaf99fe3ade148872c351f685
7
- data.tar.gz: 6665995e6ab6ac36c740801e0eadb3928e8e5aeacd1ef3fb81ad67d729da0749964256c5f69dca8fef082d3700865fc3767485608fd17f6ddf18d09470b322fd
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
- map new_record["new_foo"] = record["foo"]; new_record["new_bar"] = record["bar"]
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
- map new_record["new_foo"] = record["foo"].upcase; new_record["new_bar"] = record["bar"].upcase
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
- map record.each {|k, v| new_record[k] = k + "." + v }
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
- map new_record = {"new_foo" => record["foo"]}
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
- map new_record["tag"] = tag; new_record["new_foo"] = tag_parts[1] + "." + record["foo"]
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
- eval(@map, bind)
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
@@ -1,3 +1,3 @@
1
1
  module FluentPluginFilterSimpleMap
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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.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-12 00:00:00.000000000 Z
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd