From 242d2ac2a1fc7fe14334c1f7ed7904c1f25ba89c Mon Sep 17 00:00:00 2001 From: csolei Date: Wed, 29 Nov 2017 00:55:32 -0800 Subject: [PATCH 1/5] adding cert option to some checks and metrics --- bin/check-es-circuit-breakers.rb | 12 +++++++++++- bin/check-es-cluster-status.rb | 11 ++++++++++- bin/check-es-node-status.rb | 6 +++++- bin/metrics-es-cluster.rb | 11 ++++++++++- bin/metrics-es-node-graphite.rb | 11 ++++++++++- bin/metrics-es-node.rb | 11 ++++++++++- 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/bin/check-es-circuit-breakers.rb b/bin/check-es-circuit-breakers.rb index da98176..b9e6b11 100755 --- a/bin/check-es-circuit-breakers.rb +++ b/bin/check-es-circuit-breakers.rb @@ -69,6 +69,12 @@ class ESCircuitBreaker < Sensu::Plugin::Check::CLI short: '-e', long: '--https' + option :cert, + description: 'Cert to use', + short: '-c CERT', + long: '--cert CERT' + + option :localhost, description: 'only check local node', short: '-l', @@ -89,7 +95,11 @@ def get_es_resource(resource) 'http' end - r = RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + r = if config[:cert] + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + else + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + end JSON.parse(r.get) rescue Errno::ECONNREFUSED critical 'Connection refused' diff --git a/bin/check-es-cluster-status.rb b/bin/check-es-cluster-status.rb index b372cfd..b625f5b 100755 --- a/bin/check-es-cluster-status.rb +++ b/bin/check-es-cluster-status.rb @@ -83,6 +83,11 @@ class ESClusterStatus < Sensu::Plugin::Check::CLI short: '-e', long: '--https' + option :cert, + description: 'Cert to use', + short: '-c CERT', + long: '--cert CERT' + option :alert_status, description: 'Only alert when status matches given RED/YELLOW/GREEN or if blank all statuses', long: '--alert-status STATUS', @@ -102,7 +107,11 @@ def get_es_resource(resource) 'http' end - r = RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + r = if config[:cert] + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + else + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + end JSON.parse(r.get) rescue Errno::ECONNREFUSED critical 'Connection refused' diff --git a/bin/check-es-node-status.rb b/bin/check-es-node-status.rb index b614cc7..5ddc10b 100755 --- a/bin/check-es-node-status.rb +++ b/bin/check-es-node-status.rb @@ -87,7 +87,11 @@ def get_es_resource(resource) 'http' end - r = RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + r = if config[:cert] + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + else + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + end r.get rescue Errno::ECONNREFUSED critical 'Connection refused' diff --git a/bin/metrics-es-cluster.rb b/bin/metrics-es-cluster.rb index 267cfc9..d293a7c 100755 --- a/bin/metrics-es-cluster.rb +++ b/bin/metrics-es-cluster.rb @@ -90,6 +90,11 @@ class ESClusterMetrics < Sensu::Plugin::Metric::CLI::Graphite short: '-e', long: '--https' + option :cert, + description: 'Cert to use', + short: '-c CERT', + long: '--cert CERT' + def acquire_es_version info = get_es_resource('/') info['version']['number'] @@ -108,7 +113,11 @@ def get_es_resource(resource) 'http' end - r = RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + r = if config[:cert] + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + else + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + end JSON.parse(r.get) rescue Errno::ECONNREFUSED warning 'Connection refused' diff --git a/bin/metrics-es-node-graphite.rb b/bin/metrics-es-node-graphite.rb index 85f303e..0334d5d 100755 --- a/bin/metrics-es-node-graphite.rb +++ b/bin/metrics-es-node-graphite.rb @@ -115,6 +115,11 @@ class ESNodeGraphiteMetrics < Sensu::Plugin::Metric::CLI::Graphite short: '-e', long: '--https' + option :cert, + description: 'Cert to use', + short: '-c CERT', + long: '--cert CERT' + def get_es_resource(resource) headers = {} if config[:user] && config[:password] @@ -128,7 +133,11 @@ def get_es_resource(resource) 'http' end - r = RestClient::Resource.new("#{protocol}://#{config[:server]}:#{config[:port]}#{resource}?pretty", timeout: config[:timeout], headers: headers) + r = if config[:cert] + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + else + RestClient::Resource.new("#{protocol}://#{config[:server]}:#{config[:port]}#{resource}?pretty", timeout: config[:timeout], headers: headers) + end JSON.parse(r.get) rescue Errno::ECONNREFUSED warning 'Connection refused' diff --git a/bin/metrics-es-node.rb b/bin/metrics-es-node.rb index 5b8e2f3..6904b4f 100755 --- a/bin/metrics-es-node.rb +++ b/bin/metrics-es-node.rb @@ -71,6 +71,11 @@ class ESMetrics < Sensu::Plugin::Metric::CLI::Graphite short: '-e', long: '--https' + option :cert, + description: 'Cert to use', + short: '-c CERT', + long: '--cert CERT' + def acquire_es_version info = get_es_resource('/') info['version']['number'] @@ -89,7 +94,11 @@ def get_es_resource(resource) 'http' end - r = RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + r = if config[:cert] + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + else + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + end JSON.parse(r.get) rescue Errno::ECONNREFUSED warning 'Connection refused' From 330234f26d099da51f359fe6c17a92d238d927fa Mon Sep 17 00:00:00 2001 From: csolei Date: Wed, 29 Nov 2017 08:51:18 -0800 Subject: [PATCH 2/5] ran rubocop -a --- Rakefile | 6 +++--- bin/check-es-circuit-breakers.rb | 11 +++++------ bin/check-es-cluster-status.rb | 2 +- bin/check-es-indices-sizes.rb | 1 - bin/check-es-node-status.rb | 2 +- bin/metrics-es-cluster.rb | 16 ++++++++-------- bin/metrics-es-node-graphite.rb | 14 +++++++------- bin/metrics-es-node.rb | 2 +- sensu-plugins-elasticsearch.gemspec | 10 +++++----- 9 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Rakefile b/Rakefile index 51cb458..f2c9558 100644 --- a/Rakefile +++ b/Rakefile @@ -8,9 +8,9 @@ require 'yard/rake/yardoc_task' require 'English' 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 @@ -36,4 +36,4 @@ task :check_binstubs do end end -task default: [:spec, :make_bin_executable, :yard, :rubocop, :check_binstubs] +task default: %i[spec make_bin_executable yard rubocop check_binstubs] diff --git a/bin/check-es-circuit-breakers.rb b/bin/check-es-circuit-breakers.rb index b9e6b11..73f3bb8 100755 --- a/bin/check-es-circuit-breakers.rb +++ b/bin/check-es-circuit-breakers.rb @@ -69,11 +69,10 @@ class ESCircuitBreaker < Sensu::Plugin::Check::CLI short: '-e', long: '--https' - option :cert, - description: 'Cert to use', - short: '-c CERT', - long: '--cert CERT' - + option :cert, + description: 'Cert to use', + short: '-c CERT', + long: '--cert CERT' option :localhost, description: 'only check local node', @@ -96,7 +95,7 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) else RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) end diff --git a/bin/check-es-cluster-status.rb b/bin/check-es-cluster-status.rb index b625f5b..3af8e4c 100755 --- a/bin/check-es-cluster-status.rb +++ b/bin/check-es-cluster-status.rb @@ -108,7 +108,7 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) else RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) end diff --git a/bin/check-es-indices-sizes.rb b/bin/check-es-indices-sizes.rb index 8243f78..98f10e0 100755 --- a/bin/check-es-indices-sizes.rb +++ b/bin/check-es-indices-sizes.rb @@ -159,7 +159,6 @@ def build_indices_with_sizes def run node_fs_stats = client.nodes.stats metric: 'fs,indices' nodes_being_used = node_fs_stats['nodes'].values.select { |node| node['indices']['store']['size_in_bytes'] > 0 } - # rubocop:disable SingleLineBlockParams # rubocop:disable LineLength used_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] - data['available_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x } # rubocop:enable LineLength diff --git a/bin/check-es-node-status.rb b/bin/check-es-node-status.rb index 5ddc10b..55f9040 100755 --- a/bin/check-es-node-status.rb +++ b/bin/check-es-node-status.rb @@ -88,7 +88,7 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) else RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) end diff --git a/bin/metrics-es-cluster.rb b/bin/metrics-es-cluster.rb index d293a7c..49fab2f 100755 --- a/bin/metrics-es-cluster.rb +++ b/bin/metrics-es-cluster.rb @@ -90,10 +90,10 @@ class ESClusterMetrics < Sensu::Plugin::Metric::CLI::Graphite short: '-e', long: '--https' - option :cert, - description: 'Cert to use', - short: '-c CERT', - long: '--cert CERT' + option :cert, + description: 'Cert to use', + short: '-c CERT', + long: '--cert CERT' def acquire_es_version info = get_es_resource('/') @@ -114,7 +114,7 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) else RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) end @@ -140,8 +140,8 @@ def master? end def acquire_health - health = get_es_resource('/_cluster/health').reject { |k, _v| %w(cluster_name timed_out).include?(k) } - health['status'] = %w(red yellow green).index(health['status']) + health = get_es_resource('/_cluster/health').reject { |k, _v| %w[cluster_name timed_out].include?(k) } + health['status'] = %w[red yellow green].index(health['status']) health end @@ -187,7 +187,7 @@ def acquire_allocation_status cluster_config = get_es_resource('/_cluster/settings') transient_settings = cluster_config['transient'] if transient_settings.key?('cluster') - return %w(none new_primaries primaries all).index(transient_settings['cluster']['routing']['allocation']['enable']) + return %w[none new_primaries primaries all].index(transient_settings['cluster']['routing']['allocation']['enable']) else return nil end diff --git a/bin/metrics-es-node-graphite.rb b/bin/metrics-es-node-graphite.rb index 0334d5d..4f8ac8e 100755 --- a/bin/metrics-es-node-graphite.rb +++ b/bin/metrics-es-node-graphite.rb @@ -115,10 +115,10 @@ class ESNodeGraphiteMetrics < Sensu::Plugin::Metric::CLI::Graphite short: '-e', long: '--https' - option :cert, - description: 'Cert to use', - short: '-c CERT', - long: '--cert CERT' + option :cert, + description: 'Cert to use', + short: '-c CERT', + long: '--cert CERT' def get_es_resource(resource) headers = {} @@ -134,7 +134,7 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) else RestClient::Resource.new("#{protocol}://#{config[:server]}:#{config[:port]}#{resource}?pretty", timeout: config[:timeout], headers: headers) end @@ -161,7 +161,7 @@ def run es_version = Gem::Version.new(acquire_es_version) if es_version >= Gem::Version.new('3.0.0') - stats_query_array = %w(indices http transport) + stats_query_array = %w[indices http transport] stats_query_array.push('jvm') if jvm_stats == true stats_query_array.push('os') if os_stat == true stats_query_array.push('process') if process_stats == true @@ -169,7 +169,7 @@ def run stats_query_array.push('fs') if fs_stats == true stats_query_string = stats_query_array.join(',') elsif es_version >= Gem::Version.new('1.0.0') - stats_query_array = %w(indices http network transport thread_pool) + stats_query_array = %w[indices http network transport thread_pool] stats_query_array.push('jvm') if jvm_stats == true stats_query_array.push('os') if os_stat == true stats_query_array.push('process') if process_stats == true diff --git a/bin/metrics-es-node.rb b/bin/metrics-es-node.rb index 6904b4f..e37f2a8 100755 --- a/bin/metrics-es-node.rb +++ b/bin/metrics-es-node.rb @@ -95,7 +95,7 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: "#{config[:cert]}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) else RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) end diff --git a/sensu-plugins-elasticsearch.gemspec b/sensu-plugins-elasticsearch.gemspec index 464f4a1..a33bda7 100644 --- a/sensu-plugins-elasticsearch.gemspec +++ b/sensu-plugins-elasticsearch.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| service health and metrics for cluster, node, and more.' 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.files = Dir.glob('{bin,lib}/**/*') + %w[LICENSE README.md CHANGELOG.md] s.homepage = 'https://github.com/sensu-plugins/sensu-plugins-elasticsearch' s.license = 'MIT' s.metadata = { 'maintainer' => 'sensu-plugin', @@ -33,10 +33,10 @@ Gem::Specification.new do |s| s.test_files = s.files.grep(%r{^(test|spec|features)/}) s.version = SensuPluginsElasticsearch::Version::VER_STRING - s.add_runtime_dependency 'rest-client', '1.8.0' - s.add_runtime_dependency 'elasticsearch', '~> 1.0.14' - s.add_runtime_dependency 'aws-es-transport', '~> 0.1' + s.add_runtime_dependency 'aws-es-transport', '~> 0.1' s.add_runtime_dependency 'aws-sdk', ['>= 2.1.14', '< 2.5', '~> 2.1'] + s.add_runtime_dependency 'elasticsearch', '~> 1.0.14' + s.add_runtime_dependency 'rest-client', '1.8.0' s.add_runtime_dependency 'sensu-plugin', '~> 1.2' s.add_development_dependency 'bundler', '~> 1.7' @@ -45,7 +45,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'pry', '~> 0.10' s.add_development_dependency 'rake', '~> 10.0' s.add_development_dependency 'redcarpet', '~> 3.2' - s.add_development_dependency 'rubocop', '~> 0.40.0' s.add_development_dependency 'rspec', '~> 3.1' + s.add_development_dependency 'rubocop', '~> 0.40.0' s.add_development_dependency 'yard', '~> 0.8' end From 74a54ed35de30a09da7cc39ae9e1f8ee4301467b Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Fri, 29 Dec 2017 15:20:13 -0800 Subject: [PATCH 3/5] appease the cops --- Rakefile | 6 +++--- bin/check-es-circuit-breakers.rb | 9 +++++++-- bin/check-es-cluster-status.rb | 9 +++++++-- bin/check-es-indices-sizes.rb | 8 ++++---- bin/check-es-node-status.rb | 9 +++++++-- bin/metrics-es-cluster.rb | 15 ++++++++++----- bin/metrics-es-node-graphite.rb | 13 +++++++++---- bin/metrics-es-node.rb | 9 +++++++-- sensu-plugins-elasticsearch.gemspec | 2 +- 9 files changed, 55 insertions(+), 25 deletions(-) diff --git a/Rakefile b/Rakefile index f2c9558..5b451cf 100644 --- a/Rakefile +++ b/Rakefile @@ -8,9 +8,9 @@ require 'yard/rake/yardoc_task' require 'English' 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 @@ -36,4 +36,4 @@ task :check_binstubs do end end -task default: %i[spec make_bin_executable yard rubocop check_binstubs] +task default: %i(spec make_bin_executable yard rubocop check_binstubs) diff --git a/bin/check-es-circuit-breakers.rb b/bin/check-es-circuit-breakers.rb index 73f3bb8..490316e 100755 --- a/bin/check-es-circuit-breakers.rb +++ b/bin/check-es-circuit-breakers.rb @@ -95,9 +95,14 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + ssl_ca_file: config[:cert].to_s, + timeout: config[:timeout], + headers: headers) else - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + timeout: config[:timeout], + headers: headers) end JSON.parse(r.get) rescue Errno::ECONNREFUSED diff --git a/bin/check-es-cluster-status.rb b/bin/check-es-cluster-status.rb index 3af8e4c..dabb067 100755 --- a/bin/check-es-cluster-status.rb +++ b/bin/check-es-cluster-status.rb @@ -108,9 +108,14 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + ssl_ca_file: config[:cert].to_s, + timeout: config[:timeout], + headers: headers) else - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + timeout: config[:timeout], + headers: headers) end JSON.parse(r.get) rescue Errno::ECONNREFUSED diff --git a/bin/check-es-indices-sizes.rb b/bin/check-es-indices-sizes.rb index 98f10e0..b1c840a 100755 --- a/bin/check-es-indices-sizes.rb +++ b/bin/check-es-indices-sizes.rb @@ -159,11 +159,11 @@ def build_indices_with_sizes def run node_fs_stats = client.nodes.stats metric: 'fs,indices' nodes_being_used = node_fs_stats['nodes'].values.select { |node| node['indices']['store']['size_in_bytes'] > 0 } - # rubocop:disable LineLength - used_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] - data['available_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x } - # rubocop:enable LineLength + # TODO: come back and cleanup all these rubocop disables with a little refactor + # rubocop:disable Style/SingleLineBlockParams + used_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] - data['available_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x } # rubocop:disable LineLength total_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x } - # rubocop:enable SingleLineBlockParams + # rubocop:enable Style/SingleLineBlockParams LineLength if config[:maximum_megabytes] > 0 target_bytes_used = config[:maximum_megabytes] * 1_000_000 diff --git a/bin/check-es-node-status.rb b/bin/check-es-node-status.rb index 55f9040..7488e92 100755 --- a/bin/check-es-node-status.rb +++ b/bin/check-es-node-status.rb @@ -88,9 +88,14 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + ssl_ca_file: config[:cert].to_s, + timeout: config[:timeout], + headers: headers) else - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + timeout: config[:timeout], + headers: headers) end r.get rescue Errno::ECONNREFUSED diff --git a/bin/metrics-es-cluster.rb b/bin/metrics-es-cluster.rb index 49fab2f..57c09d1 100755 --- a/bin/metrics-es-cluster.rb +++ b/bin/metrics-es-cluster.rb @@ -114,9 +114,14 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + ssl_ca_file: config[:cert].to_s, + timeout: config[:timeout], + headers: headers) else - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + timeout: config[:timeout], + headers: headers) end JSON.parse(r.get) rescue Errno::ECONNREFUSED @@ -140,8 +145,8 @@ def master? end def acquire_health - health = get_es_resource('/_cluster/health').reject { |k, _v| %w[cluster_name timed_out].include?(k) } - health['status'] = %w[red yellow green].index(health['status']) + health = get_es_resource('/_cluster/health').reject { |k, _v| %w(cluster_name timed_out).include?(k) } + health['status'] = %w(red yellow green).index(health['status']) health end @@ -187,7 +192,7 @@ def acquire_allocation_status cluster_config = get_es_resource('/_cluster/settings') transient_settings = cluster_config['transient'] if transient_settings.key?('cluster') - return %w[none new_primaries primaries all].index(transient_settings['cluster']['routing']['allocation']['enable']) + return %w(none new_primaries primaries all).index(transient_settings['cluster']['routing']['allocation']['enable']) else return nil end diff --git a/bin/metrics-es-node-graphite.rb b/bin/metrics-es-node-graphite.rb index 4f8ac8e..82f3842 100755 --- a/bin/metrics-es-node-graphite.rb +++ b/bin/metrics-es-node-graphite.rb @@ -134,9 +134,14 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + ssl_ca_file: config[:cert].to_s, + timeout: config[:timeout], + headers: headers) else - RestClient::Resource.new("#{protocol}://#{config[:server]}:#{config[:port]}#{resource}?pretty", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:server]}:#{config[:port]}#{resource}?pretty", + timeout: config[:timeout], + headers: headers) end JSON.parse(r.get) rescue Errno::ECONNREFUSED @@ -161,7 +166,7 @@ def run es_version = Gem::Version.new(acquire_es_version) if es_version >= Gem::Version.new('3.0.0') - stats_query_array = %w[indices http transport] + stats_query_array = %w(indices http transport) stats_query_array.push('jvm') if jvm_stats == true stats_query_array.push('os') if os_stat == true stats_query_array.push('process') if process_stats == true @@ -169,7 +174,7 @@ def run stats_query_array.push('fs') if fs_stats == true stats_query_string = stats_query_array.join(',') elsif es_version >= Gem::Version.new('1.0.0') - stats_query_array = %w[indices http network transport thread_pool] + stats_query_array = %w(indices http network transport thread_pool) stats_query_array.push('jvm') if jvm_stats == true stats_query_array.push('os') if os_stat == true stats_query_array.push('process') if process_stats == true diff --git a/bin/metrics-es-node.rb b/bin/metrics-es-node.rb index e37f2a8..40592b8 100755 --- a/bin/metrics-es-node.rb +++ b/bin/metrics-es-node.rb @@ -95,9 +95,14 @@ def get_es_resource(resource) end r = if config[:cert] - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", ssl_ca_file: config[:cert].to_s, timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + ssl_ca_file: config[:cert].to_s, + timeout: config[:timeout], + headers: headers) else - RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers) + RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", + timeout: config[:timeout], + headers: headers) end JSON.parse(r.get) rescue Errno::ECONNREFUSED diff --git a/sensu-plugins-elasticsearch.gemspec b/sensu-plugins-elasticsearch.gemspec index a33bda7..8cea5aa 100644 --- a/sensu-plugins-elasticsearch.gemspec +++ b/sensu-plugins-elasticsearch.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| service health and metrics for cluster, node, and more.' 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.files = Dir.glob('{bin,lib}/**/*') + %w(LICENSE README.md CHANGELOG.md) s.homepage = 'https://github.com/sensu-plugins/sensu-plugins-elasticsearch' s.license = 'MIT' s.metadata = { 'maintainer' => 'sensu-plugin', From a1d4538e391f8376546dd825b117198fc1ca1877 Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Mon, 19 Feb 2018 13:18:18 -0800 Subject: [PATCH 4/5] rename cert to cert_file and improve descriptions --- bin/check-es-circuit-breakers.rb | 12 ++++++------ bin/check-es-cluster-status.rb | 12 ++++++------ bin/check-es-node-status.rb | 9 +++++++-- bin/metrics-es-cluster.rb | 12 ++++++------ bin/metrics-es-node-graphite.rb | 12 ++++++------ bin/metrics-es-node.rb | 12 ++++++------ 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/bin/check-es-circuit-breakers.rb b/bin/check-es-circuit-breakers.rb index 490316e..81a4a03 100755 --- a/bin/check-es-circuit-breakers.rb +++ b/bin/check-es-circuit-breakers.rb @@ -69,10 +69,10 @@ class ESCircuitBreaker < Sensu::Plugin::Check::CLI short: '-e', long: '--https' - option :cert, - description: 'Cert to use', - short: '-c CERT', - long: '--cert CERT' + option :cert_file, + description: 'Cert file to use', + short: '-c CERT_FILE', + long: '--cert-file CERT' option :localhost, description: 'only check local node', @@ -94,9 +94,9 @@ def get_es_resource(resource) 'http' end - r = if config[:cert] + r = if config[:cert_file] RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", - ssl_ca_file: config[:cert].to_s, + ssl_ca_file: config[:cert_file].to_s, timeout: config[:timeout], headers: headers) else diff --git a/bin/check-es-cluster-status.rb b/bin/check-es-cluster-status.rb index dabb067..9e502dd 100755 --- a/bin/check-es-cluster-status.rb +++ b/bin/check-es-cluster-status.rb @@ -83,10 +83,10 @@ class ESClusterStatus < Sensu::Plugin::Check::CLI short: '-e', long: '--https' - option :cert, - description: 'Cert to use', - short: '-c CERT', - long: '--cert CERT' + option :cert_file, + description: 'Cert file to use', + short: '-c CERT_FILE', + long: '--cert-file CERT_FILE' option :alert_status, description: 'Only alert when status matches given RED/YELLOW/GREEN or if blank all statuses', @@ -107,9 +107,9 @@ def get_es_resource(resource) 'http' end - r = if config[:cert] + r = if config[:cert_file] RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", - ssl_ca_file: config[:cert].to_s, + ssl_ca_file: config[:cert_file].to_s, timeout: config[:timeout], headers: headers) else diff --git a/bin/check-es-node-status.rb b/bin/check-es-node-status.rb index 7488e92..741c467 100755 --- a/bin/check-es-node-status.rb +++ b/bin/check-es-node-status.rb @@ -68,6 +68,11 @@ class ESNodeStatus < Sensu::Plugin::Check::CLI short: '-e', long: '--https' + option :cert_file, + description: 'Cert file to use', + short: '-c CERT_FILE', + long: '--cert-file CERT_FILE' + option :all, description: 'Check all nodes in the ES cluster', short: '-a', @@ -87,9 +92,9 @@ def get_es_resource(resource) 'http' end - r = if config[:cert] + r = if config[:cert_file] RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", - ssl_ca_file: config[:cert].to_s, + ssl_ca_file: config[:cert_file].to_s, timeout: config[:timeout], headers: headers) else diff --git a/bin/metrics-es-cluster.rb b/bin/metrics-es-cluster.rb index 57c09d1..8abe676 100755 --- a/bin/metrics-es-cluster.rb +++ b/bin/metrics-es-cluster.rb @@ -90,10 +90,10 @@ class ESClusterMetrics < Sensu::Plugin::Metric::CLI::Graphite short: '-e', long: '--https' - option :cert, - description: 'Cert to use', - short: '-c CERT', - long: '--cert CERT' + option :cert_file, + description: 'Cert file to use', + short: '-c CERT_FILE', + long: '--cert-file CERT_FILE' def acquire_es_version info = get_es_resource('/') @@ -113,9 +113,9 @@ def get_es_resource(resource) 'http' end - r = if config[:cert] + r = if config[:cert_file] RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", - ssl_ca_file: config[:cert].to_s, + ssl_ca_file: config[:cert_file].to_s, timeout: config[:timeout], headers: headers) else diff --git a/bin/metrics-es-node-graphite.rb b/bin/metrics-es-node-graphite.rb index 82f3842..25f964f 100755 --- a/bin/metrics-es-node-graphite.rb +++ b/bin/metrics-es-node-graphite.rb @@ -115,10 +115,10 @@ class ESNodeGraphiteMetrics < Sensu::Plugin::Metric::CLI::Graphite short: '-e', long: '--https' - option :cert, - description: 'Cert to use', - short: '-c CERT', - long: '--cert CERT' + option :cert_file, + description: 'Cert file to use', + short: '-c CERT_FILE', + long: '--cert-file CERT_FILE' def get_es_resource(resource) headers = {} @@ -133,9 +133,9 @@ def get_es_resource(resource) 'http' end - r = if config[:cert] + r = if config[:cert_file] RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", - ssl_ca_file: config[:cert].to_s, + ssl_ca_file: config[:cert_file].to_s, timeout: config[:timeout], headers: headers) else diff --git a/bin/metrics-es-node.rb b/bin/metrics-es-node.rb index 40592b8..c0f705f 100755 --- a/bin/metrics-es-node.rb +++ b/bin/metrics-es-node.rb @@ -71,10 +71,10 @@ class ESMetrics < Sensu::Plugin::Metric::CLI::Graphite short: '-e', long: '--https' - option :cert, - description: 'Cert to use', - short: '-c CERT', - long: '--cert CERT' + option :cert_file, + description: 'Cert file to use', + short: '-c CERT_FILE', + long: '--cert CERT_FILE' def acquire_es_version info = get_es_resource('/') @@ -94,9 +94,9 @@ def get_es_resource(resource) 'http' end - r = if config[:cert] + r = if config[:cert_file] RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", - ssl_ca_file: config[:cert].to_s, + ssl_ca_file: config[:cert_file].to_s, timeout: config[:timeout], headers: headers) else From d86b2b14cf2fdffd28d2f2513bfb9974de831569 Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Mon, 19 Feb 2018 15:44:13 -0800 Subject: [PATCH 5/5] remove short "-c" option to avoid confusion with it being used for critical thresholds in other checks in this repo as well as that being a standard across plugins. --- bin/check-es-circuit-breakers.rb | 1 - bin/check-es-cluster-status.rb | 1 - bin/check-es-node-status.rb | 1 - bin/metrics-es-cluster.rb | 1 - bin/metrics-es-node-graphite.rb | 1 - bin/metrics-es-node.rb | 1 - 6 files changed, 6 deletions(-) diff --git a/bin/check-es-circuit-breakers.rb b/bin/check-es-circuit-breakers.rb index 81a4a03..3f96447 100755 --- a/bin/check-es-circuit-breakers.rb +++ b/bin/check-es-circuit-breakers.rb @@ -71,7 +71,6 @@ class ESCircuitBreaker < Sensu::Plugin::Check::CLI option :cert_file, description: 'Cert file to use', - short: '-c CERT_FILE', long: '--cert-file CERT' option :localhost, diff --git a/bin/check-es-cluster-status.rb b/bin/check-es-cluster-status.rb index 9e502dd..5bde70c 100755 --- a/bin/check-es-cluster-status.rb +++ b/bin/check-es-cluster-status.rb @@ -85,7 +85,6 @@ class ESClusterStatus < Sensu::Plugin::Check::CLI option :cert_file, description: 'Cert file to use', - short: '-c CERT_FILE', long: '--cert-file CERT_FILE' option :alert_status, diff --git a/bin/check-es-node-status.rb b/bin/check-es-node-status.rb index 741c467..8f2a933 100755 --- a/bin/check-es-node-status.rb +++ b/bin/check-es-node-status.rb @@ -70,7 +70,6 @@ class ESNodeStatus < Sensu::Plugin::Check::CLI option :cert_file, description: 'Cert file to use', - short: '-c CERT_FILE', long: '--cert-file CERT_FILE' option :all, diff --git a/bin/metrics-es-cluster.rb b/bin/metrics-es-cluster.rb index 8abe676..754e3eb 100755 --- a/bin/metrics-es-cluster.rb +++ b/bin/metrics-es-cluster.rb @@ -92,7 +92,6 @@ class ESClusterMetrics < Sensu::Plugin::Metric::CLI::Graphite option :cert_file, description: 'Cert file to use', - short: '-c CERT_FILE', long: '--cert-file CERT_FILE' def acquire_es_version diff --git a/bin/metrics-es-node-graphite.rb b/bin/metrics-es-node-graphite.rb index 25f964f..b98604e 100755 --- a/bin/metrics-es-node-graphite.rb +++ b/bin/metrics-es-node-graphite.rb @@ -117,7 +117,6 @@ class ESNodeGraphiteMetrics < Sensu::Plugin::Metric::CLI::Graphite option :cert_file, description: 'Cert file to use', - short: '-c CERT_FILE', long: '--cert-file CERT_FILE' def get_es_resource(resource) diff --git a/bin/metrics-es-node.rb b/bin/metrics-es-node.rb index c0f705f..7b8d810 100755 --- a/bin/metrics-es-node.rb +++ b/bin/metrics-es-node.rb @@ -73,7 +73,6 @@ class ESMetrics < Sensu::Plugin::Metric::CLI::Graphite option :cert_file, description: 'Cert file to use', - short: '-c CERT_FILE', long: '--cert CERT_FILE' def acquire_es_version