fluent-plugin-mule 1.0 → 1.0.1

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: e8ee78dafd7dd6aa40cebba7db6fa251ddb0469d
4
- data.tar.gz: 3793bbea0b21e20c4b45ed5fcf5cc605cd29f2ee
3
+ metadata.gz: 887fb6cd62de2ad184f1c5b783a4b8b329234a49
4
+ data.tar.gz: 601b0839d9ab6355986af97bee0ca2093f2ddd68
5
5
  SHA512:
6
- metadata.gz: 3b23f82d97aba5426f345e16d3674d288e74fd4c4c887c45f5da3714ffb39ebf8ce4413450a52ff4199aa11dc72d554b2904c96142771d7992d23c28c7379d23
7
- data.tar.gz: eabb9dc283fdbb8b5c15062a0ae5fd8d15957df9c1ff9243010da435b4af89653636c02106afbaa67e875f2359bec53084edbb938e122195d758ddb014b4af1a
6
+ metadata.gz: 672a1ef989dc0fca20fd54db9fc510ed25ed777ad9ddc19db0b8967ff1df2d2d4bd7b550789d07ece336a462a976b5ae9c5ace98c82c0e42b8b9e433e58e1e74
7
+ data.tar.gz: 107e36c6b65f0cdc8b5e0dafb8d119bb5c6576cc595884e7d2d452358f7ad34889b2dbd0acee87de0e064f9cfc8cfd110b581ea81119f880708b33824cc04520
@@ -6,11 +6,13 @@ module Fluent
6
6
  Fluent::Plugin.register_filter('mule', self)
7
7
 
8
8
  # config_param works like other plugins
9
+ config_param :key_name, :string, :default => 'message'
9
10
  config_param :kv_delimiter, :string, :default => ' '
10
11
  config_param :kv_char, :string, :default => '='
11
12
  config_param :time_parse, :bool, :default => false
12
13
  # 2016-12-09 14:50:51,330
13
14
  config_param :time_format, :string, :default => '%Y-%m-%d %H:%M:%S,%L'
15
+ config_param :prefix, :string, :default => 'mule_'
14
16
 
15
17
  def configure(conf)
16
18
  super
@@ -36,71 +38,56 @@ module Fluent
36
38
  # It is internal to this class and called by filter_stream unless
37
39
  # the user overrides filter_stream.
38
40
  #
39
- # Since our example is a pass-thru filter, it does nothing and just
40
- # returns the record as-is.
41
41
  # If returns nil, that records are ignored.
42
- text = record['message']
43
- puts "TEXT: " + text
42
+ text = record[@key_name]
44
43
 
45
- match = text.match(/^(?<log_level>[\w]+)\s(?<log_time>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3})\s\[(?<thread>.+)\]\s(?<position>[^:]+):\s(?<kv_pairs>.*?)\s?(?<payload>payload=.*)?$/)
44
+ messageRegex = /
45
+ ^
46
+ (?<log_level>[\w]+)\s
47
+ (?<log_time>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3})\s
48
+ \[(?<thread>.+)\]\s
49
+ (?<position>[^:]+):\s
50
+ (?<kv_pairs>.*?)\s?
51
+ (?<payload>payload=.*)?
52
+ $
53
+ /x
54
+
55
+ match = text.match(messageRegex)
46
56
 
57
+ # If message doesn't match regex we return the record as is
47
58
  if match.nil?
48
- puts 'match is nil'
49
59
  return record
50
60
  end
51
61
 
52
- puts '1'
53
- if match.names.include? 'log_level'
54
- record['mule_log_level'] = match['log_level']
55
- end
56
- puts '2'
57
- if match.names.include? 'log_time'
58
- record['mule_log_time'] = match['log_time']
59
- end
60
- puts '3'
61
- if match.names.include? 'thread'
62
- record['mule_thread'] = match['thread']
63
- end
64
- puts '4'
65
- if match.names.include? 'position'
66
- record['mule_position'] = match['position']
67
- end
68
- puts '5'
69
- if match.names.include? 'kv_pairs'
70
- kv_match = match['kv_pairs'].match(/(\w+)=([\w|-]+)\s/)
71
- if kv_match == nil
72
- puts 'Couldn\'t find kv pairs'
73
- return record
74
- end
75
-
76
- match['kv_pairs'].split(@kv_delimiter).each { |kv|
77
- k, v = kv.split(@kv_char, 2)
78
- record['mule_' + k] = v
79
- }
80
- end
81
- puts '6'
82
-
83
- if (match.names.include? 'payload') && !match['payload'].nil?
84
- puts '6.1'
85
- k, v = match['payload'].split('=', 2)
86
- puts '6.2'
87
- record['mule_' + k] = v
88
- end
62
+ ['log_level', 'log_time', 'thread', 'position', 'kv_pairs', 'payload'].each { |group|
63
+ updateRecord(record, match, group, group == 'kv_pairs')
64
+ }
89
65
 
90
- puts '7'
91
- puts 'record[log_time]: ' + record['mule_log_time']
92
- puts 'record[log_time].nil?: ' + record['mule_log_time'].nil?.to_s
93
- puts 'timeParse?: ' + @time_parse.to_s
94
66
  if @time_parse && !record['log_time'].nil?
95
- puts '7.1'
96
67
  new_time = @time_parser.parse(record['mule_log_time'])
97
68
  record.delete('time')
98
69
  record['time'] = current_time
99
70
  end
100
- puts '8'
101
- record.delete('message')
102
- puts '9'
71
+ record.delete(@key_name)
103
72
  record
104
73
  end
74
+
75
+ def updateRecord(record, match, group, kv_flag)
76
+ if (match.names.include? group) && !match[group].nil?
77
+ if kv_flag
78
+ kv_match = match[group].match(/(\w+)=([\w|-]+)\s/)
79
+ if kv_match.nil?
80
+ return
81
+ end
82
+
83
+ match[group].split(@kv_delimiter).each { |kv|
84
+ k, v = kv.split(@kv_char, 2)
85
+ record[@prefix + k] = v
86
+ }
87
+ else
88
+ record[@prefix + group] = match[group]
89
+ end
90
+ end
91
+ end
105
92
  end
106
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mule
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Martinez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-15 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Extract entries from Mule log4j key-value pairs
14
14
  email:
@@ -41,6 +41,6 @@ rubyforge_project:
41
41
  rubygems_version: 2.0.14.1
42
42
  signing_key:
43
43
  specification_version: 4
44
- summary: Fluentd filter plugin. Extract fields from Mule/Log4j formatted entries containing
45
- key value pairs
44
+ summary: Fluentd filter plugin. Extracts fields from Mule/Log4j formatted entries
45
+ containing key value pairs
46
46
  test_files: []