class Fluent::HatoholOutput
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_hatohol.rb, line 33 def configure(conf) super validate_configuraiton end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_hatohol.rb, line 56 def format(tag, time, record) [tag, time, record].to_msgpack end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_hatohol.rb, line 51 def shutdown super @connection.close end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_hatohol.rb, line 38 def start super options = { :tls_cert => @tls_cert, :tls_key => @tls_key, :tls_ca_certificates => @tls_ca_certificates, } @connection = Bunny.new(url || {}, options) @connection.start @channel = @connection.create_channel @queue = @channel.queue(@queue_name) end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_hatohol.rb, line 60 def write(chunk) chunk.msgpack_each do |tag, time, record| @queue.publish(JSON.generate(build_message(tag, time, record)), :content_type => "application/json") end end
Private Instance Methods
build_content(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_hatohol.rb, line 92 def build_content(tag, time, record) parameters = { :tag => tag, :time => time, } record.each do |key, value| parameters[key.to_sym] = value end @content_format % parameters end
build_id(time)
click to toggle source
# File lib/fluent/plugin/out_hatohol.rb, line 87 def build_id(time) now = Time.now now.to_i * 1_000_000_000 + now.nsec end
build_message(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_hatohol.rb, line 74 def build_message(tag, time, record) { "type" => "event", "body" => { "id" => build_id(time), "timestamp" => Time.at(time).iso8601, "hostName" => record[@host_key], "content" => build_content(tag, time, record), "severity" => build_severity(record), } } end
build_severity(record)
click to toggle source
# File lib/fluent/plugin/out_hatohol.rb, line 103 def build_severity(record) parameters = {} record.each do |key, value| parameters[key.to_sym] = value end @severity_format % parameters end
validate_configuraiton()
click to toggle source
# File lib/fluent/plugin/out_hatohol.rb, line 68 def validate_configuraiton if @queue_name.nil? raise ConfigError, "Must set queue_name" end end