Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.0
78 changes: 41 additions & 37 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,67 @@ PATH
GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
hashdiff (1.0.0)
jaro_winkler (1.5.3)
json (2.2.0)
ast (2.4.2)
crack (0.4.5)
rexml
diff-lcs (1.4.4)
hashdiff (1.0.1)
json (2.5.1)
mixlib-cli (1.7.0)
parallel (1.17.0)
parser (2.6.4.0)
ast (~> 2.4.0)
public_suffix (4.0.1)
parallel (1.20.1)
parser (3.0.2.0)
ast (~> 2.4.1)
public_suffix (4.0.6)
rainbow (3.0.0)
rake (10.5.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
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)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.1)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
rubocop (0.74.0)
jaro_winkler (~> 1.5.1)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (0.93.1)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 2.7.1.5)
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, < 1.7)
ruby-progressbar (1.10.1)
safe_yaml (1.0.5)
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.6.0)
webmock (3.7.2)
unicode-display_width (1.7.0)
webmock (3.13.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
bundler (~> 1.11)
rake (~> 10.0)
rspec (~> 3.7)
bundler (~> 2.2)
rake (~> 13.0)
rspec (~> 3.10)
rubocop (~> 0.54)
sensu-plugins-minio!
webmock (~> 3.3)

BUNDLED WITH
1.16.1
2.2.23
2 changes: 1 addition & 1 deletion bin/check-minio-update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_latest_version(checkurl, platform)
end

def get_local_version
stdout, stderr, status = Open3.capture3('minio --version', unsetenv_others: true)
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?

Expand Down
6 changes: 3 additions & 3 deletions sensu-plugins-minio.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
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 'bundler', '~> 2.2'
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 'webmock', '~> 3.3'
end
120 changes: 67 additions & 53 deletions spec/check-minio-update_spec.rb
Original file line number Diff line number Diff line change
@@ -1,83 +1,97 @@
# frozen_string_literal: true

require 'json'
require 'webmock/rspec'
require_relative '../bin/check-minio-update'

require_relative '../bin/check-minio-update.rb'
CheckMinioUpdate.class_variable_set(:@@autorun, false)

describe CheckMinioUpdate do
let(:status) { double }
local_version_return = "Version: 2019-09-05T23:24:38Z\nRelease-Tag: RELEASE.2019-09-05T23-24-38Z\nCommit-ID: b52a3e523cc3c4debc0ea2f86386377df5355c81"
latest_version_return = [body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-05T23-24-38Z', status: 200]

before :context do
CheckMinioUpdate.class_variable_set(:@@autorun, false)
before do
stub_checksum_request
allow(check).to(receive(:output))
allow(Open3).to(receive(:capture3).with(array_including('minio --version'))
.and_return([stdout, stderr, double(:success? => success)]))
end

before(:each) do
@api = stub_request(
let(:checksum_request) do
stub_request(
:get,
'https://dl.min.io/server/minio/release/linux-amd64/minio.shasum'
)
).to_return(response)
end

@check = CheckMinioUpdate.new
@check.config[:checkurl] = 'https://dl.min.io/server/minio/release'
@check.config[:platform] = 'linux-amd64'
let(:response) do
{ body: '285ec90006a6961ebcb7dd9685acc0ebcd08f561 minio.RELEASE.2021-07-08T19-43-25Z', status: 200 }
end

allow(@check).to receive(:output)
alias_method :stub_checksum_request, :checksum_request

let(:check) do
CheckMinioUpdate.new.tap do |check|
check.config[:checkurl] = 'https://dl.min.io/server/minio/release'
check.config[:platform] = 'linux-amd64'
end
end

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').and_return([local_version_return, nil, status])
let(:stdout) { 'minio version RELEASE.2021-07-08T19-43-25Z' }
let(:stderr) { nil }
let(:success) { true }

expect { @check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 0
context 'with matching local and remote version' do
it 'should be ok if versions are equal' do
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(checksum_request).to have_been_requested
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
latest_version_return_diff = [body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-11T19-53-16Z', status: 200]
@api.to_return(latest_version_return_diff)
allow(status).to receive(:success?).and_return(true)
allow(Open3).to receive(:capture3).with('minio').and_return([local_version_return, nil, status])
context 'with different local and remote versions' do
let(:response) do
{ body: '285ec90006a6961ebcb7dd9685acc0ebcd08f561 minio.RELEASE.2022-07-08T19-43-25Z', status: 200 }
end

it 'should be critical' do
expect { check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 2
end

expect { @check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 2
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
expect(@check).to have_received(:output).with('New minio version available 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(latest_version_return)
allow(status).to receive(:success?).and_return(false)
allow(Open3).to receive(:capture3).with('minio').and_return([nil, 'Minio not found', status])
context 'with unknown local version' do
let(:stdout) { nil }
let(:stderr) { 'Minio not found' }
let(:success) { false }

expect { @check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 3
it 'should be unknown' do
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('Unable to gather local minio version: Minio not found')
expect(checksum_request).to have_been_requested
end
expect(@check).to have_received(:output).with('Unable to gather local minio version: Minio not found')
expect(@api).to have_been_requested
end

it 'should be unknown if release url changes ' do
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').and_return([local_version_return, nil, status])
context 'with release url not found' do ||
let(:response) { { body: '404 Not Found', status: 404 } }

it 'should be unknown' do
expect { check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 3
end

expect { @check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 3
expect(check).to have_received(:output).with('Unable to gather latest minio version: 404 Not Found')
expect(checksum_request).to have_been_requested
end
expect(@check).to have_received(:output).with('Unable to gather latest minio version: 404 Not Found')
expect(@api).to have_been_requested
end
end