Class: Fluent::Plugin::ChatworkOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_chatwork.rb

Constant Summary collapse

DEFAULT_BUFFER_TYPE =
"memory"

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

This method is called before starting.



27
28
29
# File 'lib/fluent/plugin/out_chatwork.rb', line 27

def configure(conf)
  super
end

#format(tag, time, record) ⇒ Object



49
50
51
# File 'lib/fluent/plugin/out_chatwork.rb', line 49

def format(tag, time, record)
  [time, record].to_msgpack
end

#formatted_to_msgpack_binary?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/fluent/plugin/out_chatwork.rb', line 45

def formatted_to_msgpack_binary?
  true
end

#generate_message(args = {}) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/fluent/plugin/out_chatwork.rb', line 77

def generate_message(args={})
  time   = args[:time]
  record = args[:record]
  tag    = args[:tag]

  ERB.new(@message).result(binding).gsub("\\n", "\n")
end

#post_message(args = {}) ⇒ Object



71
72
73
74
75
# File 'lib/fluent/plugin/out_chatwork.rb', line 71

def post_message(args={})
  body = generate_message(args)
  ChatWork.api_key = @api_token
  ChatWork::Message.create(room_id: @room_id, body: body)
end

#prefer_buffered_processingObject



41
42
43
# File 'lib/fluent/plugin/out_chatwork.rb', line 41

def prefer_buffered_processing
  @buffered
end

#process(tag, es) ⇒ Object

This method is called when an event reaches Fluentd. ‘es’ is a Fluent::EventStream object that includes multiple events. You can use ‘es.each {|time,record| … }’ to retrieve events. ‘chain’ is an object that manages transactions. Call ‘chain.next’ at appropriate points and rollback if it raises an exception.



58
59
60
61
62
# File 'lib/fluent/plugin/out_chatwork.rb', line 58

def process(tag, es)
  es.each {|time,record|
    post_message(time: time, record: record, tag: tag)
  }
end

#shutdownObject

This method is called when shutting down.



37
38
39
# File 'lib/fluent/plugin/out_chatwork.rb', line 37

def shutdown
  super
end

#startObject

This method is called when starting.



32
33
34
# File 'lib/fluent/plugin/out_chatwork.rb', line 32

def start
  super
end

#write(chunk) ⇒ Object



64
65
66
67
68
69
# File 'lib/fluent/plugin/out_chatwork.rb', line 64

def write(chunk)
  tag = chunk..tag
  chunk.msgpack_each {|time, record|
    post_message(time: time, record: record, tag: tag)
  }
end