Class: Fluent::HipchatOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::HipchatOutput
- Defined in:
- lib/fluent/plugin/out_hipchat.rb
Constant Summary collapse
- COLORS =
%w(yellow red green purple gray random)- FORMAT =
%w(html text)
Instance Attribute Summary collapse
-
#hipchat ⇒ Object
readonly
Returns the value of attribute hipchat.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#initialize ⇒ HipchatOutput
constructor
A new instance of HipchatOutput.
- #send_message(record) ⇒ Object
- #set_topic(record) ⇒ Object
Constructor Details
#initialize ⇒ HipchatOutput
Returns a new instance of HipchatOutput.
21 22 23 24 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 21 def initialize super require 'hipchat-api' end |
Instance Attribute Details
#hipchat ⇒ Object (readonly)
Returns the value of attribute hipchat.
19 20 21 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 19 def hipchat @hipchat end |
Instance Method Details
#configure(conf) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 26 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 |
#emit(tag, es, chain) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 44 def emit(tag, es, chain) es.each {|time, record| begin (record) if record['message'] set_topic(record) if record['topic'] rescue => e $log.error("HipChat Error: #{e} / #{e.message}") end } end |
#send_message(record) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 55 def (record) room = record['room'] || @default_room from = record['from'] || @default_from = record['message'] if record['notify'].nil? notify = @default_notify else notify = record['notify'] ? 1 : 0 end color = COLORS.include?(record['color']) ? record['color'] : @default_color = FORMAT.include?(record['format']) ? record['format'] : @default_format @hipchat.(room, from, , notify, color, ) end |
#set_topic(record) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 69 def set_topic(record) room = record['room'] || @default_room from = record['from'] || @default_from topic = record['topic'] @hipchat.rooms_topic(room, topic, from) end |