Skip to content

Instantly share code, notes, and snippets.

@daniel-marschner
Created November 2, 2012 13:57
Show Gist options
  • Select an option

  • Save daniel-marschner/4001503 to your computer and use it in GitHub Desktop.

Select an option

Save daniel-marschner/4001503 to your computer and use it in GitHub Desktop.

Revisions

  1. Daniel Marschner revised this gist Nov 2, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # Fetches the first argument passed to the script, if no is given
    # it raises and error with this simple custom message.
    unless @domain = ARGV.first
    raise "You need to pass in a domain name like www.6wunderkinder.com"
    raise "You need to pass in a domain like www.6wunderkinder.com"
    end

    puts "[#{DateTime.now}] Started the DNS check for #{@domain}..."
  2. Daniel Marschner revised this gist Nov 2, 2012. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,25 @@
    require 'net/http'
    require 'date'

    # Fetches the first argument passed to the script, if no is given it raises and error
    # with this simple custom message.
    # Fetches the first argument passed to the script, if no is given
    # it raises and error with this simple custom message.
    unless @domain = ARGV.first
    raise "You need to pass in a domain name like www.6wunderkinder.com"
    end

    puts "[#{DateTime.now}] Started the DNS check for #{@domain}..."

    # Sends a simple GET request to the given domain and checks if the response was
    # 200 OK.
    # Sends a simple GET request to the given domain and checks
    # if the response was 200 OK.
    def do_request
    uri = URI("http://#{@domain}")
    response = Net::HTTP.get_response(uri)
    response.is_a?(Net::HTTPOK)
    end

    # Puts a NotFound message and sleeps for 60 seconds as long as the request is not a
    # 200 OK. If there is a 200 OK coming back it puts the success message and the script
    # terminates.
    # Puts a NotFound message and sleeps for 60 seconds as long as the
    # request is not a 200 OK. If there is a 200 OK coming back it puts
    # the success message and the script terminates.
    begin
    while do_request == false
    puts "[#{DateTime.now}] NotFound: #{@domain}..."
    @@ -29,10 +29,10 @@ def do_request
    puts "[#{DateTime.now}] Success: #{@domain} is up and running!"
    puts "[#{DateTime.now}] Done."

    # If something went wrong, any error occurs the script terminates with a error
    # message.
    # If something went wrong, any error occurs the script terminates
    # with a error message.
    rescue => e
    puts "[#{DateTime.now}] Error: We couldn't reach #{@domain}, something went wrong!"
    puts "[#{DateTime.now}] Error: We couldn't reach #{@domain}!"
    puts "[#{DateTime.now}] Error: #{e.message}"
    puts "[#{DateTime.now}] Canceled."
    end
  3. Daniel Marschner created this gist Nov 2, 2012.
    38 changes: 38 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    require 'net/http'
    require 'date'

    # Fetches the first argument passed to the script, if no is given it raises and error
    # with this simple custom message.
    unless @domain = ARGV.first
    raise "You need to pass in a domain name like www.6wunderkinder.com"
    end

    puts "[#{DateTime.now}] Started the DNS check for #{@domain}..."

    # Sends a simple GET request to the given domain and checks if the response was
    # 200 OK.
    def do_request
    uri = URI("http://#{@domain}")
    response = Net::HTTP.get_response(uri)
    response.is_a?(Net::HTTPOK)
    end

    # Puts a NotFound message and sleeps for 60 seconds as long as the request is not a
    # 200 OK. If there is a 200 OK coming back it puts the success message and the script
    # terminates.
    begin
    while do_request == false
    puts "[#{DateTime.now}] NotFound: #{@domain}..."
    sleep 60
    end

    puts "[#{DateTime.now}] Success: #{@domain} is up and running!"
    puts "[#{DateTime.now}] Done."

    # If something went wrong, any error occurs the script terminates with a error
    # message.
    rescue => e
    puts "[#{DateTime.now}] Error: We couldn't reach #{@domain}, something went wrong!"
    puts "[#{DateTime.now}] Error: #{e.message}"
    puts "[#{DateTime.now}] Canceled."
    end