diff --git a/Gemfile b/Gemfile index 120651f..53b9c1f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in sensu-plugin-minio.gemspec diff --git a/README.md b/README.md index d369409..94bafe6 100644 --- a/README.md +++ b/README.md @@ -16,16 +16,15 @@ 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 +Checks will check the default URL https://dl.min.io/server/minio/release +and the default Platform linux-amd64 for updates. Adjust these optional +parameters if you want to check a different platform or for whatever +reason need to check a differen URL. | Parameter | Description | | ------------------ | ----------------------------------------------- | @@ -52,6 +51,8 @@ release a new version, update the version number in `version.rb`, and then run git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +Plugin follows the [rubocop ruby style guide](https://github.com/rubocop-hq/ruby-style-guide) + ## Contributing Bug reports and pull requests are welcome on GitHub at diff --git a/Rakefile b/Rakefile index f4cea96..d4befcc 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,11 @@ +# frozen_string_literal: true + 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'] + r.pattern = FileList['spec/**/*_spec.rb'] end RuboCop::RakeTask.new diff --git a/bin/check-minio-update.rb b/bin/check-minio-update.rb index 3d3c5f7..4371651 100755 --- a/bin/check-minio-update.rb +++ b/bin/check-minio-update.rb @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # # Check for minio updates # @@ -51,41 +53,26 @@ def run end def check_update(checkurl, platform) - uri = URI.parse( - format( - '%s/%s/minio.shasum', - checkurl: checkurl, - platform: platform - ) - ) + uri = URI.parse("#{checkurl}/#{platform}/minio.shasum") response = Net::HTTP.get_response(uri) if response.is_a?(Net::HTTPSuccess) - latest_version = response.body.split.last.split('.', 2).last.freeze + latest_version = response.body.split.last.split('.', 2).last else - unknown format( - 'Unable to gather latest minio version: %s', - response: response.body - ) + unknown "Unable to gather latest minio version: #{response.body}" end stdout_str, error_str, status = Open3.capture3('minio version') if status.success? - local_version = stdout_str.lines.at(1).split.last.freeze + local_version = stdout_str.lines.at(1).split.last else - unknown format( - 'Unable to gather local minio version: %s', - error: error_str - ) + unknown "Unable to gather local minio version: #{error_str}" end if latest_version == local_version ok 'No new minio version available' else - critical format( - 'New minio version available %s', - version: latest_version - ) + critical "New minio version available #{latest_version}" end end end diff --git a/bin/console b/bin/console index 8075c3c..269acc7 100755 --- a/bin/console +++ b/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'bundler/setup' require 'sensu/plugins/minio' diff --git a/lib/sensu/plugins/minio.rb b/lib/sensu/plugins/minio.rb deleted file mode 100644 index 61884b3..0000000 --- a/lib/sensu/plugins/minio.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'sensu/plugins/minio/version' - -module Sensu - module Plugins - module Minio - # Your code goes here... - end - end -end diff --git a/lib/sensu/plugins/minio/version.rb b/lib/sensu/plugins/minio/version.rb index 5036a0f..f0fdb17 100644 --- a/lib/sensu/plugins/minio/version.rb +++ b/lib/sensu/plugins/minio/version.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module Sensu module Plugins module Minio - VERSION = '0.0.1'.freeze + VERSION = '0.0.1' end end end diff --git a/sensu-plugins-minio.gemspec b/sensu-plugins-minio.gemspec index 322f5cc..fcc08c3 100644 --- a/sensu-plugins-minio.gemspec +++ b/sensu-plugins-minio.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require_relative 'lib/sensu/plugins/minio/version' diff --git a/test/check-minio-update_spec.rb b/spec/check-minio-update_spec.rb similarity index 93% rename from test/check-minio-update_spec.rb rename to spec/check-minio-update_spec.rb index 1e2a92f..16d1f3f 100644 --- a/test/check-minio-update_spec.rb +++ b/spec/check-minio-update_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'webmock/rspec' @@ -25,7 +27,7 @@ allow(@check).to receive(:output) end - it 'should bo ok if versions are equal' do + it 'should be ok if versions are equal' do @api.to_return(latest_version_return) allow(status).to receive(:success?).and_return(true) allow(Open3).to receive(:capture3).with('minio version').and_return([local_version_return, nil, status]) @@ -66,10 +68,10 @@ end it 'should be unknown if release url changes ' do - latest_version_return_404 = [body: '404 Not Found', status: 404] - @api.to_return(latest_version_return_404) + not_found = [body: '404 Not Found', status: 404] + @api.to_return(not_found) allow(status).to receive(:success?).and_return(false) - allow(Open3).to receive(:capture3).with('minio version').and_return([nil, 'Minio not found', status]) + allow(Open3).to receive(:capture3).with('minio version').and_return([local_version_return, nil, status]) expect { @check.run }.to raise_error do |error| expect(error).to be_a SystemExit