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 | ca9be00dc45d0a71210ad16423d6d319c87b6727 (patch) | |
tree | 5a00a2b2f7a37f3f6a89146dddc396218c1d4bd4 /lib | |
parent | 06c1e4db27ca6c68c694e35af651502b0da6086e (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
Diffstat (limited to 'lib')
-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 |