Class: Fluent::BufferedHipchatOutput

Inherits:
TimeSlicedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_buffered_hipchat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBufferedHipchatOutput

Returns a new instance of BufferedHipchatOutput.



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

def initialize
  super
  require 'hipchat-api'
end

Instance Attribute Details

#hipchatObject (readonly)

Returns the value of attribute hipchat.



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

def hipchat
  @hipchat
end

Instance Method Details

#configure(conf) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fluent/plugin/out_buffered_hipchat.rb', line 49

def configure(conf)
  super

  @hipchat = HipChat::API.new(conf['api_token'])
  @default_room = conf['default_room']
  @default_from = conf['default_from'] || 'fluentd'
  @default_notify = conf['default_notify'] || 0
  @default_color = conf['default_color'] || 'yellow'
  @default_format = conf['default_format'] || 'html'
  if conf['http_proxy_host']
    HipChat::API.http_proxy(
      conf['http_proxy_host'],
      conf['http_proxy_port'],
      conf['http_proxy_user'],
      conf['http_proxy_pass'])
  end
end

#format(tag, time, record) ⇒ Object



17
18
19
# File 'lib/fluent/plugin/out_buffered_hipchat.rb', line 17

def format(tag, time, record)
  [tag, time, record].to_json + "\n"
end

#write(chunk) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fluent/plugin/out_buffered_hipchat.rb', line 21

def write(chunk)
  messages = {}
  chunk.open {|io|
    io.each {|line|
      line_json = JSON.parse(line)
      tag    = line_json[0]
      time   = line_json[1]
      record = line_json[2]
      messages[tag] = '' unless messages[tag]
      messages[tag] << "[#{Time.at(time)}] #{record['message']}\n"
    }
  }
  # hoge = "ajshdfjalksfjlkasdjf\nlaksjfdl\naksfksadflka;"
  # hoge.scan(/.{1,24}\Z|.{1,24}\n/m)
  messages.each do |tag, message|
    message.scan(/.{1,9500}/m).each {|chunked_message|
      @hipchat.rooms_message(@default_room, @default_from, "#{tag} >>\n" + chunked_message, @default_notify, @default_color, @default_format)
    }
  end
rescue => e
  $log.error("HipChat Error: #{e} / #{e.message}")
end