awsm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e24a01866b9592580f781071d0930eb454b81a27
4
+ data.tar.gz: 5ae12ba51869dd5339f515f770bcf8b0b44470ef
5
+ SHA512:
6
+ metadata.gz: 72f890cb1c74a2a3913c7477be147e8cf40b2cb9e20e1d2d6cc59472d0bfa84f0ec966a363df41b9f865fca88ece6f839780da063235bd7b8b00ecb8bac8a8b5
7
+ data.tar.gz: 3a84fe176fdfe08a7b085dbd57ddbcea3e9e857626de1906d5915f0781a457063915d032c861d53a1ad58e97d75278abaac2f100ecc4e5210230ca3cbb673868
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .*.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in awsome.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Daniel Kendell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Awsm
2
+
3
+ Awsm is an awesome AWS querying tool. Pun most certainly intended.
4
+
5
+ ## Make it go!
6
+
7
+ Awsm is written in Ruby 2.1, so you'll need that to start with, you'll also need the `bundler` gem.
8
+
9
+ [you@host:~]$ git clone https://github.com/mduk/awsome
10
+ [you@host:~]$ cd awsome
11
+
12
+ Awsm requires four enviornment variables to be set in order to work. I use something like this:
13
+
14
+ #!/bin/bash
15
+
16
+ export AWS_ACCESS_KEY_ID="You do not leak keys on github."
17
+ export AWS_SECRET_ACCESS_KEY="You DO, NOT, LEAK, keys on github!"
18
+ export AWS_REGION="eu-west-1"
19
+ export AWSM_HOSTEDZONE="Don't leak this either."
20
+
21
+ echo -e "\033[1m\033[92mAWS Environment Set.\033[0m"
22
+
23
+ Once you have that in place, install dependencies.
24
+
25
+ [you@host:~/awsome]$ bundle install
26
+
27
+ Initialise environment variables.
28
+
29
+ [you@host:~/awsome]$ source ./setvars.sh
30
+ AWS Environment Set.
31
+
32
+ And off you go.
33
+
34
+ [you@host:~/awsome]$ bundle exec awsome search -dia beta
35
+
36
+
37
+ # Licence
38
+
39
+ See `LICENCE.txt` file.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'awsm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "awsm"
8
+ spec.version = Awsm::VERSION
9
+ spec.authors = ["Daniel Kendell"]
10
+ spec.email = ["daniel@kendell.org"]
11
+ spec.summary = %q{Awsm AWS queryer}
12
+ spec.description = File.open( 'README.md', 'rb' ).read
13
+ spec.homepage = "http://github.com/mduk/awsm"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = [ 'awsm' ]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'thor', '~> 0.19'
22
+ spec.add_runtime_dependency 'aws-sdk-core', '~> 2.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake", '~> 0'
26
+ spec.add_development_dependency "pry", '~> 0'
27
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'awsm'
4
+
5
+ Awsm::Cli.start( ARGV )
6
+
@@ -0,0 +1,9 @@
1
+ require "awsm/version"
2
+ require "awsm/loadbalancers"
3
+ require "awsm/autoscalinggroups"
4
+ require "awsm/dns"
5
+ require "awsm/instances"
6
+ require "awsm/cli"
7
+
8
+ module Awsm
9
+ end
@@ -0,0 +1,28 @@
1
+ module Awsm
2
+ class AutoScalingGroups
3
+ def initialize
4
+ @client = Aws::AutoScaling::Client.new
5
+ @asg_map = {}
6
+ load_auto_scaling_groups
7
+ end
8
+
9
+ def find_for( elb_name )
10
+ @asg_map[ elb_name ]
11
+ end
12
+
13
+ def load_auto_scaling_groups
14
+ @client.describe_auto_scaling_groups.each_page do |p|
15
+ p.auto_scaling_groups.map do |asg|
16
+ asg.load_balancer_names.each do |elb_name|
17
+ @asg_map[elb_name] = [] if @asg_map[elb_name].nil?
18
+ @asg_map[elb_name] << {
19
+ asg_name: asg.auto_scaling_group_name,
20
+ instances: asg.instances.map{ |i| i.to_h },
21
+ instance_ids: asg.instances.map { |i| i.instance_id }
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,147 @@
1
+ require 'thor'
2
+
3
+ module Awsm
4
+ class Cli < Thor
5
+ class_option :instances, :type => :boolean, :default => false, :aliases => "-i",
6
+ :desc => "Also show instance information. Including ID, Private IP, and current health."
7
+ class_option :dns, :type => :boolean, :default => false, :aliases => "-d",
8
+ :desc => "Check if there are any Route53 records pointing at this Load Balancer"
9
+ class_option :asg, :type => :boolean, :default => false, :aliases => "-a",
10
+ :desc => "Show Auto Scaling Groups that are receiving traffic from this Load Balancer"
11
+
12
+ desc "specific <comma-separated-elb-names>",
13
+ "Only find specific ELBs named in a comma-separated list."
14
+ def specific( elb_names )
15
+ results = load_balancers.get(elb_names)
16
+ results = do_options( results )
17
+ results.each { |elb| print_result(elb) }
18
+ end
19
+
20
+ desc "search <search-terms>",
21
+ "Show ELBs where the name matches the search terms."
22
+ def search( search_terms )
23
+ results = load_balancers.getAll.select { |combined| combined[:elb][:name] =~ /#{search_terms}/ }
24
+ results = do_options( results )
25
+ results.each { |elb| print_result(elb) }
26
+ end
27
+
28
+ no_commands do
29
+ def load_balancers
30
+ Awsm::LoadBalancers.new
31
+ end
32
+
33
+ def instances
34
+ Awsm::Instances.new
35
+ end
36
+
37
+ def dns
38
+ Awsm::Dns.new
39
+ end
40
+
41
+ def asg
42
+ Awsm::AutoScalingGroups.new
43
+ end
44
+
45
+ def do_options( results )
46
+ if options[:instances]
47
+ results.map do |combined|
48
+ instance_data = Awsm::Instances.new.get_instance_data( combined[:elb_instance_ids] )
49
+ combined[:instances] = instance_data
50
+ end
51
+ say "Added instance data", :white
52
+ end
53
+
54
+ if options[:dns]
55
+ results.map do |combined|
56
+ elb_dns = combined[:elb][:dns]
57
+ r53_dns = dns.find_for( elb_dns )
58
+ combined[:r53_dns] = r53_dns
59
+ end
60
+ say "Added dns data", :white
61
+ end
62
+
63
+ if options[:asg]
64
+ results.map do |combined|
65
+ elb_name = combined[:elb][:name]
66
+ asgs = asg.find_for( elb_name )
67
+ combined[:asgs] = asgs
68
+ end
69
+ end
70
+
71
+ results
72
+ end
73
+
74
+ def print_result(result)
75
+ say result[:elb][:name], :green, false
76
+ print ' <= '
77
+
78
+ # DNS
79
+ if result[:r53_dns].nil?
80
+ say result[:elb][:dns], :white, false
81
+ else
82
+ say result[:r53_dns], :bold, false
83
+ end
84
+
85
+ puts
86
+
87
+ # Load Balancer Tags
88
+ say " NO TAGS!", :red unless result[:elb][:tags].length > 0
89
+ say " Tags:" if result[:elb][:tags].length > 0
90
+ result[:elb][:tags].each do |k, v|
91
+ print ' '
92
+ say k, :cyan, false
93
+ print ' => '
94
+ say v, :yellow
95
+ end
96
+
97
+ if options[:instances]
98
+ say " Instances:"
99
+ result[:instances].each do |instance_and_id|
100
+ instance = instance_and_id[1]
101
+ print_instance( 12, instance )
102
+ end
103
+ end
104
+
105
+ # Auto Scaling Groups
106
+ if options[:asg]
107
+ say " Auto Scaling Groups:"
108
+ end
109
+ if options[:asg] and result[:asgs].nil?
110
+ say " No Auto Scaling Groups!", :red
111
+ end
112
+
113
+ if options[:asg] and !result[:asgs].nil?
114
+ result[:asgs].each do |asg|
115
+ enabled = result[:elb_instance_ids] & asg[:instance_ids]
116
+
117
+ if enabled.length > 0
118
+ say " >> #{asg[:asg_name]} (#{asg[:instances].length})", :magenta
119
+ else
120
+ say " #{asg[:asg_name]} (#{asg[:instances].length})", :magenta
121
+ end
122
+
123
+ if options[:instances]
124
+ asg[:instances].each do |asg_instance|
125
+ instance_id = asg_instance[:instance_id]
126
+ instance_health = asg_instance[:health_status]
127
+ instance_health_colour = ( instance_health == "Healthy" ? :green : :red )
128
+ instance_description = result[:instances][ instance_id ]
129
+ instance_ip = instance_description[:private_ip_address]
130
+ unless result[:instances][ instance_id ].nil?
131
+ say " #{instance_id} : #{instance_ip}", instance_health_colour
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ def print_instance( pad_length, instance )
140
+ padding = " " * pad_length
141
+ instance_id = instance[:instance_id]
142
+ instance_ip = instance[:private_ip_address]
143
+ say "#{padding}#{instance_id} : #{instance_ip}"
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,37 @@
1
+ require 'aws-sdk-core'
2
+
3
+ module Awsm
4
+ class Dns
5
+ def initialize
6
+ @client = Aws::Route53::Client.new
7
+ @dns_map = {}
8
+ load_dns_records
9
+ end
10
+
11
+ def find_for( target )
12
+ @dns_map[ target ]
13
+ end
14
+
15
+ def load_dns_records
16
+ paged_response = @client.list_resource_record_sets(
17
+ hosted_zone_id: ENV['AWSM_HOSTEDZONE']
18
+ )
19
+
20
+ paged_response.each_page do |p|
21
+ records = p.resource_record_sets.select do |r|
22
+ r.type == 'A' || r.type == 'CNAME'
23
+ end
24
+
25
+ records.each do |r|
26
+ if r.resource_records == []
27
+ target = r.alias_target.dns_name
28
+ else
29
+ target = r.resource_records[0].value
30
+ end
31
+
32
+ @dns_map[target] = r.name
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module Awsm
2
+ class Instances
3
+ def initialize
4
+ @client = Aws::EC2::Client.new
5
+ end
6
+
7
+ def get_instance_data( instance_ids )
8
+ descriptions = @client.describe_instances( {
9
+ filters: [
10
+ { name: "instance-id", values: instance_ids }
11
+ ]
12
+ } ).reservations.first.instances
13
+
14
+ instance_hash = {}
15
+ descriptions.each do |description|
16
+ instance_hash[ description.instance_id ] = description.to_h
17
+ end
18
+ instance_hash
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ module Awsm
2
+ class LoadBalancers
3
+ def initialize
4
+ @elb_client = Aws::ElasticLoadBalancing::Client.new
5
+ @asg_client = Aws::AutoScaling::Client.new
6
+ end
7
+
8
+ def get(elb_names)
9
+ processResponse(@elb_client.describe_load_balancers({
10
+ load_balancer_names: elb_names.split(',')
11
+ }))
12
+ end
13
+
14
+ def getAll
15
+ processResponse(@elb_client.describe_load_balancers)
16
+ end
17
+
18
+ private
19
+
20
+ def processResponse(pagableResponse)
21
+ elbs = []
22
+
23
+ pagableResponse.each_page do |p|
24
+ p.load_balancer_descriptions.each do |elb|
25
+ elbs << {
26
+ load_balancer_name: elb.load_balancer_name,
27
+ dns_name: elb.dns_name,
28
+ instance_ids: elb.instances.map { |i| i.instance_id }
29
+ }
30
+ end
31
+ end
32
+
33
+ combined = []
34
+ elbs.each do |elb|
35
+ result = {
36
+ elb: {
37
+ dns: elb[:dns_name],
38
+ name: elb[:load_balancer_name],
39
+ tags: getLoadBalancerTags( elb[:load_balancer_name] )
40
+ },
41
+ elb_instance_ids: elb[:instance_ids],
42
+ }
43
+
44
+ combined << result
45
+ end
46
+ combined
47
+ end
48
+
49
+ def getLoadBalancerTags(elb_name)
50
+ tags = {}
51
+ @elb_client.describe_tags( load_balancer_names: [ elb_name ] ).each_page do |p|
52
+ p.tag_descriptions.first.tags.each do |t|
53
+ tags[t.key] = t.value
54
+ end
55
+ end
56
+ tags
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,3 @@
1
+ module Awsm
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awsm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Kendell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: "# Awsm\n\nAwsm is an awesome AWS querying tool. Pun most certainly intended.\n\n##
84
+ Make it go!\n\nAwsm is written in Ruby 2.1, so you'll need that to start with, you'll
85
+ also need the `bundler` gem.\n\n\t[you@host:~]$ git clone https://github.com/mduk/awsome\n\t[you@host:~]$
86
+ cd awsome\n\nAwsm requires four enviornment variables to be set in order to work.
87
+ I use something like this:\n\n\t#!/bin/bash\n\n\texport AWS_ACCESS_KEY_ID=\"You
88
+ do not leak keys on github.\"\n\texport AWS_SECRET_ACCESS_KEY=\"You DO, NOT, LEAK,
89
+ keys on github!\"\n\texport AWS_REGION=\"eu-west-1\"\n\texport AWSM_HOSTEDZONE=\"Don't
90
+ leak this either.\"\n\n\techo -e \"\\033[1m\\033[92mAWS Environment Set.\\033[0m\"\n\nOnce
91
+ you have that in place, install dependencies.\n\n\t[you@host:~/awsome]$ bundle install\n\nInitialise
92
+ environment variables.\n\n\t[you@host:~/awsome]$ source ./setvars.sh\n\tAWS Environment
93
+ Set.\n\nAnd off you go.\n\n\t[you@host:~/awsome]$ bundle exec awsome search -dia
94
+ beta\n\n\n# Licence\n\nSee `LICENCE.txt` file.\n"
95
+ email:
96
+ - daniel@kendell.org
97
+ executables:
98
+ - awsm
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - ".gitignore"
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - awsm.gemspec
108
+ - bin/awsm
109
+ - lib/awsm.rb
110
+ - lib/awsm/autoscalinggroups.rb
111
+ - lib/awsm/cli.rb
112
+ - lib/awsm/dns.rb
113
+ - lib/awsm/instances.rb
114
+ - lib/awsm/loadbalancers.rb
115
+ - lib/awsm/version.rb
116
+ homepage: http://github.com/mduk/awsm
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Awsm AWS queryer
140
+ test_files: []
141
+ has_rdoc: