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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in sensu-plugin-minio.gemspec
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| ------------------ | ----------------------------------------------- |
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 8 additions & 21 deletions bin/check-minio-update.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# Check for minio updates
#
Expand Down Expand Up @@ -51,41 +53,26 @@ def run
end

def check_update(checkurl, platform)
uri = URI.parse(
format(
'%<checkurl>s/%<platform>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: %<response>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: %<error>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 %<version>s',
version: latest_version
)
critical "New minio version available #{latest_version}"
end
end
end
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'sensu/plugins/minio'
Expand Down
9 changes: 0 additions & 9 deletions lib/sensu/plugins/minio.rb

This file was deleted.

4 changes: 3 additions & 1 deletion lib/sensu/plugins/minio/version.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions sensu-plugins-minio.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'
require 'webmock/rspec'

Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down