Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for bonsai #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
53 changes: 53 additions & 0 deletions .bonsai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
description: "#{repo}"
builds:
- platform: "alpine"
arch: "amd64"
asset_filename: "#{repo}_#{version}_alpine_linux_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'amd64'"
- "entity.system.platform == 'alpine'"
- "entity.system.platform_version.split('.')[0] == '3'"
- platform: "alpine3.8"
arch: "amd64"
asset_filename: "#{repo}_#{version}_alpine3.8_linux_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'amd64'"
- "entity.system.platform == 'alpine'"
- platform: "centos6"
arch: "amd64"
asset_filename: "#{repo}_#{version}_centos6_linux_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'amd64'"
- "entity.system.platform_family == 'rhel'"
- "entity.system.platform_version.split('.')[0] == '6'"
- platform: "centos7"
arch: "amd64"
asset_filename: "#{repo}_#{version}_centos7_linux_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'amd64'"
- "entity.system.platform_family == 'rhel'"
- "entity.system.platform_version.split('.')[0] == '7'"
- platform: "debian"
arch: "amd64"
asset_filename: "#{repo}_#{version}_debian_linux_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'amd64'"
- "entity.system.platform_family == 'debian'"
- platform: "debian9"
arch: "amd64"
asset_filename: "#{repo}_#{version}_debian9_linux_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'amd64'"
43 changes: 33 additions & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
AllCops:
TargetRubyVersion: 2.3

MethodLength:
Metrics/MethodLength:
Max: 200

LineLength:
Layout/LineLength:
Max: 160

AbcSize:
Max: 100
Metrics/AbcSize:
Max: 220

FileName:
Metrics/PerceivedComplexity:
Enabled: false

PerceivedComplexity:
Metrics/CyclomaticComplexity:
Enabled: false

CyclomaticComplexity:
Metrics/ClassLength:
Enabled: false

ClassLength:
Naming/FileName:
Enabled: false

IfUnlessModifier:
Style/IfUnlessModifier:
Enabled: false

RegexpLiteral:
Style/RegexpLiteral:
Enabled: false

Style/Documentation:
Enabled: false

Style/Next:
Enabled: false

# ruby 2.1, 2.2 support
Style/NumericPredicate:
Enabled: false

Style/SafeNavigation:
Enabled: false


# highly opinionated, subject to false positives, and likely to break valid code
Style/FormatStringToken:
Enabled: false

# testing
Metrics/BlockLength:
Enabled: true
Exclude:
- 'test/**/*'
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-plugins-etcd.gemspec
Expand Down
11 changes: 7 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'github/markup'
require 'redcarpet'
Expand All @@ -7,9 +9,9 @@ require 'yard'
require 'yard/rake/yardoc_task'

YARD::Rake::YardocTask.new do |t|
OTHER_PATHS = %w().freeze
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)
t.options = %w[--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md]
end

RuboCop::RakeTask.new
Expand All @@ -27,12 +29,13 @@ desc 'Test for binstubs'
task :check_binstubs do
bin_list = Gem::Specification.load('sensu-plugins-etcd.gemspec').executables
bin_list.each do |b|
`which #{ b }`
`which #{b}`
unless $CHILD_STATUS.success?
puts "#{b} was not a binstub"
exit
end
end
end

