Class: OnLooker

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

Class Method Summary collapse

Class Method Details

.check(host, ping_type, debug = false, timeout = 2) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/onlooker.rb', line 5

def self.check(host, ping_type, debug=false, timeout=2)
  type = ping_type.downcase
  if type == "ip"
    request = Net::PingExternal.new(host, timeout)
    get_result(request, debug)
  elsif type == "web"
    request = PingTCP.new(host, "http", 2)
    get_result(request, debug)
  else
    "Type invalid. Try 'web' or 'ip'."
  end    
end

.get_result(request, debug) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/onlooker.rb', line 18

def self.get_result(request, debug)
  if request.ping?
      "Online"
  else
      status = "Offline "
      if debug == true
        return status + request.exception
      else
        return status
      end
  end
end