diff options
| author | Steve Kemp <steve@steve.org.uk> | 2015-01-13 16:14:56 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2015-01-13 16:14:56 +0000 | 
| commit | 7991f9a5ffc4d09209bf0431c188106a88cd8258 (patch) | |
| tree | 08a83ee3bf5abeb1f77b0276f4918a6f68668c92 | |
| parent | d81e114a3c4a5ffe2c89819f335c4a040704c239 (diff) | |
Updated to actually test the backend MX servers.
We now connec to the MX-servers via XX:25 and alert if that
fails.:wq
| -rw-r--r-- | lib/custodian/protocoltest/mx.rb | 53 | 
1 files changed, 50 insertions, 3 deletions
diff --git a/lib/custodian/protocoltest/mx.rb b/lib/custodian/protocoltest/mx.rb index ed46c4c..8b415ec 100644 --- a/lib/custodian/protocoltest/mx.rb +++ b/lib/custodian/protocoltest/mx.rb @@ -88,10 +88,57 @@ module Custodian            return false          end -        mx.each do |bob| -          puts "XXXX #{bob}" + +        # +        #  For each host we must make a connection. +        # +        #  We'll keep count of failures. +        # +        failed = 0 +        passed = 0 +        error  = "" + +        mx.each do |backend| + +          begin +            timeout(period) do +              begin +                socket = TCPSocket.new( backend, 25 ) +                read = socket.sysread(1024) + +                # trim to a sane length & strip newlines. +                if ( ! read.nil? ) +                  read = read[0,255] +                  read.gsub!(/[\n\r]/, "") +                end + +                if ( read =~ /^220/ ) +                  passed += 1 +                else +                  failed += 1 +                end +              rescue +                # Failure to connect. +                failed +=1 +                error += "Error connecting to #{backend}:25. " +              end +            end +          rescue Timeout::Error => ex +            # Timeout +            failed +=1 +            error += "Timeout connecting to #{backend}:25. " +          end +        end + +        # +        #  At this point we should have tested the things +        # +        if ( failed > 0 ) +          @error = "There are #{mx.size} hosts running as MX-servers for domain #{@host} - #{passed}:OK #{failed}:FAILED - #{error}" +          return false +        else +          return true;          end -        return true;        end  | 
