diff options
-rwxr-xr-x | up.rb | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -1,5 +1,6 @@ #!/usr/bin/env ruby +require "net/http" require "net/ping" require "socket" @@ -8,10 +9,16 @@ class Host parts = s.split @hostname = parts.first @services_and_ports = {} + @sites = [] parts.slice(1, parts.size).each { |part| - service, port_and_protocol = part.split ":" - port, protocol = port_and_protocol.split "/" - @services_and_ports["#{service}/#{protocol}"] = [port.to_i, protocol] + if part[0] == "@" + url = part.slice 1, part.size + @sites << url + else + service, port_and_protocol = part.split ":" + port, protocol = port_and_protocol.split "/" + @services_and_ports["#{service}/#{protocol}"] = [port.to_i, protocol] + end } end @@ -39,6 +46,17 @@ class Host else STDERR.write "unknown protocol '#{protocol}'\n" end + return false + end + + def site_up? site + begin + url = URI site + response = Net::HTTP.get_response url + return response.kind_of? Net::HTTPSuccess + rescue + return false + end end def check @@ -48,6 +66,9 @@ class Host @services_and_ports.each_key { |k| ret[k] = service_up? k, @services_and_ports[k][0], @services_and_ports[k][1] } + @sites.each { |url| + ret[url] = site_up? url + } return ret end end |