elbping 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/elbping/resolver.rb +24 -6
  2. metadata +33 -1
@@ -1,21 +1,39 @@
1
1
 
2
2
  require 'net/dns'
3
+ require 'ipaddress'
3
4
 
4
5
  module ElbPing
5
6
  module Resolver
6
- # Resolve an ELB address to a list of node IPs
7
- def self.find_elb_nodes(target, nameserver)
7
+ def self.resolve_ns(nameserver)
8
+ # Resolve nameserver IP (you can't just plug a hostname into Net::DNS::Resolve)
9
+ # Return an empty list if can't look up nameserver address
10
+ if IPAddress.valid? nameserver
11
+ ns_addrs = [nameserver]
12
+ else
13
+ begin
14
+ ns_addrs = Resolver(nameserver).answer.map { |rr| rr.address.to_s }
15
+ rescue
16
+ ns_addrs = []
17
+ end
18
+ end
19
+ end
8
20
 
9
- # First resolve our nameserver IP
10
- ns_addrs = Resolver(nameserver).answer.map { |rr| rr.address.to_s }
21
+ # Resolve an ELB address to a list of node IPs. Should always return a list
22
+ # as long as the server responded, even if it's empty.
23
+ def self.find_elb_nodes(target, nameserver)
24
+ ns_addrs = resolve_ns nameserver
11
25
 
12
26
  # Now resolve our ELB nodes
13
27
  resolver = Net::DNS::Resolver.new(
14
28
  :use_tcp => true,
15
29
  :nameservers => ns_addrs,
16
30
  :retry => 5)
17
-
18
- resp = resolver.query(target, Net::DNS::ANY)
31
+ begin
32
+ resp = resolver.query(target, Net::DNS::ANY)
33
+ rescue ArgumentError
34
+ # For some reason this is raised on timeout
35
+ raise "Error querying DNS: Probably a timeout"
36
+ end
19
37
 
20
38
  nodes = []
21
39
  resp.each_address { |a| nodes += [a.to_s] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elbping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.8.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.4
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: ipaddress
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.0
30
62
  description: elbping is a tool to ping all of the nodes behind an Amazon Elastic Load
31
63
  Balancer. It only works for ELBs in HTTP mode and works by triggering an HTTP 405
32
64
  (METHOD NOT ALLOWED) error caused when the ELB receives a HTTP verb that is too