Class: EzHealthcheck

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, id, key) ⇒ EzHealthcheck

Returns a new instance of EzHealthcheck.



8
9
10
11
12
13
14
15
# File 'lib/ez_healthcheck.rb', line 8

def initialize(host, id, key)
  @codes = {}
  @host = host
  @ses = AWS::SimpleEmailService.new(
    :access_key_id => id,
    :secret_access_key => key
  )
end

Instance Attribute Details

#codesObject

Returns the value of attribute codes.



6
7
8
# File 'lib/ez_healthcheck.rb', line 6

def codes
  @codes
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/ez_healthcheck.rb', line 6

def host
  @host
end

#sesObject

Returns the value of attribute ses.



6
7
8
# File 'lib/ez_healthcheck.rb', line 6

def ses
  @ses
end

Instance Method Details

#access(paths = []) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ez_healthcheck.rb', line 17

def access(paths=[])
  paths.each do |path|
    #puts path
    response = Net::HTTP.get_response(@host,path)
    case response
    when Net::HTTPInformation
      #puts "1xx"
    when Net::HTTPSuccess
      #puts "2xx"
    when Net::HTTPRedirection
      #puts "3xx"
    when Net::HTTPClientError
      #puts "4xx"
    when Net::HTTPServerError
      #puts "5xx"
    else
      #puts "unknown"
    end
    @codes.store(path, response.code)
  end
end

#send_email(params = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ez_healthcheck.rb', line 39

def send_email(params={})
  begin
    @ses.send_email(
      :subject   => params[:subject],
      :from      => params[:from],
      :to        => params[:to],
      :body_text => params[:body_text],
      :body_html => params[:body_html]
    )
  rescue => ex
    puts ex
  end
end