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.

Raises:

  • (Fluent::ConfigError)


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

def configure(conf)
  compat_parameters_convert(conf, :buffer)
  super

  raise Fluent::ConfigError, "'tag' in chunk_keys is required." unless @chunk_key_tag
end

#format(tag, time, record) ⇒ Object



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

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

#formatted_to_msgpack_binary?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/fluent/plugin/out_chatwork.rb', line 54

def formatted_to_msgpack_binary?
  true
end

#generate_message(args = {}) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/fluent/plugin/out_chatwork.rb', line 86

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



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

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



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

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.



67
68
69
70
71
# File 'lib/fluent/plugin/out_chatwork.rb', line 67

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.



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

def shutdown
  super
end

#startObject

This method is called when starting.



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

def start
  super
end

#write(chunk) ⇒ Object



73
74
75
76
77
78
# File 'lib/fluent/plugin/out_chatwork.rb', line 73

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