fluent-plugin-mule 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/fluent/plugin/filter_mule.rb +106 -0
  3. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8ee78dafd7dd6aa40cebba7db6fa251ddb0469d
4
+ data.tar.gz: 3793bbea0b21e20c4b45ed5fcf5cc605cd29f2ee
5
+ SHA512:
6
+ metadata.gz: 3b23f82d97aba5426f345e16d3674d288e74fd4c4c887c45f5da3714ffb39ebf8ce4413450a52ff4199aa11dc72d554b2904c96142771d7992d23c28c7379d23
7
+ data.tar.gz: eabb9dc283fdbb8b5c15062a0ae5fd8d15957df9c1ff9243010da435b4af89653636c02106afbaa67e875f2359bec53084edbb938e122195d758ddb014b4af1a
@@ -0,0 +1,106 @@
1
+ require 'fluent/filter'
2
+
3
+ module Fluent
4
+ class MuleFilter < Filter
5
+ # Register this filter as "passthru"
6
+ Fluent::Plugin.register_filter('mule', self)
7
+
8
+ # config_param works like other plugins
9
+ config_param :kv_delimiter, :string, :default => ' '
10
+ config_param :kv_char, :string, :default => '='
11
+ config_param :time_parse, :bool, :default => false
12
+ # 2016-12-09 14:50:51,330
13
+ config_param :time_format, :string, :default => '%Y-%m-%d %H:%M:%S,%L'
14
+
15
+ def configure(conf)
16
+ super
17
+ # TimeParser class is already given. It takes a single argument as the time format
18
+ # to parse the time string with.
19
+ @time_parser = Fluent::TextParser::TimeParser.new(@time_format)
20
+ end
21
+
22
+ def start
23
+ super
24
+ # This is the first method to be called when it starts running
25
+ # Use it to allocate resources, etc.
26
+ end
27
+
28
+ def shutdown
29
+ super
30
+ # This method is called when Fluentd is shutting down.
31
+ # Use it to free up resources, etc.
32
+ end
33
+
34
+ def filter(tag, time, record)
35
+ # This method implements the filtering logic for individual filters
36
+ # It is internal to this class and called by filter_stream unless
37
+ # the user overrides filter_stream.
38
+ #
39
+ # Since our example is a pass-thru filter, it does nothing and just
40
+ # returns the record as-is.
41
+ # If returns nil, that records are ignored.
42
+ text = record['message']
43
+ puts "TEXT: " + text
44
+
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=.*)?$/)
46
+
47
+ if match.nil?
48
+ puts 'match is nil'
49
+ return record
50
+ end
51
+
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
89
+
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
+ if @time_parse && !record['log_time'].nil?
95
+ puts '7.1'
96
+ new_time = @time_parser.parse(record['mule_log_time'])
97
+ record.delete('time')
98
+ record['time'] = current_time
99
+ end
100
+ puts '8'
101
+ record.delete('message')
102
+ puts '9'
103
+ record
104
+ end
105
+ end
106
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-mule
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Martinez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Extract entries from Mule log4j key-value pairs
14
+ email:
15
+ - rodmartinez@deloitte.com.au
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/fluent/plugin/filter_mule.rb
21
+ homepage:
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.14.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Fluentd filter plugin. Extract fields from Mule/Log4j formatted entries containing
45
+ key value pairs
46
+ test_files: []