dogell 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 904b319cf24cd941086860caf531fba547c5c848
4
+ data.tar.gz: c62f72c221aebeef87d87d52eaa29c6f92956a65
5
+ SHA512:
6
+ metadata.gz: adbb803d025099bfdc3eca2b90bd6df4c7a0682b4f317b93c48b60721b109b75ded78a22cb5db69583f9aa10006d1432310580eb7663798721eb57d46052abd3
7
+ data.tar.gz: 5d09d1f7d5fdf98bf2ed46a7db90eb704f89c787404c4f9354a59691f0c5fe6f1ac16755585d8a792ed6f3b19180713cf026c177f94e1fcdc78ae5a5e17034c9
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .byebug_history
13
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in dogell.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dogell (0.0.3)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ net-ssh (5.0.2)
11
+ net-ssh-gateway (2.0.0)
12
+ net-ssh (>= 4.0.0)
13
+ net-ssh-multi (1.2.1)
14
+ net-ssh (>= 2.6.5)
15
+ net-ssh-gateway (>= 1.2.0)
16
+ rake (10.5.0)
17
+ rspec (3.7.0)
18
+ rspec-core (~> 3.7.0)
19
+ rspec-expectations (~> 3.7.0)
20
+ rspec-mocks (~> 3.7.0)
21
+ rspec-core (3.7.1)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-expectations (3.7.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-mocks (3.7.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.7.0)
29
+ rspec-support (3.7.1)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.16)
36
+ dogell!
37
+ net-ssh-multi (~> 1.2.1)
38
+ rake (~> 10.0)
39
+ rspec (~> 3.0)
40
+
41
+ BUNDLED WITH
42
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+
2
+ # Dogell
3
+
4
+ Dogell let's you run commands on multiple servers querying by your host tags in your Datadog Infrastructure
5
+
6
+
7
+ ## Installation
8
+
9
+ To run this script you must have a ruby installed in your machine.
10
+
11
+ After that, you can install from RubyGems
12
+
13
+ ```bash
14
+ gem install dogell
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ To start using dogell you need a Datadog `API_KEY` and `APP_KEY`, after that you can set the keys as environment variables:
20
+
21
+ ```bash
22
+ export DATADOG_APP_KEY=my_secret_app_key
23
+ export DATADOG_API_KEY=my_secret_api_key
24
+ ```
25
+
26
+ Or set with the dogell options in each command:
27
+
28
+ ```bash
29
+ dogell -t name:some-app -u my_user -c 'hostname' --api-key my_secret_api_key --app-key my_secret_app_key
30
+ ```
31
+ Dogell use Datadog host tags to query the servers with the `-t`/ `--tag` flags, to know more just type `dogell -h`
32
+
33
+ ## TODO
34
+
35
+ 1. Transform this project into a gem
36
+ 2. Separate concerns
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/catks/dogell
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dogell"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dogell.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dogell/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dogell"
8
+ spec.version = Dogell::VERSION
9
+ spec.authors = ["Carlos Atkinson"]
10
+ spec.email = ["carlos.atks@gmail.com"]
11
+
12
+ spec.summary = %q{Run commands on multiple servers in your Datadog Infrastructure}
13
+ spec.homepage = "https://github.com/catks/dogell"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "net-ssh-multi", "~> 1.2.1"
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
data/exe/dogell ADDED
@@ -0,0 +1,90 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'net/ssh/multi'
4
+ require 'optparse'
5
+ require 'dogell/version'
6
+
7
+ API_KEY = ENV['DATADOG_API_KEY']
8
+ APP_KEY = ENV['DATADOG_APP_KEY']
9
+
10
+
11
+ def verify_options!(options)
12
+ error('Error: Missing user "-u my_user"') unless options[:user]
13
+ error('Error: Missing tag "-t some_tag:example" or hosts "-h 10.0.0.1,my_domain.intra"') unless options[:tag] || options[:hosts]
14
+ error('Error: Missing command "-c some_command"') unless options[:command]
15
+ error('Error: Missing Datadog API KEY set with DATADOG_API_KEY environment variable or with "--api-key my_key"') unless options[:api_key] || options[:hosts]
16
+ error('Error: Missing Datadog API KEY set with DATADOG_APP_KEY environment variable or with "--app-key my_key"') unless options[:app_key] || options[:hosts]
17
+ end
18
+
19
+ def error(message)
20
+ $stderr.puts message
21
+ exit 1
22
+ end
23
+
24
+ def get_servers_ips(api_key,app_key,tag)
25
+ uri = URI("https://app.datadoghq.com/reports/v2/overview?api_key=#{api_key}&application_key=#{app_key}&tags=#{tag}&with_meta=true")
26
+ response = Net::HTTP.get_response(uri)
27
+ JSON.parse(response.body)['rows'].map { |server| JSON.parse(server['meta']['gohai'])['network']['ipaddress'] }
28
+ end
29
+
30
+ options = {
31
+ app_key: APP_KEY,
32
+ api_key: API_KEY
33
+ }
34
+
35
+ OptionParser.new do |opts|
36
+ opts.banner = <<-BANNER
37
+ Dogell - Run commands in multiple servers querying by your Datadog Infrastructure
38
+
39
+ Usage: dogell -t some_tag:some_value -u ssh_user -c some_command
40
+
41
+ BANNER
42
+
43
+ opts.on("-t", "--tag TAG",
44
+ "Datadog tags to search servers") do |tag|
45
+ options[:tag] = tag
46
+ end
47
+
48
+ opts.on("--hosts 'some.domain,10.0.0.1'",
49
+ "specify the hosts to run the command(Separated by `,`)") do |hosts|
50
+ options[:hosts] = hosts.split(',')
51
+ end
52
+
53
+ opts.on("-c", "--command COMMAND", "Command to run in the servers") do |command|
54
+ options[:command] = command
55
+ end
56
+
57
+ opts.on("-u", "--user USER", "User to connect in the servers") do |user|
58
+ options[:user] = user
59
+ end
60
+
61
+ opts.on("-v", "--version", "Shows dogell version") do
62
+ puts Dogell::VERSION
63
+ exit
64
+ end
65
+
66
+ opts.on("--api-key API_KEY", "Sets the Datadog API key") do |api_key|
67
+ options[:api_key] = api_key
68
+ end
69
+
70
+ opts.on("--app-key APP_KEY", "Sets the Datadog APP key") do |app_key|
71
+ options[:app_key] = app_key
72
+ end
73
+
74
+ opts.on_tail("-h", "--help", "Show this message") do
75
+ puts opts
76
+ exit
77
+ end
78
+ end.parse!
79
+
80
+ verify_options!(options)
81
+
82
+ servers = options[:hosts] || get_servers_ips(options[:api_key], options[:app_key], options[:tag])
83
+
84
+ Net::SSH::Multi.start do |session|
85
+ servers.each do |server|
86
+ session.use(options[:user] ? "#{options[:user]}@#{server}" : server)
87
+ end
88
+
89
+ session.exec options[:command]
90
+ end
data/lib/dogell.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "dogell/version"
2
+
3
+ module Dogell
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Dogell
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dogell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Atkinson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh-multi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - carlos.atks@gmail.com
72
+ executables:
73
+ - dogell
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - dogell.gemspec
88
+ - exe/dogell
89
+ - lib/dogell.rb
90
+ - lib/dogell/version.rb
91
+ homepage: https://github.com/catks/dogell
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.8
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Run commands on multiple servers in your Datadog Infrastructure
115
+ test_files: []