Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created September 15, 2014 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnakamur/a77b4a3c017b63f75c77 to your computer and use it in GitHub Desktop.
Save hnakamur/a77b4a3c017b63f75c77 to your computer and use it in GitHub Desktop.
ドメインとELBのIPアドレスを毎秒表示するRubyスクリプト。Route53でALIASでELBのドメインを設定した時用。domainとelb_domainの値を書き換えて使ってください。
#!/usr/bin/env ruby
# (c) 2014 Hioraki Nakamura
# MIT License
domain = "_YOUR_DOMAIN_HERE_"
elb_domain = "_YOUR_ELB_HOSTNAME_HERE_.ap-northeast-1.elb.amazonaws.com"
def get_ttl_and_ip(domain)
ttl_and_ips = []
IO.popen(["dig", domain], "r") do |io|
while line = io.gets
if line =~ /ANSWER SECTION/
while (line = io.gets) != "\n"
words = line.split(/\s+/)
ttl_and_ips << {ttl: words[1], ip: words[4]}
end
break
end
end
end
ttl_and_ips
end
while true
terms = []
now = Time.now
terms << "time:#{now.strftime("%Y-%m-%dT%H:%M:%S%z")}"
ttl_and_ip = get_ttl_and_ip(domain)[0]
terms << "ttl:#{ttl_and_ip[:ttl]}"
terms << "ip:#{ttl_and_ip[:ip]}"
elb_ttl_and_ips = get_ttl_and_ip elb_domain
elb_ttl_and_ips.each_with_index do |ttl_and_ip, i|
terms << "elb_ttl#{i}:#{ttl_and_ip[:ttl]}"
terms << "elb_ip#{i}:#{ttl_and_ip[:ip]}"
end
puts terms.join("\t")
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment