fluent-plugin-ltsv-parser 0.0.8 → 0.0.9

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.
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-ltsv-parser"
4
- gem.version = "0.0.8"
4
+ gem.version = "0.0.9"
5
5
  gem.authors = ["anarcher"]
6
6
  gem.email = ["anarcher@gmail.com"]
7
7
  gem.description = %q{fluentd plugin to ltsv parse single field, or to combine log structure into single field}
@@ -7,6 +7,7 @@ class Fluent::ParserOutput < Fluent::Output
7
7
  config_param :filter_in, :string , :default => ""
8
8
  config_param :add_prefix, :string ,:default => nil
9
9
  config_param :min_field, :integer , :default => nil
10
+ config_param :transform_values,:string,:default => nil
10
11
 
11
12
  def initialize
12
13
  super
@@ -20,10 +21,16 @@ class Fluent::ParserOutput < Fluent::Output
20
21
 
21
22
  def configure(conf)
22
23
  super
24
+
23
25
  if @key_name[0] == ":"
24
26
  @key_name = @key_name[1..-1].to_sym
25
27
  end
28
+
26
29
  @filter_in = @filter_in.split(",").map(&:strip).select{ |e| e != "" }
30
+
31
+ if @transform_values then
32
+ @transform_values = Hash[@transform_values.split(",").map{|p| p.split(":",2)}]
33
+ end
27
34
  end
28
35
 
29
36
  def emit(tag,es,chain)
@@ -33,7 +40,7 @@ class Fluent::ParserOutput < Fluent::Output
33
40
  end
34
41
  es.each do |time,record|
35
42
  raw_value = record[@key_name]
36
- values = raw_value ? filter(parse(raw_value)) : nil
43
+ values = raw_value ? transform_values(filter(parse(raw_value))) : nil
37
44
 
38
45
  r = @reserve_data ? record.merge(values) : values
39
46
  if r
@@ -65,6 +72,17 @@ class Fluent::ParserOutput < Fluent::Output
65
72
  return _record
66
73
  end
67
74
 
75
+ def transform_values(record)
76
+ return record if @transform_values.nil?
77
+
78
+ @transform_values.each do |key,value|
79
+ field_name,field_value = key.split("=")
80
+ next if record[field_name].nil? or field_name.nil? or field_value.nil?
81
+ record[field_name] = value if field_value == record[field_name]
82
+ end
83
+ return record
84
+ end
85
+
68
86
  def parse(text)
69
87
  return Hash[text.split("\t").map{|p| p.split(":", 2)}]
70
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-ltsv-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-18 00:00:00.000000000 Z
12
+ date: 2014-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake