diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..1468772 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,27 @@ +## Pull Request Checklist + +**Is this in reference to an existing issue?** + +#### General + +- [ ] Update Changelog following the conventions laid out [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) + +- [ ] Update README with any necessary configuration snippets + +- [ ] Binstubs are created if needed + +- [ ] RuboCop passes + +- [ ] Existing tests pass + +#### New Plugins + +- [ ] Tests + +- [ ] Add the plugin to the README + +- [ ] Does it have a complete header as outlined [here](http://sensu-plugins.io/docs/developer_guidelines.html#coding-style) + +#### Purpose + +#### Known Compatibility Issues diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fdb1ebb --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +/.bundle/ +/.yardoc +/Gemfile.lock +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ +*.bundle +*.so +*.o +*.a +mkmf.log +.vagrant/* +.DS_Store +.idea/* +*.gem + + +# test-kitchen +.kitchen/ +.kitchen.list.yml diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..5c3ad91 --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,23 @@ +--- +driver: + name: docker + use_sudo: false + +provisioner: + name: shell + data_path: . + script: test/fixtures/bootstrap.sh + +verifier: + ruby_bindir: /usr/local/bin + +platforms: + - name: debian-8 + +suites: + - name: ruby-230 + driver: + image: ruby:2.3.0-slim + - name: ruby-241 + driver: + image: ruby:2.4.1-slim diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..0ba1665 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,30 @@ + +MethodLength: + Max: 200 + +LineLength: + Max: 160 + +AbcSize: + Max: 100 + +FileName: + Enabled: false + +PerceivedComplexity: + Enabled: false + +CyclomaticComplexity: + Enabled: false + +ClassLength: + Enabled: false + +IfUnlessModifier: + Enabled: false + +RegexpLiteral: + Enabled: false + +Style/Documentation: + Enabled: false diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..229845b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +sudo: true +service: docker +language: ruby +cache: +- bundler +before_install: +- sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables + -N DOCKER ) +- gem install bundler -v 1.15 +install: +- bundle install +rvm: +- 2.3.0 +- 2.4.1 +notifications: + email: + recipients: + - sensu-plugin@sensu-plugins.io + on_success: change + on_failure: always +script: +- gem build sensu-plugins-kafka.gemspec +- gem install sensu-plugins-kafka-*.gem +- bundle exec rake quick +- bundle exec rake kitchen:ruby-`echo $TRAVIS_RUBY_VERSION | sed -e "s/\.//g"`-debian-8 +deploy: + provider: rubygems + api_key: + secure: mZhCJKtOyUqcpJwZS2CmQPLu5bnyStuFAHYhxEfBhggac+zxAUJkNodAgZGiNmX9JHpuZ4SlpZuuyec7EvGeKWFFBEVPoWC7STzWhgM3se74Us1k/QCcQ0NP/Bh9Ic8RPev5d0ZCT1qiQ+wQonzbfFGRZEoXvQabEHPi0bfd+KsgVVkwcTRsmxC8Ml4xb020PigqOuPP5N9wHDfKAQJPJiPF9C6HzaVE1uoQz+jYYg9NPsgYmNlHefXn/s61PHP5556dOL8+tL8JDaTzFnYyKfQ+4L6LXiLVMVVCM+fJp0YVfCYCmyrJRJGgyxbyIeC72drEAGKH7Z+CQyVlwC3bXZKv1v80eFCRujMTj5JvaqXCRArIxlkQNhvhQmFTtXf8Y552JBzsU8Ej6L1XRzWFtZSLkZ1WSv44STexEBow7hEWntVcbGAWx+eQD+buBuqZXzGZ0epxuNMpLQRnCw6M3i6rJ2lfxuF2s2tBh216u70NmR7vuxgm1o4odAOv0YNKhu6xYZ2zw3CkcZwtb5KNXIrEk+q2iuJV6MbXDlJHZh1m0jncuVVvjYtTIcc8nm/tOWtkIiG9EciOjLnbrYbXfm0HBtFjHuIYguXTedOXLbnvkiB9CWU2EaqxurCoXV+DFf0jLaboUY5biYJbzimtL+soSvDO5nPnu3kuEfwU3uA= + gem: sensu-plugins-kafka + on: + tags: true + all_branches: true + rvm: 2.4.1 + repo: sensu-plugins/sensu-plugins-kafka diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8ce5958 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log +This project adheres to [Semantic Versioning](http://semver.org/). + +This CHANGELOG follows the format located [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) + +## [Unreleased] + +### Added +- Basic Skel to be used to make new plugin repo setup easier. +- PR template +- Rubocop config +- basic testing setup +- removing EOL versions of ruby +- patching for any known CVEs + +[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-kafka/compare/d4eebcfed091899571e21c0e433cceb3e386d2c7...HEAD diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..fa75df1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8e950ad --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2016 Sensu Community Plugins + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md index 5cad5a1..4454be4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ -# sensu-plugins-kafka -Sensu Plugins for kafka +## Sensu-Plugins-kafka + +[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-skel.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-skel) +[![Gem Version](https://badge.fury.io/rb/sensu-plugins-skel.svg)](http://badge.fury.io/rb/sensu-plugins-skel) +[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-skel.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-skel) +[![Community Slack](https://slack.sensu.io/badge.svg)](https://slack.sensu.io/badge) + +## Functionality + +## Files + +## Usage + +## Installation + +[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html) + +## Notes diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..bc4cb8f --- /dev/null +++ b/Rakefile @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'bundler/gem_tasks' +require 'github/markup' +require 'redcarpet' +require 'rspec/core/rake_task' +require 'rubocop/rake_task' +require 'yard' +require 'yard/rake/yardoc_task' +require 'English' +require 'kitchen/rake_tasks' + +YARD::Rake::YardocTask.new do |t| + OTHER_PATHS = %w[].freeze + t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS] + t.options = %w[--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md] +end + +RuboCop::RakeTask.new + +RSpec::Core::RakeTask.new(:spec) do |r| + r.pattern = FileList['**/**/*_spec.rb'] +end + +desc 'Make all plugins executable' +task :make_bin_executable do + `chmod -R +x bin/*` +end + +desc 'Test for binstubs' +task :check_binstubs do + unless Dir.glob('bin/**/*.rb').empty? + bin_list = Gem::Specification.load('sensu-plugins-skel.gemspec').executables + bin_list.each do |b| + `which #{ b }` + unless $CHILD_STATUS.success? + puts "#{b} was not a binstub" + exit + end + end + end +end + +Kitchen::RakeTasks.new +desc 'Alias for kitchen:all' +task integration: 'kitchen:all' + +task default: %i[spec make_bin_executable yard rubocop check_binstubs integration] +task quick: %i[make_bin_executable yard rubocop check_binstubs] diff --git a/lib/sensu-plugins-kafka.rb b/lib/sensu-plugins-kafka.rb new file mode 100644 index 0000000..0eabe6b --- /dev/null +++ b/lib/sensu-plugins-kafka.rb @@ -0,0 +1 @@ +require 'sensu-plugins-kafka/version' diff --git a/lib/sensu-plugins-kafka/version.rb b/lib/sensu-plugins-kafka/version.rb new file mode 100644 index 0000000..6d5fcf9 --- /dev/null +++ b/lib/sensu-plugins-kafka/version.rb @@ -0,0 +1,9 @@ +module SensuPluginsKafka + module Version + MAJOR = 0 + MINOR = 0 + PATCH = 1 + + VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') + end +end diff --git a/sensu-plugins-kafka.gemspec b/sensu-plugins-kafka.gemspec new file mode 100644 index 0000000..c549379 --- /dev/null +++ b/sensu-plugins-kafka.gemspec @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +require 'date' +require_relative 'lib/sensu-plugins-kafka' + +Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength + s.authors = ['Sensu-Plugins and contributors'] + s.date = Date.today.to_s + s.description = 'Sensu kafka plugins' + s.email = '' + s.executables = Dir.glob('bin/**/*.rb').map { |file| File.basename(file) } + s.files = Dir.glob('{bin,lib}/**/*') + %w[LICENSE README.md CHANGELOG.md] + s.homepage = 'https://github.com/sensu-plugins/sensu-plugins-kafka' + s.license = 'MIT' + s.metadata = { 'maintainer' => 'sensu-plugin', + 'development_status' => 'active', + 'production_status' => 'unstable - testing recommended', + 'release_draft' => 'false', + 'release_prerelease' => 'false' } + s.name = 'sensu-plugins-kafka' + s.platform = Gem::Platform::RUBY + s.post_install_message = 'You can use the embedded Ruby by setting EMBEDDED_RUBY=true in /etc/default/sensu' + s.require_paths = ['lib'] + s.required_ruby_version = '>= 2.3.0' + s.summary = 'Sensu plugins for kafka' + s.test_files = s.files.grep(%r{^(test|spec|features)/}) + s.version = SensuPluginsKafka::Version::VER_STRING + + s.add_runtime_dependency 'sensu-plugin', '~> 2.0' + + s.add_development_dependency 'bundler', '~> 1.15' + s.add_development_dependency 'github-markup', '~> 1.3' + s.add_development_dependency 'kitchen-docker', '~> 2.6' + s.add_development_dependency 'kitchen-localhost', '~> 0.3' + s.add_development_dependency 'pry', '~> 0.10' + s.add_development_dependency 'rake', '~> 12.0' + s.add_development_dependency 'redcarpet', '~> 3.2' + s.add_development_dependency 'rspec', '~> 3.4' + s.add_development_dependency 'rubocop', '~> 0.49.0' + s.add_development_dependency 'serverspec', '~> 2.36.1' + s.add_development_dependency 'test-kitchen', '~> 1.6' + s.add_development_dependency 'yard', '~> 0.9.11' +end diff --git a/test/fixtures/bootstrap.sh b/test/fixtures/bootstrap.sh new file mode 100644 index 0000000..3125463 --- /dev/null +++ b/test/fixtures/bootstrap.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Set up a super simple web server and make it accept GET and POST requests +# for Sensu plugin testing. +# + +set -e + +# base utilities that need to exist to start bootatraping +apt-get update +# apt-get install -y wget + +# setup the rubies +source /etc/profile +DATA_DIR=/tmp/kitchen/data +RUBY_HOME=${MY_RUBY_HOME} + +# Start bootatraping + +## install some required deps for pg_gem to install + + +# End of Actual bootatrap + +# Install gems +cd $DATA_DIR +SIGN_GEM=false gem build sensu-plugins-kafka.gemspec +gem install sensu-plugins-kafka-*.gem diff --git a/test/integration/helpers/serverspec/check-example-dns_spec.rb b/test/integration/helpers/serverspec/check-example-dns_spec.rb new file mode 100644 index 0000000..5860b22 --- /dev/null +++ b/test/integration/helpers/serverspec/check-example-dns_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +# require 'spec_helper' +# require 'shared_spec' +# +# gem_path = '/usr/local/bin' +# check_name = 'check-dns.rb' +# check = "#{gem_path}/#{check_name}" +# domain = 'benabrams.it' +# +# describe 'ruby environment' do +# it_behaves_like 'ruby checks', check +# end +# +# describe command("#{check} --domain #{domain}") do +# its(:exit_status) { should eq 0 } +# its(:stdout) { should match(/DNS OK: Resolved benabrams.it A/) } +# end +# +# describe command("#{check} --domain sensutest-a.#{domain} --result 1.1.1.1") do +# its(:exit_status) { should eq 0 } +# its(:stdout) { should match(/DNS OK: Resolved UNCHECKED sensutest-a.benabrams.it A included 1.1.1.1/) } +# end +# +# describe command("#{check} --domain sensutest-a.#{domain} --result 1.1.2.2") do +# its(:exit_status) { should eq 0 } +# its(:stdout) { should match(/DNS OK: Resolved UNCHECKED sensutest-a.benabrams.it A included 1.1.2.2/) } +# end +# +# describe command("#{check} --domain sensutest-a.#{domain} --result 1.1.1.1,1.1.2.2") do +# its(:exit_status) { should eq 0 } +# its(:stdout) { should match(/DNS OK: Resolved UNCHECKED sensutest-a.benabrams.it A included 1.1.1.1,1.1.2.2/) } +# end +# +# describe command(check.to_s) do +# its(:exit_status) { should eq 3 } +# its(:stdout) { should match(/DNS UNKNOWN: No domain specified/) } +# end +# +# describe command("#{check} --domain some.non.existent.domain.tld --timeout 1") do +# its(:exit_status) { should eq 2 } +# its(:stdout) { should match(/DNS CRITICAL: 0% of tests succeeded: Could not resolve some.non.existent.domain.tld A record/) } +# end +# +# describe command("#{check} --domain sensutest-a.#{domain} --request_count 2") do +# its(:exit_status) { should eq 0 } +# its(:stdout) { should match(/DNS OK: Resolved sensutest-a.benabrams.it A/) } +# end +# +# describe command("#{check} --domain sensutest-a.#{domain} --request_count 5") do +# its(:exit_status) { should eq 0 } +# its(:stdout) { should match(/DNS OK: Resolved sensutest-a.benabrams.it A/) } +# end diff --git a/test/integration/helpers/serverspec/shared_spec.rb b/test/integration/helpers/serverspec/shared_spec.rb new file mode 100644 index 0000000..545a1e5 --- /dev/null +++ b/test/integration/helpers/serverspec/shared_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +shared_examples_for 'ruby checks' do |check| + describe command('which ruby') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match(/\/usr\/local\/bin\/ruby/) } + end + + describe command('which gem') do + its(:exit_status) { should eq 0 } + its(:stdout) { should match(/\/usr\/local\/bin\/gem/) } + end + + describe command("which #{check}") do + its(:exit_status) { should eq 0 } + its(:stdout) { should match(Regexp.new(Regexp.escape(check))) } + end + + describe file(check) do + it { should be_file } + it { should be_executable } + end +end diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb new file mode 100644 index 0000000..06657bc --- /dev/null +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +require 'serverspec' + +set :backend, :exec diff --git a/test/integration/ruby-230/serverspec/default_spec.rb b/test/integration/ruby-230/serverspec/default_spec.rb new file mode 100644 index 0000000..c2a6fe0 --- /dev/null +++ b/test/integration/ruby-230/serverspec/default_spec.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'shared_spec' diff --git a/test/integration/ruby-241/serverspec/default_spec.rb b/test/integration/ruby-241/serverspec/default_spec.rb new file mode 100644 index 0000000..c2a6fe0 --- /dev/null +++ b/test/integration/ruby-241/serverspec/default_spec.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'shared_spec'