Class: Fluent::MuleFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_mule.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



15
16
17
18
19
20
# File 'lib/fluent/plugin/filter_mule.rb', line 15

def configure(conf)
  super
  # TimeParser class is already given. It takes a single argument as the time format
  # to parse the time string with.
  @time_parser = Fluent::TextParser::TimeParser.new(@time_format)
end

#filter(tag, time, record) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fluent/plugin/filter_mule.rb', line 34

def filter(tag, time, record)
  # This method implements the filtering logic for individual filters
  # It is internal to this class and called by filter_stream unless
  # the user overrides filter_stream.
  #
  # Since our example is a pass-thru filter, it does nothing and just
  # returns the record as-is.
  # If returns nil, that records are ignored.
  text = record['message']
  puts "TEXT: " + text

  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=.*)?$/)

  if match.nil?
    puts 'match is nil'
    return record
  end

  puts '1'
  if match.names.include? 'log_level'
    record['mule_log_level'] = match['log_level']
  end
  puts '2'
  if match.names.include? 'log_time'
    record['mule_log_time'] = match['log_time']
  end
  puts '3'
  if match.names.include? 'thread'
    record['mule_thread'] = match['thread']
  end
  puts '4'
  if match.names.include? 'position'
    record['mule_position'] = match['position']
  end       
  puts '5'
  if match.names.include? 'kv_pairs'
    kv_match = match['kv_pairs'].match(/(\w+)=([\w|-]+)\s/)
    if kv_match == nil
      puts 'Couldn\'t find kv pairs'
      return record 
    end

    match['kv_pairs'].split(@kv_delimiter).each { |kv|
      k, v = kv.split(@kv_char, 2)
      record['mule_' + k] = v
    }
  end
  puts '6'

  if (match.names.include? 'payload') && !match['payload'].nil?
    puts '6.1'
    k, v = match['payload'].split('=', 2)
    puts '6.2'
    record['mule_' + k] = v
  end
    
  puts '7'
  puts 'record[log_time]: ' + record['mule_log_time']
  puts 'record[log_time].nil?: ' + record['mule_log_time'].nil?.to_s
  puts 'timeParse?: ' + @time_parse.to_s
  if @time_parse && !record['log_time'].nil? 
    puts '7.1'
    new_time = @time_parser.parse(record['mule_log_time'])
    record.delete('time')
    record['time'] = current_time
  end
  puts '8'
  record.delete('message')
  puts '9'
  record
end

#shutdownObject



28
29
30
31
32
# File 'lib/fluent/plugin/filter_mule.rb', line 28

def shutdown
  super
  # This method is called when Fluentd is shutting down.
  # Use it to free up resources, etc.
end

#startObject



22
23
24
25
26
# File 'lib/fluent/plugin/filter_mule.rb', line 22

def start
  super
  # This is the first method to be called when it starts running
  # Use it to allocate resources, etc.
end