Class: Failbot::Haystack

Inherits:
Object
  • Object
show all
Defined in:
lib/failbot/haystack.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, connect_timeout = nil, timeout_seconds = nil) ⇒ Haystack

Returns a new instance of Haystack.



8
9
10
11
12
# File 'lib/failbot/haystack.rb', line 8

def initialize(url, connect_timeout=nil, timeout_seconds=nil)
  @url = url
  @connect_timeout = connect_timeout
  @rw_timeout = timeout_seconds - @connect_timeout.to_f if timeout_seconds
end

Instance Attribute Details

#connect_timeoutObject

Returns the value of attribute connect_timeout.



7
8
9
# File 'lib/failbot/haystack.rb', line 7

def connect_timeout
  @connect_timeout
end

#rw_timeoutObject

Returns the value of attribute rw_timeout.



7
8
9
# File 'lib/failbot/haystack.rb', line 7

def rw_timeout
  @rw_timeout
end

Class Method Details

.send_data(data) ⇒ Object



33
34
35
# File 'lib/failbot/haystack.rb', line 33

def self.send_data(data)
  new(Failbot.haystack).send_data(data)
end

Instance Method Details

#passwordObject



18
19
20
# File 'lib/failbot/haystack.rb', line 18

def password
  @url.password
end

#pingObject

Raises:

  • (StandardError)


37
38
39
40
41
# File 'lib/failbot/haystack.rb', line 37

def ping
  request = Net::HTTP::Head.new('/')
  response = send_request(request)
  raise StandardError, "haystack returned #{response.code}" unless response.code == "200"
end

#send_data(data) ⇒ Object

Raises:

  • (StandardError)


22
23
24
25
26
27
28
29
30
31
# File 'lib/failbot/haystack.rb', line 22

def send_data(data)
  # make a post
  post = Net::HTTP::Post.new(@url.path)
  post.set_form_data('json' => data.to_json)
  response = send_request(post)

  # Raise if the exception doesn't make it to Haystack, ensures the failure
  # is logged
  raise StandardError, "couldn't send exception to Haystack: #{response.code} #{response.message}" unless response.code == "201"
end

#userObject



14
15
16
# File 'lib/failbot/haystack.rb', line 14

def user
  @url.user || "failbot"
end