fluent-plugin-burrow 1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79b17469b72f5d09f0bc84ef8471a934cba254db
4
- data.tar.gz: c91601ac6a9d7f8368aa39e79d7f12cf26418d9b
3
+ metadata.gz: 15a9ff282bcacf54d1aa7c6a1fa1cfd59238b5a6
4
+ data.tar.gz: 9495741eaa5f261773e1fbd7d68b43f6fd360e84
5
5
  SHA512:
6
- metadata.gz: 8bec4b6f3f963915ad55ac28cbc20143ea346d442bc22402cb513ca2b5a40cc4b03c5619c9afc7edf03eb25690f505cb1b63455b51c8db921f3bbe596b5120c0
7
- data.tar.gz: 423673c8e99d563a7b3ebdf49d4e389597b195d42167ab03180ed59f60d83af7dc6f9d00ad07a67849638c77fde68dfef5cd6d8811c3d3f6f68b5e0e757ce349
6
+ metadata.gz: 8ba386ea6ca214ea20c4b94a88b3c609c1839cf150ea85a570847351c65afb7a5ea2e61485e75620ca74bab0dd6146b78dde272223a44e0520dae4a6805eac6b
7
+ data.tar.gz: 1c5b33f9c93a27bfedc16952228de175fedf13a090cd29cb217a565c9186b546335c842b78b19e9a797191c54478f4dbc65840414d07081e2eef06cfe19058b3
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
- vendor/*
5
+ vendor/*
6
+ .DS_Store
@@ -4,7 +4,7 @@ $:.push File.expand_path("../lib", __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-burrow"
6
6
  s.description = "Extract a single key (in formats Fluent can natively understand) from an event and re-emit a new event that replaces the entire original record with that key's values."
7
- s.version = "1.1"
7
+ s.version = "1.2"
8
8
  s.license = "MIT"
9
9
  s.authors = ["Tim Gunter"]
10
10
  s.email = ["tim@vanillaforums.com"]
@@ -0,0 +1,106 @@
1
+ # Burrow Filter Plugin
2
+ # @author Tim Gunter <tim@vanillaforums.com>
3
+ #
4
+ # This plugin allows to extract a single key from an existing event and re-parse it with a given
5
+ # format, and then re-emit a new event with the key's value replaced, or with the whole record replaced.
6
+ #
7
+
8
+ require 'fluent/filter'
9
+
10
+ module Fluent
11
+ class BurrowFilter < Filter
12
+ # Register type
13
+ Fluent::Plugin.register_filter('burrow', self)
14
+
15
+ # Required
16
+ config_param :key_name, :string
17
+ config_param :format, :string
18
+
19
+ # Optional - record format
20
+ config_param :action, :string, :default => 'inplace' # The action to take once key parsing is complete
21
+ config_param :keep_key, :bool, :default => false # Keep original source key (only valid with 'overlay' and 'replace' actions)
22
+
23
+ # Optional - time format
24
+ config_param :keep_time, :bool, :default => false # Keep the original event's "time" key
25
+ config_param :record_time_key, :string, :default => 'time' # Allow a custom time field in the record
26
+ config_param :time_key, :string, :default => 'time' # Allow a custom time field in the sub-record
27
+ config_param :time_format, :string, :default => nil # Allow a custom time format for the new record
28
+
29
+
30
+ def configure(conf)
31
+ super
32
+
33
+ # Validate action
34
+ actions = ['replace','overlay','inplace','prefix']
35
+ if not actions.include? @action
36
+ raise Fluent::ConfigError, "Invalid 'action', must be one of #{actions.join(',')}"
37
+ end
38
+
39
+ # Validate action-based restrictions
40
+ if @action == 'inplace' and @keep_key
41
+ raise Fluent::ConfigError, "Specifying 'keep_key' with action 'inplace' is not supported"
42
+ end
43
+ if @action == 'prefix' and not @data_prefix
44
+ raise Fluent::ConfigError, "You must specify 'data_prefix' with action 'prefix'"
45
+ end
46
+
47
+ # Prepare fluent's built-in parser
48
+ @parser = Fluent::Plugin.new_parser(@format)
49
+ @parser.configure(conf) if @parser.respond_to?(:configure)
50
+ end
51
+
52
+
53
+ def start
54
+ super
55
+ end
56
+
57
+
58
+ def shutdown
59
+ super
60
+ end
61
+
62
+
63
+ def filter(tag, time, record)
64
+ raw_value = record[@key_name]
65
+ if raw_value then
66
+ new_time, new_values = nil, nil
67
+ @parser.parse(raw_value) do |parsed_time, parsed_values|
68
+ new_time = parsed_time
69
+ new_values = parsed_values
70
+ end
71
+
72
+ if new_values then
73
+ original_time = record[@record_time_key]
74
+ new_time ||= original_time
75
+
76
+ # Overlay new record on top of original record?
77
+ new_record = case @action
78
+ when 'inplace'
79
+ record.merge({@key_name => new_values})
80
+ when 'overlay'
81
+ record.merge(new_values)
82
+ when 'replace'
83
+ new_values
84
+ when 'prefix'
85
+ record.merge({@data_prefix => new_values})
86
+ end
87
+
88
+ # Keep the key?
89
+ if ['overlay','replace','prefix'].include? @action
90
+ if not @keep_key and new_record.has_key?(@key_name)
91
+ new_record.delete(@key_name)
92
+ end
93
+ end
94
+
95
+ # Preserve 'time' key?
96
+ if @keep_time
97
+ new_record[@record_time_key] = original_time
98
+ end
99
+
100
+ new_record
101
+ end
102
+ end
103
+ end
104
+
105
+ end
106
+ end
@@ -5,6 +5,8 @@
5
5
  # format, and then re-emit a new event with the key's value replaced, or with the whole record replaced.
6
6
  #
7
7
 
8
+ require 'fluent/parser'
9
+
8
10
  class Fluent::BurrowPlugin < Fluent::Output
9
11
  # Register type
10
12
  Fluent::Plugin.register_output('burrow', self)
@@ -140,11 +142,11 @@ class Fluent::BurrowPlugin < Fluent::Output
140
142
 
141
143
  # Emit event back to Fluent
142
144
  if r
143
- Fluent::Engine.emit(tag, t, r)
145
+ router.emit(tag, t, r)
144
146
  end
145
147
  end
146
148
 
147
149
  chain.next
148
150
  end
149
151
 
150
- end
152
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-burrow
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Gunter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -55,6 +55,7 @@ files:
55
55
  - Rakefile
56
56
  - examples/syslog.json.txt
57
57
  - fluent-plugin-burrow.gemspec
58
+ - lib/fluent/plugin/filter_burrow.rb
58
59
  - lib/fluent/plugin/out_burrow.rb
59
60
  - test/helper.rb
60
61
  homepage: https://github.com/vanilla/fluent-plugin-burrow
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  requirements: []
79
80
  rubyforge_project:
80
- rubygems_version: 2.0.14
81
+ rubygems_version: 2.0.14.1
81
82
  signing_key:
82
83
  specification_version: 4
83
84
  summary: Fluentd output filter plugin. Extract a single key (in formats Fluent can