sensu-install 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e60eeb721d605d897f3e7a293a6bd305a1284cf
4
+ data.tar.gz: bda4f265c7d2f184aed6b1dace87b391eb8af489
5
+ SHA512:
6
+ metadata.gz: d3ab4a656fb6a7ce11ba19eaba75e4620cfbdc2b2e00d140bd79006c0c8984a84bfd776120bc9dfe6833b9e47607f30ea24f7f10bda34e168a509e0e0d213e29
7
+ data.tar.gz: 295272d4679ca7c6fc5d10f841e9ac0dc642288f7cd84e703cdc1e41ae90e44e6ccf3709dadc3391e902a6c7abfaf161863404990498d28c8dd674fa9e8fd347
@@ -0,0 +1,11 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
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 sensu-install.gemspec
6
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sensu-install (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.0)
32
+ sensu-install!
33
+
34
+ BUNDLED WITH
35
+ 1.16.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Sensu
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sean Porter
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.
@@ -0,0 +1,39 @@
1
+ # Sensu::Install
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sensu/install`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sensu-install'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sensu-install
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sensu-install.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sensu/install"
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__)
@@ -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
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "sensu/install"
4
+
5
+ Sensu::Install.run
@@ -0,0 +1,192 @@
1
+ require "sensu/install/version"
2
+ require "optparse"
3
+
4
+ module Sensu
5
+ module Install
6
+ class << self
7
+ def cli_options(arguments=ARGV)
8
+ options = {
9
+ :verbose => false,
10
+ :plugins => [],
11
+ :extensions => [],
12
+ :clean => false,
13
+ :proxy => nil
14
+ }
15
+ optparse = OptionParser.new do |opts|
16
+ opts.on("-h", "--help", "Display this message") do
17
+ puts opts
18
+ exit
19
+ end
20
+ opts.on("-v", "--verbose", "Enable verbose logging") do
21
+ options[:verbose] = true
22
+ end
23
+ opts.on("-p", "--plugin PLUGIN", "Install a Sensu PLUGIN") do |plugin|
24
+ options[:plugins] << plugin
25
+ end
26
+ opts.on("-P", "--plugins PLUGIN[,PLUGIN]", "PLUGIN or comma-delimited list of Sensu plugins to install") do |plugins|
27
+ options[:plugins].concat(plugins.split(","))
28
+ end
29
+ opts.on("-e", "--extension EXTENSION", "Install a Sensu EXTENSION") do |extension|
30
+ options[:extensions] << extension
31
+ end
32
+ opts.on("-E", "--extensions EXTENSION[,EXT]", "EXTENSION or comma-delimited list of Sensu extensions to install") do |extensions|
33
+ options[:extensions].concat(extensions.split(","))
34
+ end
35
+ opts.on("-s", "--source SOURCE", "Install Sensu plugins and extensions from a custom SOURCE") do |source|
36
+ options[:source] = source
37
+ end
38
+ opts.on("-c", "--clean", "Clean up (remove) other installed versions of the plugin(s) and/or extension(s)") do
39
+ options[:clean] = true
40
+ end
41
+ opts.on("-x", "--proxy PROXY", "Install Sensu plugins and extensions via a PROXY URL") do |proxy|
42
+ options[:proxy] = proxy
43
+ end
44
+ end
45
+ optparse.parse!(arguments)
46
+ options
47
+ end
48
+
49
+ def log(message)
50
+ puts "[SENSU-INSTALL] #{message}"
51
+ end
52
+
53
+ def gem_installed?(raw_gem, options={})
54
+ log "determining if Sensu gem '#{raw_gem}' is already installed ..."
55
+ gem_name, gem_version = raw_gem.split(":")
56
+ gem_command = "gem list -i #{gem_name}"
57
+ gem_command << " --version '#{gem_version}'" if gem_version
58
+ log gem_command if options[:verbose]
59
+ if system(gem_command)
60
+ log "Sensu gem '#{gem_name}' has already been installed"
61
+ true
62
+ else
63
+ log "Sensu gem '#{gem_name}' has not been installed" if options[:verbose]
64
+ false
65
+ end
66
+ end
67
+
68
+ def install_gem(raw_gem, options={})
69
+ log "installing Sensu gem '#{raw_gem}'"
70
+ gem_name, gem_version = raw_gem.split(":")
71
+ gem_command = "gem install #{gem_name}"
72
+ gem_command << " --version '#{gem_version}'" if gem_version
73
+ gem_command << " --no-ri --no-rdoc"
74
+ gem_command << " --verbose" if options[:verbose]
75
+ gem_command << " --source #{options[:source]}" if options[:source]
76
+ gem_command << " --http-proxy #{options[:proxy]}" if options[:proxy]
77
+ log gem_command if options[:verbose]
78
+ unless system(gem_command)
79
+ log "failed to install Sensu gem '#{gem_name}'"
80
+ log "you can run the sensu-install command again with --verbose for more info" unless options[:verbose]
81
+ log "please take note of any failure messages above"
82
+ log "make sure you have build tools installed (e.g. gcc)"
83
+ log "trying to determine the Sensu plugin homepage for #{gem_name} ..."
84
+ system("gem specification #{gem_name} -r | grep homepage")
85
+ exit 2
86
+ end
87
+ end
88
+
89
+ def gem_installed_versions(raw_gem, options={})
90
+ gem_name, gem_version = raw_gem.split(":")
91
+ log "determining installed versions of Sensu gem '#{gem_name}' ..."
92
+ gem_command = "gem list #{gem_name}"
93
+ log gem_command if options[:verbose]
94
+ gem_command_output = `#{gem_command}`
95
+ last_line = gem_command_output.split("\n").last
96
+ if last_line == "false"
97
+ []
98
+ else
99
+ /\((.*)\)/.match(last_line)[1].split(", ")
100
+ end
101
+ end
102
+
103
+ def clean_gem(raw_gem, options={})
104
+ log "cleaning Sensu gem '#{raw_gem}'"
105
+ gem_name, gem_version = raw_gem.split(":")
106
+ gem_command = "gem clean #{gem_name}"
107
+ if gem_version
108
+ if gem_installed_versions(raw_gem, options) == [gem_version]
109
+ log "Sensu gem '#{gem_name}' version '#{gem_version}' is the only version installed"
110
+ else
111
+ gem_command = "gem uninstall #{gem_name} --version '!= #{gem_version}' -a"
112
+ end
113
+ end
114
+ log gem_command if options[:verbose]
115
+ if system(gem_command)
116
+ log "successfully cleaned Sensu gem '#{gem_name}'"
117
+ else
118
+ log "failed to clean Sensu gem '#{gem_name}'"
119
+ end
120
+ end
121
+
122
+ def install_plugins(plugins, options={})
123
+ log "installing Sensu plugins ..."
124
+ log "provided Sensu plugins: #{plugins}" if options[:verbose]
125
+ plugin_gems = plugins.map do |plugin|
126
+ if plugin.start_with?("sensu-plugins-")
127
+ plugin
128
+ else
129
+ "sensu-plugins-#{plugin}"
130
+ end
131
+ end
132
+ log "compiled Sensu plugin gems: #{plugin_gems}" if options[:verbose]
133
+ to_be_installed = plugin_gems.reject do |raw_gem|
134
+ gem_installed?(raw_gem, options)
135
+ end
136
+ log "Sensu plugin gems to be installed: #{to_be_installed}"
137
+ to_be_installed.each do |raw_gem|
138
+ install_gem(raw_gem, options)
139
+ end
140
+ log "successfully installed Sensu plugins: #{to_be_installed}"
141
+ if options[:clean]
142
+ log "cleaning Sensu plugin gems: #{plugin_gems}" if options[:verbose]
143
+ plugin_gems.each do |raw_gem|
144
+ clean_gem(raw_gem, options)
145
+ end
146
+ end
147
+ end
148
+
149
+ def install_extensions(extensions, options={})
150
+ if ENV["EMBEDDED_RUBY"] == "false"
151
+ log "EMBEDDED_RUBY must be set to true in order to install extensions"
152
+ log "failed to install extensions: #{extensions}"
153
+ exit 2
154
+ end
155
+ log "installing Sensu extensions ..."
156
+ log "provided Sensu extensions: #{extensions}" if options[:verbose]
157
+ extension_gems = extensions.map do |extension|
158
+ if extension.start_with?("sensu-extensions-")
159
+ extension
160
+ else
161
+ "sensu-extensions-#{extension}"
162
+ end
163
+ end
164
+ log "compiled Sensu extension gems: #{extension_gems}" if options[:verbose]
165
+ to_be_installed = extension_gems.reject do |raw_gem|
166
+ gem_installed?(raw_gem, options)
167
+ end
168
+ log "Sensu extension gems to be installed: #{to_be_installed}"
169
+ to_be_installed.each do |raw_gem|
170
+ install_gem(raw_gem, options)
171
+ end
172
+ log "successfully installed Sensu extensions: #{to_be_installed}"
173
+ if options[:clean]
174
+ log "cleaning Sensu extension gems: #{extension_gems}" if options[:verbose]
175
+ extension_gems.each do |raw_gem|
176
+ clean_gem(raw_gem, options)
177
+ end
178
+ end
179
+ end
180
+
181
+ def run
182
+ options = cli_options
183
+ unless options[:plugins].empty?
184
+ install_plugins(options[:plugins], options)
185
+ end
186
+ unless options[:extensions].empty?
187
+ install_extensions(options[:extensions], options)
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,5 @@
1
+ module Sensu
2
+ module Install
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sensu/install/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sensu-install"
8
+ spec.version = Sensu::Install::VERSION
9
+ spec.authors = ["Sean Porter"]
10
+ spec.email = ["portertech@gmail.com"]
11
+
12
+ spec.summary = "The Sensu Ruby Plugin installer"
13
+ spec.description = "The Sensu Ruby Plugin installer"
14
+ spec.homepage = "https://github.com/sensu/sensu-install"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
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 "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-install
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sean Porter
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: The Sensu Ruby Plugin installer
56
+ email:
57
+ - portertech@gmail.com
58
+ executables:
59
+ - sensu-install
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - exe/sensu-install
75
+ - lib/sensu/install.rb
76
+ - lib/sensu/install/version.rb
77
+ - sensu-install.gemspec
78
+ homepage: https://github.com/sensu/sensu-install
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.11
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: The Sensu Ruby Plugin installer
102
+ test_files: []