Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in sensu-plugin-trello.gemspec
gemspec
Comment thread
hauke-altmann-as marked this conversation as resolved.
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
# sensu-plugins-minio
Sensu check for minio updates
# Sensu check for minio updates

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'sensu-plugins-minio'
```

And then execute:

$ bundle

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
Comment thread
hauke-altmann-as marked this conversation as resolved.

| Parameter | Description |
| ------------------ | ----------------------------------------------- |
| -u URL | Url of minio site containing update information |
| -p PLATFORM | OS Platform to check for |
| --timeout TIMEOUT | Update website request timeout in seconds |

### Example:
```
./bin/check-minio-update.rb
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. You can
also run `bin/console` for an interactive prompt that will allow you to
experiment.

To run the tests execute `bundle exec rspec spec`.
Comment thread
hauke-altmann-as marked this conversation as resolved.

To install this gem onto your local machine, run `bundle exec rake install`. To
release a new version, update the version number in `version.rb`, and then run
`bundle exec rake release`, which will create a git tag for the version, push
Comment thread
hauke-altmann-as marked this conversation as resolved.
git commits and tags, and push the `.gem` file to
[rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at
https://github.com/aboutsource/sensu-plugins-minio.
11 changes: 11 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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']
Comment thread
hauke-altmann-as marked this conversation as resolved.
end

RuboCop::RakeTask.new

task default: %i[rubocop spec]
Comment thread
hauke-altmann-as marked this conversation as resolved.
71 changes: 71 additions & 0 deletions bin/check-minio-update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env ruby
#
# Check for minio updates
#
#
# OUTPUT:
# plain text
#
#
# USAGE:
# Check if minio updates are available for the local minio instance
# ./check-minio-update.rb

require 'sensu-plugin/check/cli'
require 'sensu-plugin/utils'
require 'net/http'
require 'open3'

class CheckMinioUpdate < Sensu::Plugin::Check::CLI
include Sensu::Plugin::Utils

option :checkurl,
description: 'Base URL to check for updates',
short: '-u URL',
long: '--url URL',
default: 'https://dl.min.io/server/minio/release'

option :platform,
description: 'os platform',
short: '-p PLATFORM',
long: '--platform PLATFORM',
default: 'linux-amd64'

option :timeout,
description: 'Request timeout in seconds',
long: '--timeout TIMEOUT',
default: 30

def run
checkurl = config[:checkurl]
platform = config[:platform]
timeout = config[:timeout].to_i

begin
Timeout.timeout(timeout) do
check_update(checkurl, platform)
end
rescue Timeout::Error
unknown 'Connection timed out'
end
end

def check_update(checkurl, platform)
uri = URI.parse(format('%<checkurl>s/%<platform>s/minio.shasum',
checkurl: checkurl, platform: platform))
latest_version = Net::HTTP.get(uri).split.last
Comment thread
hauke-altmann-as marked this conversation as resolved.
Outdated

stdout_str, error_str, status = Open3.capture3('sh -c "minio"')
Comment thread
hauke-altmann-as marked this conversation as resolved.
Outdated
if status.success?
minio_version = stdout_str.split.last
else
unknown format('Check failed: %<error>s', error: error_str)
Comment thread
hauke-altmann-as marked this conversation as resolved.
Outdated
end

if latest_version.split('.').last == minio_version.tr(':', '-')
Comment thread
hauke-altmann-as marked this conversation as resolved.
Outdated
ok 'No new minio version available'
else
critical format('New minio version available %<version>s', version: latest_version)
end
end
end
14 changes: 14 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'sensu/plugins/minio'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require 'pry'
# Pry.start

require 'irb'
IRB.start
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install --path vendor/bundle

# Do any other automated setup that you need to do here
9 changes: 9 additions & 0 deletions lib/sensu/plugins/minio.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'sensu/plugins/minio/version'

module Sensu
module Plugins
module Minio
# Your code goes here...
end
end
end
Comment thread
hauke-altmann-as marked this conversation as resolved.
7 changes: 7 additions & 0 deletions lib/sensu/plugins/minio/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Sensu
module Plugins
module Minio
VERSION = '0.0.1'.freeze
end
end
end
28 changes: 28 additions & 0 deletions sensu-plugins-minio.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require_relative 'lib/sensu/plugins/minio/version'

Gem::Specification.new do |spec|
spec.name = 'sensu-plugins-minio'
spec.version = Sensu::Plugins::Minio::VERSION
spec.licenses = ['MIT']
Comment thread
hauke-altmann-as marked this conversation as resolved.
spec.authors = ['Hauke Altmann']
spec.email = ['info@aboutsource.net']

spec.summary = 'Check if there are updates for the local minio server instance'
spec.description = 'Used to checko 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.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', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.7'
spec.add_development_dependency 'rubocop', '~> 0.54'
spec.add_development_dependency 'webmock', '~> 3.3'
end
64 changes: 64 additions & 0 deletions test/check-minio-update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'json'
require 'webmock/rspec'

require_relative '../bin/check-minio-update.rb'

describe CheckMinioUpdate do
let(:status) { double }

before :context do
CheckMinioUpdate.class_variable_set(:@@autorun, false)
end

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

@check = CheckMinioUpdate.new
@check.config[:checkurl] = 'https://dl.min.io/server/minio/release'
@check.config[:platform] = 'linux-amd64'

allow(@check).to receive(:output)
end

it 'should bo ok if versions are equal' do
Comment thread
hauke-altmann-as marked this conversation as resolved.
@api.to_return(body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-11T19-53-16Z', status: 200)
allow(status).to receive(:success?).and_return(true)
allow(Open3).to receive(:capture3).with('sh -c "minio"').and_return(['2019-09-11T19-53-16Z', nil, status])

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(@api).to have_been_requested
end

it 'should be critical if versions differ' do
@api.to_return(body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-11T19-53-16Z', status: 200)
allow(status).to receive(:success?).and_return(true)
allow(Open3).to receive(:capture3).with('sh -c "minio"').and_return(['2019-09-05T19-53-16Z', nil, status])

expect { @check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 2
end
expect(@check).to have_received(:output).with('New minio version available minio.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(body: '65a735f04bc1d35b4f86418226d5bbb4895cf7e1 minio.RELEASE.2019-09-11T19-53-16Z', status: 200)
allow(status).to receive(:success?).and_return(false)
allow(Open3).to receive(:capture3).with('sh -c "minio"').and_return([nil, 'Minio not found', status])

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('Check failed: Minio not found')
expect(@api).to have_been_requested
end
Comment thread
hauke-altmann-as marked this conversation as resolved.
end