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
38
39
40
41
42
43
44
45
46
# 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")
      if content_hash.has_key?("full_message")
        msg = msg + ":" + content_hash["full_message"]
        content_hash.delete("full_message")
      end
      if content_hash.has_key?("timestamp")
        rettime = Fluent::EventTime.from_time(Time.at(content_hash["timestamp"]))
        content_hash.delete("timestamp")
      end
      content_hash.each do |key, value|
        prefix = key[0]
        if prefix == "_"
          record[key[1..-1]] = 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