From 540baef644ae843bf44c36c5149a1d095a9a039a Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Tue, 20 Nov 2012 10:01:57 +0000 Subject: Removed DNS lookup --- lib/custodian/alerter.rb | 70 ++++++------------------------------------------ 1 file changed, 8 insertions(+), 62 deletions(-) diff --git a/lib/custodian/alerter.rb b/lib/custodian/alerter.rb index 6ac4fe5..e70ad0d 100644 --- a/lib/custodian/alerter.rb +++ b/lib/custodian/alerter.rb @@ -1,10 +1,11 @@ +require 'custodian/dnsutil' require 'mauve/sender' require 'mauve/proto' + require 'ipaddr' -require 'socket' @@ -27,27 +28,6 @@ class Alerter end - # - # Return the reverse DNS for the specified IP address, nil on failure. - # - def resolve_ip( target ) - resolved = nil - begin - timeout( 4 ) do - begin - Socket.getaddrinfo(target, 'echo').each do |a| - resolved = a[2] if ( a ) - end - rescue SocketError - resolved = nil - end - end - rescue Timeout::Error => e - resolved = nil - end - resolved - end - @@ -75,22 +55,10 @@ class Alerter ( target =~ /^([0-9a-f:]+)$/ ) ) resolved = target else - begin - timeout( 4 ) do - - begin - Socket.getaddrinfo(target, 'echo').each do |a| - resolved = a[3] if ( a ) - end - rescue SocketError - resolved = nil - end - end - rescue Timeout::Error => e - resolved = nil - end + resolved = DNSUtil.hostname_to_ip( target ) end + # # Did we get an error? # @@ -130,28 +98,6 @@ class Alerter end - # - # Resolve an IP address - # - def document_address( address ) - - raise ArgumentError, "Address must not be nil" if ( address.nil? ) - - begin - timeout( 4 ) do - begin - Resolv.new.getname(address) - rescue - nil - end - end - rescue Timeout::Error => e - resolved = nil - end - end - - - # # Raise the alert. # @@ -171,7 +117,7 @@ class Alerter subject = @details['target_host'] if ( ( subject =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || ( subject =~ /^([0-9a-f:]+)$/ ) ) - res = resolve_ip( subject ) + res = DNSUtil.ip_to_hostname( subject ) if ( res ) subject = "#{subject} [#{res}]" @@ -187,7 +133,7 @@ class Alerter if ( ( @details["target_host"] =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || ( @details["target_host"] =~ /^([0-9a-f:]+)$/ ) ) - resolved = document_address( @details["target_host"] ) + resolved = DNSUtil.ip_to_hostname( @details["target_host"] ) if ( resolved.nil? ) resolved = "" else @@ -237,7 +183,7 @@ class Alerter subject = @details['target_host'] if ( ( subject =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || ( subject =~ /^([0-9a-f:]+)$/ ) ) - res = resolve_ip( subject ) + res = DNSUtil.ip_to_hostname( subject ) if ( res ) subject = "#{subject} [#{res}]" @@ -252,7 +198,7 @@ class Alerter if ( ( @details["target_host"] =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || ( @details["target_host"] =~ /^([0-9a-f:]+)$/ ) ) - resolved = document_address( @details["target_host"] ) + resolved = DNSUtil.ip_to_hostname( @details["target_host"] ) if ( resolved.nil? ) resolved = "" else -- cgit v1.2.1