-
Notifications
You must be signed in to change notification settings - Fork 0
Initital commit #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| source 'https://rubygems.org' | ||
|
|
||
| # Specify your gem's dependencies in sensu-plugin-trello.gemspec | ||
| gemspec | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,58 @@ | ||
| # sensu-plugins-minio | ||
| Sensu check for minio updates | ||
| # Sensu check for minio updates | ||
|
|
||
| ## Installation | ||
|
|
||
| Add this line to your application's Gemfile: | ||
|
|
||
| ```ruby | ||
| gem 'sensu-plugins-minio' | ||
| ``` | ||
|
|
||
| And then execute: | ||
|
|
||
| $ bundle | ||
|
|
||
| Or install it yourself as: | ||
|
|
||
| $ gem install sensu-plugins-minio | ||
|
|
||
| ## CONFIGURATION | ||
|
|
||
| TODO | ||
|
|
||
| ## USAGE | ||
| Check if a the local minio version is in the most recent version | ||
|
|
||
| ### Optional parameters | ||
|
|
||
| TODO | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
|
|
||
| | Parameter | Description | | ||
| | ------------------ | ----------------------------------------------- | | ||
| | -u URL | Url of minio site containing update information | | ||
| | -p PLATFORM | OS Platform to check for | | ||
| | --timeout TIMEOUT | Update website request timeout in seconds | | ||
|
|
||
| ### Example: | ||
| ``` | ||
| ./bin/check-minio-update.rb | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| After checking out the repo, run `bin/setup` to install dependencies. You can | ||
| also run `bin/console` for an interactive prompt that will allow you to | ||
| experiment. | ||
|
|
||
| To run the tests execute `bundle exec rspec spec`. | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
|
|
||
| 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 | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
| git commits and tags, and push the `.gem` file to | ||
| [rubygems.org](https://rubygems.org). | ||
|
|
||
| ## Contributing | ||
|
|
||
| Bug reports and pull requests are welcome on GitHub at | ||
| https://github.com/aboutsource/sensu-plugins-minio. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| require 'bundler/gem_tasks' | ||
| require 'rspec/core/rake_task' | ||
| require 'rubocop/rake_task' | ||
|
|
||
| RSpec::Core::RakeTask.new(:spec) do |r| | ||
| r.pattern = FileList['test/**/*_spec.rb'] | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
| end | ||
|
|
||
| RuboCop::RakeTask.new | ||
|
|
||
| task default: %i[rubocop spec] | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env ruby | ||
| # | ||
| # Check for minio updates | ||
| # | ||
| # | ||
| # OUTPUT: | ||
| # plain text | ||
| # | ||
| # | ||
| # USAGE: | ||
| # Check if minio updates are available for the local minio instance | ||
| # ./check-minio-update.rb | ||
|
|
||
| require 'sensu-plugin/check/cli' | ||
| require 'sensu-plugin/utils' | ||
| require 'net/http' | ||
| require 'open3' | ||
|
|
||
| class CheckMinioUpdate < Sensu::Plugin::Check::CLI | ||
| include Sensu::Plugin::Utils | ||
|
|
||
| option :checkurl, | ||
| description: 'Base URL to check for updates', | ||
| short: '-u URL', | ||
| long: '--url URL', | ||
| default: 'https://dl.min.io/server/minio/release' | ||
|
|
||
| option :platform, | ||
| description: 'os platform', | ||
| short: '-p PLATFORM', | ||
| long: '--platform PLATFORM', | ||
| default: 'linux-amd64' | ||
|
|
||
| option :timeout, | ||
| description: 'Request timeout in seconds', | ||
| long: '--timeout TIMEOUT', | ||
| default: 30 | ||
|
|
||
| def run | ||
| checkurl = config[:checkurl] | ||
| platform = config[:platform] | ||
| timeout = config[:timeout].to_i | ||
|
|
||
| begin | ||
| Timeout.timeout(timeout) do | ||
| check_update(checkurl, platform) | ||
| end | ||
| rescue Timeout::Error | ||
| unknown 'Connection timed out' | ||
| end | ||
| end | ||
|
|
||
| def check_update(checkurl, platform) | ||
| uri = URI.parse(format('%<checkurl>s/%<platform>s/minio.shasum', | ||
| checkurl: checkurl, platform: platform)) | ||
| latest_version = Net::HTTP.get(uri).split.last | ||
|
hauke-altmann-as marked this conversation as resolved.
Outdated
|
||
|
|
||
| stdout_str, error_str, status = Open3.capture3('sh -c "minio"') | ||
|
hauke-altmann-as marked this conversation as resolved.
Outdated
|
||
| if status.success? | ||
| minio_version = stdout_str.split.last | ||
| else | ||
| unknown format('Check failed: %<error>s', error: error_str) | ||
|
hauke-altmann-as marked this conversation as resolved.
Outdated
|
||
| end | ||
|
|
||
| if latest_version.split('.').last == minio_version.tr(':', '-') | ||
|
hauke-altmann-as marked this conversation as resolved.
Outdated
|
||
| ok 'No new minio version available' | ||
| else | ||
| critical format('New minio version available %<version>s', version: latest_version) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env ruby | ||
|
|
||
| require 'bundler/setup' | ||
| require 'sensu/plugins/minio' | ||
|
|
||
| # You can add fixtures and/or initialization code here to make experimenting | ||
| # with your gem easier. You can also use a different console, if you like. | ||
|
|
||
| # (If you use this, don't forget to add pry to your Gemfile!) | ||
| # require 'pry' | ||
| # Pry.start | ||
|
|
||
| require 'irb' | ||
| IRB.start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| IFS=$'\n\t' | ||
| set -vx | ||
|
|
||
| bundle install --path vendor/bundle | ||
|
|
||
| # Do any other automated setup that you need to do here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| require 'sensu/plugins/minio/version' | ||
|
|
||
| module Sensu | ||
| module Plugins | ||
| module Minio | ||
| # Your code goes here... | ||
| end | ||
| end | ||
| end | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module Sensu | ||
| module Plugins | ||
| module Minio | ||
| VERSION = '0.0.1'.freeze | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| lib = File.expand_path('lib', __dir__) | ||
| $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
| require_relative 'lib/sensu/plugins/minio/version' | ||
|
|
||
| Gem::Specification.new do |spec| | ||
| spec.name = 'sensu-plugins-minio' | ||
| spec.version = Sensu::Plugins::Minio::VERSION | ||
| spec.licenses = ['MIT'] | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
| spec.authors = ['Hauke Altmann'] | ||
| spec.email = ['info@aboutsource.net'] | ||
|
|
||
| spec.summary = 'Check if there are updates for the local minio server instance' | ||
| spec.description = 'Used to checko for manual installed minio servers' | ||
| spec.homepage = 'https://github.com/aboutsource/sensu-plugins-minio' | ||
| spec.require_paths = ['lib'] | ||
|
|
||
| spec.executables = Dir.glob('bin/**/*.rb').map { |file| File.basename(file) } | ||
| spec.files = `git ls-files -z`.split("\x0").reject do |f| | ||
| f.match(%r{^(test|spec|features)/}) | ||
| end | ||
|
|
||
| spec.add_dependency 'sensu-plugin', '~> 2.1' | ||
| spec.add_development_dependency 'bundler', '~> 1.11' | ||
| spec.add_development_dependency 'rake', '~> 10.0' | ||
| spec.add_development_dependency 'rspec', '~> 3.7' | ||
| spec.add_development_dependency 'rubocop', '~> 0.54' | ||
| spec.add_development_dependency 'webmock', '~> 3.3' | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| require 'json' | ||
| require 'webmock/rspec' | ||
|
|
||
| require_relative '../bin/check-minio-update.rb' | ||
|
|
||
| describe CheckMinioUpdate do | ||
| let(:status) { double } | ||
|
|
||
| before :context do | ||
| CheckMinioUpdate.class_variable_set(:@@autorun, false) | ||
| end | ||
|
|
||
| before(:each) do | ||
| @api = stub_request( | ||
| :get, | ||
| 'https://dl.min.io/server/minio/release/linux-amd64/minio.shasum' | ||
| ) | ||
|
|
||
| @check = CheckMinioUpdate.new | ||
| @check.config[:checkurl] = 'https://dl.min.io/server/minio/release' | ||
| @check.config[:platform] = 'linux-amd64' | ||
|
|
||
| allow(@check).to receive(:output) | ||
| end | ||
|
|
||
| it 'should bo ok if versions are equal' do | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
| @api.to_return(body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-11T19-53-16Z', status: 200) | ||
| allow(status).to receive(:success?).and_return(true) | ||
| allow(Open3).to receive(:capture3).with('sh -c "minio"').and_return(['2019-09-11T19-53-16Z', nil, status]) | ||
|
|
||
| expect { @check.run }.to raise_error do |error| | ||
| expect(error).to be_a SystemExit | ||
| expect(error.status).to eq 0 | ||
| end | ||
| expect(@check).to have_received(:output).with('No new minio version available') | ||
| expect(@api).to have_been_requested | ||
| end | ||
|
|
||
| it 'should be critical if versions differ' do | ||
| @api.to_return(body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-11T19-53-16Z', status: 200) | ||
| allow(status).to receive(:success?).and_return(true) | ||
| allow(Open3).to receive(:capture3).with('sh -c "minio"').and_return(['2019-09-05T19-53-16Z', nil, status]) | ||
|
|
||
| expect { @check.run }.to raise_error do |error| | ||
| expect(error).to be_a SystemExit | ||
| expect(error.status).to eq 2 | ||
| end | ||
| expect(@check).to have_received(:output).with('New minio version available minio.RELEASE.2019-09-11T19-53-16Z') | ||
| expect(@api).to have_been_requested | ||
| end | ||
|
|
||
| it 'should be unknown if minio not found' do | ||
| @api.to_return(body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-11T19-53-16Z', status: 200) | ||
| allow(status).to receive(:success?).and_return(false) | ||
| allow(Open3).to receive(:capture3).with('sh -c "minio"').and_return([nil, 'Minio not found', status]) | ||
|
|
||
| expect { @check.run }.to raise_error do |error| | ||
| expect(error).to be_a SystemExit | ||
| expect(error.status).to eq 3 | ||
| end | ||
| expect(@check).to have_received(:output).with('Check failed: Minio not found') | ||
| expect(@api).to have_been_requested | ||
| end | ||
|
hauke-altmann-as marked this conversation as resolved.
|
||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.