diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..53e4b99 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,28 @@ +AllCops: + TargetRubyVersion: 2.3 + +Lint/RaiseException: + Enabled: true + +Lint/StructNewOverride: + Enabled: true + + +Metrics: + Enabled: false + + +Style/FrozenStringLiteralComment: + Enabled: false + +Style/Documentation: + Enabled: false + +Style/HashEachMethods: + Enabled: true + +Style/HashTransformKeys: + Enabled: true + +Style/HashTransformValues: + Enabled: true diff --git a/Gemfile.lock b/Gemfile.lock index d0395dd..18d2f84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,62 +12,59 @@ GEM ast (2.4.2) crack (0.4.5) rexml - diff-lcs (1.4.4) + diff-lcs (1.5.0) hashdiff (1.0.1) - json (2.5.1) + jaro_winkler (1.5.4) + json (2.6.2) mixlib-cli (1.7.0) - parallel (1.20.1) - parser (3.0.2.0) + parallel (1.22.1) + parser (3.1.2.0) ast (~> 2.4.1) - public_suffix (4.0.6) - rainbow (3.0.0) + public_suffix (4.0.7) + rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.1.1) rexml (3.2.5) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + rspec (3.11.0) + rspec-core (~> 3.11.0) + rspec-expectations (~> 3.11.0) + rspec-mocks (~> 3.11.0) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - rubocop (0.93.1) + rspec-support (~> 3.11.0) + rspec-support (3.11.0) + rubocop (0.81.0) + jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8) rexml - rubocop-ast (>= 0.6.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.8.0) - parser (>= 3.0.1.1) ruby-progressbar (1.11.0) sensu-plugin (2.7.1) json (< 3.0.0) mixlib-cli (~> 1.5) - unicode-display_width (1.7.0) - webmock (3.13.0) - addressable (>= 2.3.6) + unicode-display_width (1.8.0) + webmock (3.14.0) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS - x86_64-linux + ruby DEPENDENCIES - bundler (~> 2.2) + bundler (~> 2.1) rake (~> 13.0) rspec (~> 3.10) - rubocop (~> 0.54) + rubocop (~> 0.54, <= 0.81) sensu-plugins-minio! webmock (~> 3.3) BUNDLED WITH - 2.2.23 + 2.1.4 diff --git a/README.md b/README.md index 0be5c53..810bd80 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Sensu check for minio updates +Translates the presence of an outdated minio server instance into sensu check +results to reduce the time-to-patch for minio systems. + ## Installation Add this line to your application's Gemfile: @@ -24,7 +27,7 @@ Check if a the local minio version is in the most recent version 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. +reason need to check a different URL. | Parameter | Description | | ------------------ | ----------------------------------------------- | diff --git a/bin/check-minio-update.rb b/bin/check-minio-update.rb index f3cb9cf..d0541f6 100755 --- a/bin/check-minio-update.rb +++ b/bin/check-minio-update.rb @@ -46,7 +46,6 @@ def run begin Timeout.timeout(timeout) do latest_version = get_latest_version(checkurl, platform) - local_version = get_local_version if local_version == latest_version ok 'No new minio version available' @@ -55,12 +54,14 @@ def run end end rescue IOError => e - unknown "#{e.message}" + unknown e.message.to_s rescue Timeout::Error unknown 'Connection timed out' end end + private + def get_latest_version(checkurl, platform) uri = URI.parse("#{checkurl}/#{platform}/minio.shasum") response = Net::HTTP.get_response(uri) @@ -69,14 +70,18 @@ def get_latest_version(checkurl, platform) raise IOError, "Unable to gather latest minio version: #{response.body}" end - return response.body.split.last.split('.', 2).last + response.body.split.last.split('.', 2).last end - def get_local_version - stdout, stderr, status = Open3.capture3({ 'PATH' => ENV['PATH'] }, 'minio --version', :unsetenv_others => true) + def local_version + stdout, stderr, status = Open3.capture3( + { 'PATH' => ENV['PATH'] }, 'minio --version', unsetenv_others: true + ) - raise IOError, "Unable to gather local minio version: #{stderr}" unless status.success? + unless status.success? + raise IOError, "Unable to gather local minio version: #{stderr}" + end - return stdout.split.last + stdout.split.last end end diff --git a/sensu-plugins-minio.gemspec b/sensu-plugins-minio.gemspec index 889a4f1..10828e3 100644 --- a/sensu-plugins-minio.gemspec +++ b/sensu-plugins-minio.gemspec @@ -11,20 +11,23 @@ Gem::Specification.new do |spec| spec.authors = ['Hauke Altmann', 'Jonathan Schlue'] spec.email = ['info@aboutsource.net'] - spec.summary = 'Check if there are updates for the local minio server instance' + spec.summary = 'Check if there are updates for the local '\ + 'minio server instance' spec.description = 'Used to check 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.required_ruby_version = '>= 2.3.3' + + spec.executables = Dir.glob('bin/**/*.rb').map { |f| File.basename(f) } 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', '~> 2.2' + spec.add_development_dependency 'bundler', '~> 2.1' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.10' - spec.add_development_dependency 'rubocop', '~> 0.54' + spec.add_development_dependency 'rubocop', '~> 0.54', '<= 0.81' spec.add_development_dependency 'webmock', '~> 3.3' end diff --git a/spec/check-minio-update_spec.rb b/spec/check_minio_update_spec.rb similarity index 71% rename from spec/check-minio-update_spec.rb rename to spec/check_minio_update_spec.rb index 9071099..6a89e80 100644 --- a/spec/check-minio-update_spec.rb +++ b/spec/check_minio_update_spec.rb @@ -9,7 +9,9 @@ before do stub_checksum_request allow(check).to(receive(:output)) - allow(Open3).to(receive(:capture3).and_return([stdout, stderr, double(:success? => success)])) + allow(Open3).to( + receive(:capture3).and_return([stdout, stderr, double(success?: success)]) + ) end let(:checksum_request) do @@ -20,7 +22,12 @@ end let(:response) do - { body: '285ec90006a6961ebcb7dd9685acc0ebcd08f561 minio.RELEASE.2021-07-08T19-43-25Z', status: 200 } + { + body: + '285ec90006a6961ebcb7dd9685acc0ebcd08f561 '\ + 'minio.RELEASE.2021-07-08T19-43-25Z', + status: 200 + } end alias_method :stub_checksum_request, :checksum_request @@ -43,14 +50,21 @@ expect(error.status).to eq 0 end - expect(check).to have_received(:output).with('No new minio version available') + expect(check).to have_received(:output).with( + 'No new minio version available' + ) expect(checksum_request).to have_been_requested end end context 'with different local and remote versions' do let(:response) do - { body: '285ec90006a6961ebcb7dd9685acc0ebcd08f561 minio.RELEASE.2022-07-08T19-43-25Z', status: 200 } + { + body: + '285ec90006a6961ebcb7dd9685acc0ebcd08f561 '\ + 'minio.RELEASE.2022-07-08T19-43-25Z', + status: 200 + } end it 'should be critical' do @@ -59,7 +73,9 @@ expect(error.status).to eq 2 end - expect(check).to have_received(:output).with('New minio version available RELEASE.2022-07-08T19-43-25Z') + expect(check).to have_received(:output).with( + 'New minio version available RELEASE.2022-07-08T19-43-25Z' + ) expect(checksum_request).to have_been_requested end end @@ -75,7 +91,9 @@ expect(error.status).to eq 3 end - expect(check).to have_received(:output).with('Unable to gather local minio version: Minio not found') + expect(check).to have_received(:output).with( + 'Unable to gather local minio version: Minio not found' + ) expect(checksum_request).to have_been_requested end end @@ -89,7 +107,9 @@ expect(error.status).to eq 3 end - expect(check).to have_received(:output).with('Unable to gather latest minio version: 404 Not Found') + expect(check).to have_received(:output).with( + 'Unable to gather latest minio version: 404 Not Found' + ) expect(checksum_request).to have_been_requested end end