traceroute53 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/traceroute53 +137 -42
- data/lib/traceroute53/version.rb +1 -1
- data/traceroute53.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28f6329049a2d8052963a9603c76df33bc2e3d7269965482ac208082ceb400aa
|
4
|
+
data.tar.gz: 12171a9dfa1ab2194515a5714e34328e51c05bcb6666eb66198b8cf41fd8e91e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d4f5b97ef01d36047f518d6e64bc5fb170b474705f9f61bfcbe34f3ad4cfebf3157f7fc7033f8c20815eabc7a47069c143e0507f1b26d5b8aa95fdf4c08f9bc
|
7
|
+
data.tar.gz: 056376ff291ac576f88545fdd32acd0cef864f354bde6f707c6c621e21ac2c998dfbc70f57f45975dbc3f8e5c6674ee1fd95c1969fa6b1807169e49343c5735c
|
data/exe/traceroute53
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Trace route53 and Load Balancers related to the given domain
|
3
3
|
require 'aws-sdk-route53'
|
4
|
+
require 'aws-sdk-elasticloadbalancing'
|
4
5
|
require 'aws-sdk-elasticloadbalancingv2'
|
5
6
|
require 'aws-sdk-ec2'
|
6
7
|
require 'optparse'
|
@@ -43,11 +44,27 @@ def list_resource_record_sets(client, hosted_zone)
|
|
43
44
|
records
|
44
45
|
end
|
45
46
|
|
46
|
-
def describe_load_balancers(client)
|
47
|
+
def describe_load_balancers(client, name)
|
47
48
|
marker = nil
|
48
49
|
load_balancers = []
|
49
50
|
loop do
|
50
51
|
resp = client.describe_load_balancers({
|
52
|
+
load_balancer_names: [name],
|
53
|
+
marker: marker,
|
54
|
+
})
|
55
|
+
load_balancers.concat resp.load_balancer_descriptions
|
56
|
+
marker = resp.next_marker
|
57
|
+
break unless marker
|
58
|
+
end
|
59
|
+
load_balancers
|
60
|
+
end
|
61
|
+
|
62
|
+
def describe_load_balancersv2(client, name)
|
63
|
+
marker = nil
|
64
|
+
load_balancers = []
|
65
|
+
loop do
|
66
|
+
resp = client.describe_load_balancers({
|
67
|
+
names: [name],
|
51
68
|
marker: marker,
|
52
69
|
})
|
53
70
|
load_balancers.concat resp.load_balancers
|
@@ -72,6 +89,21 @@ def describe_listeners(client, load_balancer)
|
|
72
89
|
listeners
|
73
90
|
end
|
74
91
|
|
92
|
+
def describe_rules(client, listener)
|
93
|
+
marker = nil
|
94
|
+
rules = []
|
95
|
+
loop do
|
96
|
+
resp = client.describe_rules({
|
97
|
+
listener_arn: listener.listener_arn,
|
98
|
+
marker: marker,
|
99
|
+
})
|
100
|
+
rules.concat resp.rules
|
101
|
+
marker = resp.next_marker
|
102
|
+
break unless marker
|
103
|
+
end
|
104
|
+
rules
|
105
|
+
end
|
106
|
+
|
75
107
|
def describe_target_groups(client, target_group_arns)
|
76
108
|
marker = nil
|
77
109
|
target_groups = []
|
@@ -170,7 +202,7 @@ def main
|
|
170
202
|
end
|
171
203
|
dns_name = records[0].alias_target.dns_name
|
172
204
|
puts "dns name: #{dns_name}"
|
173
|
-
if
|
205
|
+
if /\.elb\.(?:[a-z0-9\-]+\.)?amazonaws.com\.\z/ =~ dns_name
|
174
206
|
break
|
175
207
|
end
|
176
208
|
domain_dot = dns_name
|
@@ -178,63 +210,126 @@ def main
|
|
178
210
|
dns_name.sub!(/\Adualstack\./, '')
|
179
211
|
dns_name.chomp!('.')
|
180
212
|
|
181
|
-
|
182
|
-
|
183
|
-
region: region,
|
184
|
-
profile: profile,
|
185
|
-
)
|
186
|
-
load_balancers = describe_load_balancers(client)
|
187
|
-
if load_balancers.empty?
|
188
|
-
STDERR.puts "load balancers not found in #{region} for #{dns_name}"
|
213
|
+
unless /([a-z0-9\-]+)?\.elb\.(?:([a-z0-9\-]+)\.)?amazonaws.com\z/ =~ dns_name
|
214
|
+
STDERR.puts "dns_name:#{dns_name} doesn't include AWS region name"
|
189
215
|
exit 1
|
190
216
|
end
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
217
|
+
region = $2 || $1
|
218
|
+
|
219
|
+
name = dns_name[/\A([a-z0-9\-]+)-\h+\./, 1]
|
220
|
+
puts "Load Balancer name is '#{name}'"
|
221
|
+
|
222
|
+
instance_ids = nil
|
223
|
+
begin
|
224
|
+
# Aws::ElasticLoadBalancingV2 (Application Load Balancer or Network Load Balancer)
|
225
|
+
client = Aws::ElasticLoadBalancingV2::Client.new(
|
226
|
+
region: region,
|
227
|
+
profile: profile,
|
228
|
+
)
|
229
|
+
load_balancers = describe_load_balancersv2(client, name)
|
230
|
+
# it raises LoadBalancerNotFound exception if not found
|
231
|
+
load_balancer = load_balancers.find{|lb| lb.dns_name == dns_name}
|
232
|
+
puts "load balancer: #{load_balancer.load_balancer_name} #{load_balancer.security_groups}"
|
233
|
+
|
234
|
+
listeners = describe_listeners(client, load_balancer)
|
235
|
+
if listeners.empty?
|
236
|
+
STDERR.puts "listeners not found in #{region} for #{load_balancer}"
|
237
|
+
exit 1
|
195
238
|
end
|
196
|
-
STDERR.puts "load balancers not found in #{region} for #{dns_name}"
|
197
|
-
exit 1
|
198
|
-
end
|
199
|
-
puts "load balancer: #{load_balancer.load_balancer_name} #{load_balancer.security_groups}"
|
200
239
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
240
|
+
instance_ids = []
|
241
|
+
target_group_arns = {}
|
242
|
+
listeners.each_with_index do |listener, i|
|
243
|
+
# p listener
|
244
|
+
puts "listener[#{i}]: port:#{listener.port} #{listener.listener_arn}"
|
245
|
+
rules = describe_rules(client, listener)
|
246
|
+
rules.each_with_index do |rule, j|
|
247
|
+
puts "listener[#{i}]rule[#{j}]: #{rule.rule_arn}#{rule.is_default ? ' (default)' : ''}"
|
248
|
+
rule.conditions.each_with_index do |condition, k|
|
249
|
+
puts "listener[#{i}]rule[#{j}]condition[#{k}]: #{condition.values}"
|
250
|
+
end
|
251
|
+
rule.actions.each_with_index do |action, k|
|
252
|
+
puts "listener[#{i}]rule[#{j}]action[#{k}]: #{action.type} #{action.target_group_arn}"
|
253
|
+
if target_group_arns[action.target_group_arn]
|
254
|
+
puts "listener[#{i}]rule[#{j}]action[#{k}]: the target group is already showed; skip"
|
255
|
+
else
|
256
|
+
target_group_arns[action.target_group_arn] = true
|
257
|
+
target_healths = describe_target_health(client, action.target_group_arn)
|
258
|
+
target_healths.each_with_index do |health, l|
|
259
|
+
puts "listener[#{i}]rule[#{j}]action[#{k}]target[#{l}]: #{health.target.id}:#{health.target.port} #{health.target_health.state}"
|
260
|
+
instance_ids << health.target.id
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
instance_ids
|
267
|
+
|
268
|
+
# p target_group_arns
|
269
|
+
# target_groups = describe_target_groups(client, target_group_arns)
|
270
|
+
# if target_groups.empty?
|
271
|
+
# STDERR.puts "target groups not found in #{region} for #{listeners}"
|
272
|
+
# exit 1
|
273
|
+
# end
|
274
|
+
# p target_groups
|
275
|
+
|
276
|
+
unless instance_ids
|
277
|
+
STDERR.puts "load balancers not found in #{region} for #{dns_name} with ELBv2"
|
278
|
+
# exit 1
|
279
|
+
end
|
280
|
+
rescue Aws::ElasticLoadBalancingV2::Errors::LoadBalancerNotFound
|
281
|
+
STDERR.puts "load balancers not found in #{region} for #{dns_name} with ELBv2"
|
205
282
|
end
|
206
283
|
|
207
|
-
instance_ids
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
284
|
+
unless instance_ids
|
285
|
+
# Aws::ElasticLoadBalancing (Classic Load Balancer)
|
286
|
+
client = Aws::ElasticLoadBalancing::Client.new(
|
287
|
+
region: region,
|
288
|
+
profile: profile,
|
289
|
+
)
|
290
|
+
load_balancers = describe_load_balancers(client, name)
|
291
|
+
if load_balancers.empty?
|
292
|
+
STDERR.puts "load balancers not found in #{region} for #{dns_name}"
|
293
|
+
exit 1
|
294
|
+
end
|
295
|
+
|
296
|
+
load_balancer = load_balancers.find{|lb| lb.dns_name == dns_name}
|
297
|
+
instance_ids = []
|
298
|
+
unless load_balancer
|
299
|
+
load_balancers.each_with_index do |lb, i|
|
300
|
+
STDERR.puts "load balancer[#{i}]: #{lb.dns_name}"
|
217
301
|
end
|
302
|
+
STDERR.puts "load balancers not found in #{region} for #{dns_name}"
|
303
|
+
exit 1
|
218
304
|
end
|
219
|
-
end
|
220
305
|
|
221
|
-
|
222
|
-
|
223
|
-
# if target_groups.empty?
|
224
|
-
# STDERR.puts "target groups not found in #{region} for #{listeners}"
|
225
|
-
# exit 1
|
226
|
-
# end
|
227
|
-
# p target_groups
|
306
|
+
load_balancer = load_balancers[0]
|
307
|
+
puts "load balancer: #{load_balancer.load_balancer_name} #{load_balancer.security_groups}"
|
228
308
|
|
309
|
+
load_balancer.instances.each_with_index do |instance, i|
|
310
|
+
puts "instances[#{i}]: #{instance[:instance_id]}"
|
311
|
+
instance_ids << instance[:instance_id]
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
# Inspect Security Group
|
229
316
|
client = Aws::EC2::Client.new(
|
230
317
|
region: region,
|
231
318
|
profile: profile,
|
232
319
|
)
|
233
320
|
instances = describe_instances(client, instance_ids)
|
234
|
-
|
321
|
+
group_ids_hash = {}
|
322
|
+
instances.each do |instance|
|
323
|
+
group_ids = instance.security_groups.map(&:group_id)
|
324
|
+
group_ids_hash[group_ids] ||= []
|
325
|
+
group_ids_hash[group_ids] << instance.instance_id
|
326
|
+
end
|
235
327
|
|
236
|
-
|
328
|
+
# Assume that instances under an ELB have the same security groups.
|
329
|
+
# If they are varied, something weird is happening and it needs further investigation...
|
330
|
+
group_ids_hash.each_pair.with_index do |(group_ids, instance_ids), i|
|
237
331
|
puts "group_ids[#{i}]: #{group_ids}"
|
332
|
+
puts "group_ids[#{i}]: #{instance_ids}"
|
238
333
|
security_groups = describe_security_groups(client, group_ids)
|
239
334
|
security_groups.each_with_index do |sg, j|
|
240
335
|
puts "group_ids[#{i}]sg[#{j}]: #{sg.group_id}"
|
data/lib/traceroute53/version.rb
CHANGED
data/traceroute53.gemspec
CHANGED
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.require_paths = ["lib"]
|
38
38
|
|
39
39
|
spec.add_dependency 'aws-sdk-route53', "~> 1"
|
40
|
+
spec.add_dependency 'aws-sdk-elasticloadbalancing', "~> 1"
|
40
41
|
spec.add_dependency 'aws-sdk-elasticloadbalancingv2', "~> 1"
|
41
42
|
spec.add_dependency 'aws-sdk-ec2', "~> 1"
|
42
43
|
spec.add_development_dependency "bundler", "~> 1.17"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traceroute53
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NARUSE, Yui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-route53
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-elasticloadbalancing
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: aws-sdk-elasticloadbalancingv2
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|