Class: Fluent::ChatworkOutput

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

This method is called before starting.



15
16
17
# File 'lib/fluent/plugin/out_chatwork.rb', line 15

def configure(conf)
  super
end

#emit(tag, es, chain) ⇒ 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.



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

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

#generate_message(args = {}) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/fluent/plugin/out_chatwork.rb', line 47

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



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

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

#shutdownObject

This method is called when shutting down.



25
26
27
# File 'lib/fluent/plugin/out_chatwork.rb', line 25

def shutdown
  super
end

#startObject

This method is called when starting.



20
21
22
# File 'lib/fluent/plugin/out_chatwork.rb', line 20

def start
  super
end