Class: Fluent::Plugin::HipchatOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::HipchatOutput
- Defined in:
- lib/fluent/plugin/out_hipchat.rb
Constant Summary collapse
- COLORS =
%w(yellow red green purple gray random)
- FORMAT =
%w(html text)
- DEFAULT_BUFFER_TYPE =
"memory"
Instance Attribute Summary collapse
-
#hipchat ⇒ Object
readonly
Returns the value of attribute hipchat.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
- #formatted_to_msgpack_binary ⇒ Object
-
#initialize ⇒ HipchatOutput
constructor
A new instance of HipchatOutput.
- #multi_workers_ready? ⇒ Boolean
- #send_message(record) ⇒ Object
- #set_topic(record) ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ HipchatOutput
Returns a new instance of HipchatOutput.
34 35 36 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 34 def initialize super end |
Instance Attribute Details
#hipchat ⇒ Object (readonly)
Returns the value of attribute hipchat.
32 33 34 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 32 def hipchat @hipchat end |
Instance Method Details
#configure(conf) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 38 def configure(conf) compat_parameters_convert(conf, :buffer) super @hipchat = HipChat::API.new(conf['api_token']) @default_room = conf['default_room'] @default_notify = conf['default_notify'] || 0 @default_timeout = conf['default_timeout'] 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 raise Fluent::ConfigError, "'tag' in chunk_keys is required." if not @chunk_key_tag end |
#format(tag, time, record) ⇒ Object
56 57 58 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 56 def format(tag, time, record) [time, record].to_msgpack end |
#formatted_to_msgpack_binary ⇒ Object
60 61 62 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 60 def formatted_to_msgpack_binary true end |
#multi_workers_ready? ⇒ Boolean
64 65 66 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 64 def multi_workers_ready? true end |
#send_message(record) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 79 def (record) room = record['room'] || @default_room from = record['from'] || @default_from = record[@key_name] 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.set_timeout(@default_timeout.to_i) unless @default_timeout.nil? response = @hipchat.(room, from, , notify, color, ) raise StandardError, response['error'][@key_name].to_s if defined?(response['error'][@key_name]) end |
#set_topic(record) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 95 def set_topic(record) room = record['room'] || @default_room from = record['from'] || @default_from topic = record['topic'] response = @hipchat.rooms_topic(room, topic, from) raise StandardError, response['error'][@key_name].to_s if defined?(response['error'][@key_name]) end |
#write(chunk) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fluent/plugin/out_hipchat.rb', line 68 def write(chunk) chunk.msgpack_each do |(time,record)| begin (record) if record[@key_name] set_topic(record) if record['topic'] rescue => e log.error("HipChat Error:", :error_class => e.class, :error => e.) end end end |