Skip to content

Instantly share code, notes, and snippets.

@mikehale
Created June 20, 2013 21:26
Show Gist options
  • Save mikehale/5826794 to your computer and use it in GitHub Desktop.
Save mikehale/5826794 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'socket'
require 'net/https'
require "uri"
# Pings all addresses of an ELB every INTERVAL
interval = (ARGV[0] || 1).to_f
elb_name = ARGV[1]
host = ARGV[2] || elb_name
while true
addrs = Socket.getaddrinfo(elb_name, nil).select{|e| e[0]["AF_INET"] }.map{|e| e[2]}.uniq
addrs.sort.each do |addr|
uri = URI.parse("https://#{addr}/")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
headers = {"Host" => host}
res = http.get(uri.path, headers)
puts [Time.now.utc, "connected to #{addr}".ljust(29," "), res.code].join(" ")
end
sleep interval
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment