Class: Nines::HttpCheck
Instance Attribute Summary collapse
-
#up_statuses ⇒ Object
Returns the value of attribute up_statuses.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Attributes inherited from Check
#address, #cycles, #group, #hostname, #interval, #logger, #name, #notifier, #port, #since, #timeout, #up
Instance Method Summary collapse
-
#debug ⇒ Object
shortcuts.
-
#initialize(group, options) ⇒ HttpCheck
constructor
A new instance of HttpCheck.
- #run ⇒ Object
Methods inherited from Check
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, ) super(group, ) @uri = ['uri'] || "http://#{hostname}:#{port}/" @up_statuses = ['up_statuses'] || [ 200 ] @user_agent = ['user_agent'] || "nines/1.0" end |
Instance Attribute Details
#up_statuses ⇒ Object
Returns the value of attribute up_statuses.
6 7 8 |
# File 'lib/nines/http_check.rb', line 6 def up_statuses @up_statuses end |
#uri ⇒ Object
Returns the value of attribute uri.
6 7 8 |
# File 'lib/nines/http_check.rb', line 6 def uri @uri end |
#user_agent ⇒ Object
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
#debug ⇒ Object
shortcuts
17 |
# File 'lib/nines/http_check.rb', line 17 def debug ; Nines::App.debug ; end |
#run ⇒ Object
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 |