diff options
| author | Steve Kemp <steve@steve.org.uk> | 2012-11-13 11:15:51 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2012-11-13 11:15:51 +0000 | 
| commit | b02dab529ccf63bd61db2cc802bdbc4d65648ae8 (patch) | |
| tree | bb9cfd21de438844e50f4bae71f3c49564ebd98d | |
| parent | c1ea9ce5c169193e254844448c4c83acf308314e (diff) | |
  Updated to use the new class-based API
| -rwxr-xr-x | worker/tests/ftp.rb | 12 | ||||
| -rwxr-xr-x | worker/tests/http.rb | 32 | ||||
| -rwxr-xr-x | worker/tests/https.rb | 34 | ||||
| -rwxr-xr-x | worker/worker | 24 | 
4 files changed, 62 insertions, 40 deletions
| diff --git a/worker/tests/ftp.rb b/worker/tests/ftp.rb index c856c00..a25fe27 100755 --- a/worker/tests/ftp.rb +++ b/worker/tests/ftp.rb @@ -45,8 +45,8 @@ class FTPTest      #      #  Get the hostname & port to test against.      # -    host = @test_data[:target_host] -    port = @test_data[:test_port] +    host = @test_data["target_host"] +    port = @test_data["test_port"]      puts "FTP testing host #{host}:#{port}" @@ -103,10 +103,10 @@ if __FILE__ == $0 then    #  Sample data.    #    test = { -    :target_host => "mirror.bytemark.co.uk", -    :test_type   => "ftp", -    :test_port   => 21, -    :test_alert  => "The FTP server no worky", +    "target_host" => "mirror.bytemark.co.uk", +    "test_type"   => "ftp", +    "test_port"   => 21, +    "test_alert"  => "The FTP server no worky",    } diff --git a/worker/tests/http.rb b/worker/tests/http.rb index 4f2cf0b..eaa351f 100755 --- a/worker/tests/http.rb +++ b/worker/tests/http.rb @@ -46,7 +46,7 @@ class HTTPTest      #      # Ensure we had a URL      # -    if ( @test_data[:target_host].nil? ) +    if ( @test_data["target_host"].nil? )        @error = "Missing URL for the test"        return false      end @@ -56,27 +56,27 @@ class HTTPTest      #  Do the fetch, if this success then we'll have the      # @status + @text setup      # -    if ( getURL (@test_data[:target_host] ) ) +    if ( getURL (@test_data["target_host"] ) )        #        #  Do we need to test for a HTTP status code?        # -      if ( @test_data[:http_status] ) -        puts "Testing for HTTP status code: #{@test_data[:http_status]}" +      if ( @test_data["http_status"] ) +        puts "Testing for HTTP status code: #{@test_data['http_status']}" -        if ( @status != @test_data[:http_status].to_i) -          @error = "#{@error} status code was #{@status} not #{@test_data[:http_status]}" +        if ( @status != @test_data['http_status'].to_i) +          @error = "#{@error} status code was #{@status} not #{@test_data['http_status']}"          end        end        #        #  Do we need to search for text in the body of the reply?        # -      if ( @test_data[:http_text] ) -        puts "Testing for text in the response: #{@test_data[:http_text]}" +      if ( @test_data['http_text'] ) +        puts "Testing for text in the response: #{@test_data['http_text']}" -        if (! @body.match(/#{@test_data[:http_text]}/i) ) -          @error = "#{@error} The respond did not contain #{test_data[:http_text]}" +        if (! @body.match(/#{@test_data['http_text']}/i) ) +          @error = "#{@error} The respond did not contain #{test_data['http_text']}"          end        end @@ -154,12 +154,12 @@ if __FILE__ == $0 then    #  Sample data.    #    test = { -    :target_host => "http://www.steve.org.uk/", -    :test_type   => "http", -    :test_port   => 80, -    :test_alert  => "Steve's website is unavailable", -    :http_text   => "Steve Kemp", -    :http_status => "200" +    "target_host" => "http://www.steve.org.uk/", +    "test_type"   => "http", +    "test_port"   => 80, +    "test_alert"  => "Steve's website is unavailable", +    "http_text"   => "Steve Kemp", +    "http_status" => "200"    } diff --git a/worker/tests/https.rb b/worker/tests/https.rb index 2575a35..8aff360 100755 --- a/worker/tests/https.rb +++ b/worker/tests/https.rb @@ -46,7 +46,7 @@ class HTTPSTest      #      # Ensure we had a URL      # -    if ( @test_data[:target_host].nil? ) +    if ( @test_data["target_host"].nil? )        @error = "Missing URL for the test"        return false      end @@ -56,27 +56,27 @@ class HTTPSTest      #  Do the fetch, if this success then we'll have the      # @status + @text setup      # -    if ( getURL (@test_data[:target_host] ) ) +    if ( getURL (@test_data["target_host"] ) )        #        #  Do we need to test for a HTTP status code?        # -      if ( @test_data[:http_status] ) -        puts "Testing for HTTP status code: #{@test_data[:http_status]}" +      if ( @test_data["http_status"] ) +        puts "Testing for HTTP status code: #{@test_data['http_status']}" -        if ( @status != @test_data[:http_status].to_i) -          @error = "#{@error} status code was #{@status} not #{@test_data[:http_status]}" +        if ( @status != @test_data['http_status'].to_i) +          @error = "#{@error} status code was #{@status} not #{@test_data['http_status']}"          end        end        #        #  Do we need to search for text in the body of the reply?        # -      if ( @test_data[:http_text] ) -        puts "Testing for text in the response: #{@test_data[:http_text]}" +      if ( @test_data['http_text'] ) +        puts "Testing for text in the response: #{@test_data['http_text']}" -        if (! @body.match(/#{@test_data[:http_text]}/i) ) -          @error = "#{@error} The respond did not contain #{test_data[:http_text]}" +        if (! @body.match(/#{@test_data['http_text']}/i) ) +          @error = "#{@error} The respond did not contain #{test_data['http_text']}"          end        end @@ -154,19 +154,19 @@ if __FILE__ == $0 then    #  Sample data.    #    test = { -    :target_host => "http://www.steve.org.uk/", -    :test_type   => "http", -    :test_port   => 80, -    :test_alert  => "Steve's website is unavailable", -    :http_text   => "Steve Kemp", -    :http_status => "200" +    "target_host" => "http://www.steve.org.uk/", +    "test_type"   => "http", +    "test_port"   => 80, +    "test_alert"  => "Steve's website is unavailable", +    "http_text"   => "Steve Kemp", +    "http_status" => "200"    }    #    #  Run the test.    # -  http = HTTPTest.new( test ) +  http = HTTPSTest.new( test )    if ( http.run_test )      puts "TEST OK"    else diff --git a/worker/worker b/worker/worker index 0b909ed..ff3b18c 100755 --- a/worker/worker +++ b/worker/worker @@ -58,6 +58,9 @@ class Alert    #    def raise +    puts "RAISE" +    return +      update = Mauve::Proto::AlertUpdate.new      update.alert   = []      update.source  = "custodian" @@ -78,6 +81,9 @@ class Alert    #  Clear the alert.    #    def clear +    puts "CLEAR" +    return +      update = Mauve::Proto::AlertUpdate.new      update.alert   = []      update.source  = "custodian" @@ -207,13 +213,26 @@ class Custodian        #        alert = Alert.new( hash ) + +      # +      # Conver the type to a className +      # +      clazz = test.upcase +      clazz = "#{clazz}Test" + +      # +      # Create the test object. +      # +      obj =  eval(clazz).new( hash ) + +        #        #  We'll run no more than MAX times.        #        #  We stop the execution on a single success.        #        while ( ( count < @retry_count ) && ( success == false ) ) -        if ( send( method, hash ) ) +        if ( obj.run_test() )            alert.clear()            success= true          end @@ -224,6 +243,9 @@ class Custodian        #  If we didn't succeed on any of the attempts raise the alert.        #        if ( ! success ) + +        # save the error message +        hash['error'] = obj.error()          alert.raise()        end      rescue => ex | 
