Class: LogStash::Outputs::HipChat

Inherits:
Base show all
Defined in:
lib/logstash/outputs/hipchat.rb

Overview

This output allows you to write events to [HipChat](www.hipchat.com/).

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#encode(hash) ⇒ Object

shamelessly lifted this from the LogStash::Outputs::Http, I’d rather put this in a common place for both to use, but unsure where that place is or should be



74
75
76
77
78
# File 'lib/logstash/outputs/hipchat.rb', line 74

def encode(hash)
  return hash.collect do |key, value|
    CGI.escape(key) + "=" + CGI.escape(value)
  end.join("&")
end

#receive(event) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/logstash/outputs/hipchat.rb', line 44

def receive(event)
  return unless output?(event)

  hipchat_data = Hash.new
  hipchat_data['room_id'] = @room_id
  hipchat_data['from']    = @from
  hipchat_data['color']   = @color
  hipchat_data['notify']  = @trigger_notify ? "1" : "0"
  hipchat_data['message'] = event.sprintf(@format)

  @logger.debug("HipChat data", :hipchat_data => hipchat_data)

  begin
    request = @agent.post(@url)
    request["Content-Type"] = @content_type
    request.body = encode(hipchat_data)

    response = @agent.execute(request)

    # Consume body to let this connection be reused
    rbody = ""
    response.read_body { |c| rbody << c }
    #puts rbody
  rescue Exception => e
    @logger.warn("Unhandled exception", :request => request, :response => response, :exception => e, :stacktrace => e.backtrace)
  end
end

#registerObject



33
34
35
36
37
38
39
40
41
# File 'lib/logstash/outputs/hipchat.rb', line 33

def register
  require "ftw"
  require "uri"

  @agent = FTW::Agent.new

  @url = "https://api.hipchat.com/v1/rooms/message?auth_token=" + @token
  @content_type = "application/x-www-form-urlencoded"
end