task default: [:spec, :make_bin_executable, :yard, :rubocop, :check_binstubs]
task default: %i[spec make_bin_executable yard rubocop check_binstubs]
task quick: %i[make_bin_executable yard rubocop check_binstubs]
6 changes: 4 additions & 2 deletions bin/check-etcd-peer-count.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-etcd-peer-count
#
Expand Down Expand Up @@ -88,8 +90,8 @@ def run
timeout: 5,
ssl_client_cert: (OpenSSL::X509::Certificate.new(File.read(config[:cert])) unless config[:cert].nil?),
ssl_client_key: (OpenSSL::PKey.read(File.read(config[:key]), config[:passphrase]) unless config[:key].nil?),
ssl_ca_file: config[:ca],
verify_ssl: config[:insecure] ? 0 : 1).get
ssl_ca_file: config[:ca],
verify_ssl: config[:insecure] ? 0 : 1).get
peers = JSON.parse(r.to_str)['members'].length
if r.code == 200 && peers == config[:peercount]
ok 'Etcd has correct number of peers'
Expand Down
7 changes: 4 additions & 3 deletions bin/check-etcd.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-etcd
#
Expand Down Expand Up @@ -110,7 +112,6 @@ def run
critical 'Etcd unhealthy'
end
end

rescue Errno::ECONNREFUSED => e
critical 'Etcd is not responding' + e.message
rescue RestClient::RequestTimeout
Expand All @@ -125,7 +126,7 @@ def request(path, server)
timeout: 5,
ssl_client_cert: (OpenSSL::X509::Certificate.new(File.read(config[:cert])) unless config[:cert].nil?),
ssl_client_key: (OpenSSL::PKey.read(File.read(config[:key]), config[:passphrase]) unless config[:key].nil?),
ssl_ca_file: config[:ca],
verify_ssl: config[:insecure] ? 0 : 1).get
ssl_ca_file: config[:ca],
verify_ssl: config[:insecure] ? 0 : 1).get
end
end
15 changes: 10 additions & 5 deletions bin/check-flannel-subnet-count.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-flannel-subnet-count
#
Expand Down Expand Up @@ -83,7 +85,8 @@ class FlannelSubnetStatus < Sensu::Plugin::Check::CLI
proc: proc(&:to_i)

def run
begin # Get the network configuration
# Get the network configuration
begin
flannel_config = request('v2/keys/coreos.com/network/config', config[:server])
# The value is stored as a json string within the json, so we have to parse, pull out the string and re-parse...
num_address = JSON.parse(JSON.parse(flannel_config.to_str)['node']['value'])['Network']
Expand All @@ -92,15 +95,17 @@ def run
critical "Could not fetch network configuration: #{e.message}"
end

begin # Calculate the number of available subnets
# Calculate the number of available subnets
begin
network_cidr = num_address[num_address.index('/') + 1..-1]
num_addresses = 2**(32 - network_cidr.to_i)
num_subnets = num_addresses / (2**(32 - subnet_len.to_i))
rescue StandardError => e
critical "Could not parse network configuration: #{e.message}"
end

begin # Calculate the actual number of subnets in use
# Calculate the actual number of subnets in use
begin
data = JSON.parse(request('v2/keys/coreos.com/network/subnets', config[:server]))
num_address_used = data['node']['nodes'].size
rescue StandardError => e
Expand All @@ -123,8 +128,8 @@ def request(path, server)
timeout: 5,
ssl_client_cert: (OpenSSL::X509::Certificate.new(File.read(config[:cert])) unless config[:cert].nil?),
ssl_client_key: (OpenSSL::PKey.read(File.read(config[:key]), config[:passphrase]) unless config[:key].nil?),
ssl_ca_file: config[:ca],
verify_ssl: config[:insecure] ? 0 : 1
ssl_ca_file: config[:ca],
verify_ssl: config[:insecure] ? 0 : 1
).get
end
end
28 changes: 15 additions & 13 deletions bin/metrics-etcd.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# etcd-metrics
#
Expand Down Expand Up @@ -88,19 +90,19 @@ class EtcdMetrics < Sensu::Plugin::Metric::CLI::Graphite
long: '--ssl'

