Class: Fluent::Plugin::DockergelfFilter

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



9
10
11
# File 'lib/fluent/plugin/filter_dockergelf.rb', line 9

def configure(conf)
  super
end

#filter_with_time(tag, time, record) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fluent/plugin/filter_dockergelf.rb', line 13

def filter_with_time(tag, time, record)
  record["logtime"] = Time.at(time.to_f).iso8601(3).to_s
  content = record["log"].strip
  rettime = time
  if (content =~ /^[{](.*)[}]$/)
    content_hash = JSON.parse(content)
    if content_hash["version"].to_s == "1.1" && content_hash["short_message"] != nil #check if gelf format
      content_hash.delete("version")
      msg = content_hash["short_message"]
      content_hash.delete("short_message")
      content_hash.each do |key ,value|
        if key == "timestamp"
          rettime = Fluent::EventTime.from_time(Time.at(value))
        else
          record[key]=value
        end
      end
      record["log"] = msg
    end
  end
rescue
ensure
  puts "returning "+ (Time.at(rettime.to_f).iso8601(3).to_s )+" "+record.to_s
  return rettime, record
end