Sha256: 3c70aa39b9cc46b8ab364298b6d77088f00b45b8dc02bc6a2a14b6131ca1c26c

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

module VirtualMonkey
  module UnifiedApplication
    # returns true if the http response contains the expected_string
    # * url<~String> url to perform http request
    # * expected_string<~String> regex compatible string used to match against the response output
    def test_http_response(expected_string, url, port)
      cmd = "curl -s #{url} 2> /dev/null "
      puts cmd
      timeout=300
      begin
        status = Timeout::timeout(timeout) do
          while true
            response = `#{cmd}` 
            break if response.include?(expected_string)
            puts "Retrying..."
            sleep 5
          end
        end
      rescue Timeout::Error => e
        raise "ERROR: Query failed after #{timeout/60} minutes."
      end
    end
    
    def run_unified_application_checks(run_on=@servers, port=8000)
      run_on.each do |server| 
        behavior(:run_unified_application_check, server.dns_name, port)
      end
    end
    
    # this is where ALL the generic application server checks live, this could get rather long but for now it's a single method with a sequence of checks
    def run_unified_application_check(dns_name, port=8000)
      url_base = "#{dns_name}:#{port}"
      behavior(:test_http_response, "html serving succeeded", "#{url_base}/index.html", port) 
      behavior(:test_http_response, "configuration=succeeded", "#{url_base}/appserver/", port) 
      behavior(:test_http_response, "I am in the db", "#{url_base}/dbread/", port) 
      behavior(:test_http_response, "hostname=", "#{url_base}/serverid/", port) 
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
virtualmonkey-0.0.1 lib/virtualmonkey/unified_application.rb