Class: Nines::HttpCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/nines/http_check.rb

Instance Attribute Summary collapse

Attributes inherited from Check

#address, #cycles, #group, #hostname, #interval, #logger, #name, #notifier, #port, #since, #timeout, #up

Instance Method Summary collapse

Methods inherited from Check

#log_status

Constructor Details

#initialize(group, options) ⇒ HttpCheck

Returns a new instance of HttpCheck.



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

def initialize(group, options)
  super(group, options)
  
  @uri = options['uri'] || "http://#{hostname}:#{port}/"
  @up_statuses = options['up_statuses'] || [ 200 ]
  @user_agent = options['user_agent'] || "nines/1.0"
end

Instance Attribute Details

#up_statusesObject

Returns the value of attribute up_statuses.



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

def up_statuses
  @up_statuses
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

#user_agentObject

Returns the value of attribute user_agent.



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

def user_agent
  @user_agent
end

Instance Method Details

#debugObject

shortcuts



17
# File 'lib/nines/http_check.rb', line 17

def debug     ; Nines::App.debug    ; end

#runObject



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

def run
  while Nines::App.continue do
    check_started = Time.now
    @address = Dnsruby::Resolv.getaddress(hostname)
    
    @pinger = Net::Ping::HTTP.new(uri, port, timeout)
    @pinger.user_agent = user_agent
    
    # the check
    log_status(@pinger.ping?, "#{uri} (#{address})#{@pinger.warning ? " [warning: #{@pinger.warning}]" : ''}")
    
    break if debug
    
    wait = interval.to_f - (Time.now - check_started)
    while wait > 0 do
      break unless Nines::App.continue
      sleep [1, wait].min
      wait -= 1
    end
  end
end