def run
if config[:ssl]
client = Etcd.client(
host: config[:etcd_host],
port: config[:etcd_port],
use_ssl: config[:ssl],
verify_mode: (config[:insecure] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER),
ca_file: config[:ca],
ssl_cert: (OpenSSL::X509::Certificate.new(File.read(config[:cert])) unless config[:cert].nil?),
ssl_key: (OpenSSL::PKey.read(File.read(config[:key]), config[:passphrase]) unless config[:key].nil?)
)
else
client = Etcd.client(host: config[:etcd_host], port: config[:etcd_port])
end
client = if config[:ssl]
Etcd.client(
host: config[:etcd_host],
port: config[:etcd_port],
use_ssl: config[:ssl],
verify_mode: (config[:insecure] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER),
ca_file: config[:ca],
ssl_cert: (OpenSSL::X509::Certificate.new(File.read(config[:cert])) unless config[:cert].nil?),
ssl_key: (OpenSSL::PKey.read(File.read(config[:key]), config[:passphrase]) unless config[:key].nil?)
)
else
Etcd.client(host: config[:etcd_host], port: config[:etcd_port])
end
client.stats(:self).each do |k, v|
output([config[:scheme], 'self', k].join('.'), v) if v.is_a? Integer
end
Expand Down
2 changes: 2 additions & 0 deletions lib/sensu-plugins-etcd.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: false

require 'sensu-plugins-etcd/version'
2 changes: 2 additions & 0 deletions lib/sensu-plugins-etcd/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: false

module SensuPluginsEtcd
module Version
MAJOR = 1
Expand Down
28 changes: 15 additions & 13 deletions sensu-plugins-etcd.gemspec
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'date'
require_relative 'lib/sensu-plugins-etcd'

Gem::Specification.new do |s|
Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength
s.authors = ['Sensu-Plugins and contributors']
s.date = Date.today.to_s
s.description = 'Sensu plugins for etcd health and status monitoring'
s.email = '<[email protected]>'
s.executables = Dir.glob('bin/**/*.rb').map { |file| File.basename(file) }
s.files = Dir.glob('{bin,lib}/**/*') + %w(LICENSE README.md CHANGELOG.md)
s.files = Dir.glob('{bin,lib}/**/*') + %w[LICENSE README.md CHANGELOG.md]
s.homepage = 'https://github.com/sensu-plugins/sensu-plugins-etcd'
s.license = 'MIT'
s.metadata = { 'maintainer' => 'sensu-plugin',
s.metadata = { 'maintainer' => 'sensu-plugin',
'development_status' => 'active',
'production_status' => 'unstable - testing recommended',
'release_draft' => 'false',
'production_status' => 'unstable - testing recommended',
'release_draft' => 'false',
'release_prerelease' => 'false' }
s.name = 'sensu-plugins-etcd'
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.0.0'
s.required_ruby_version = '>= 2.3.0'
s.summary = 'Sensu plugins for etcd'
s.test_files = s.files.grep(%r{^(test|spec|features)/})
s.version = SensuPluginsEtcd::Version::VER_STRING

s.add_runtime_dependency 'rest-client', '1.8.0'
s.add_runtime_dependency 'sensu-plugin', '>= 1.3', '< 5.0'
s.add_runtime_dependency 'etcd', '0.3.0'
s.add_runtime_dependency 'etcd', '0.3.0'
s.add_runtime_dependency 'rest-client', '~> 2.1'
s.add_runtime_dependency 'sensu-plugin', '~> 4.0'

s.add_development_dependency 'bundler', '~> 1.7'
s.add_development_dependency 'bundler', '~> 2.1'
s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
s.add_development_dependency 'github-markup', '~> 3.0'
s.add_development_dependency 'pry', '~> 0.10'
s.add_development_dependency 'rake', '~> 12.3'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'redcarpet', '~> 3.2'
s.add_development_dependency 'rubocop', '~> 0.40.0'
s.add_development_dependency 'rspec', '~> 3.4'
s.add_development_dependency 'rubocop', '~> 0.79.0'
s.add_development_dependency 'yard', '~> 0.8'
end
2 changes: 2 additions & 0 deletions test/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: false

require 'codeclimate-test-reporter'
CodeClimate::TestReporter.start