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

adding cert option to some checks and metrics #101

Merged
merged 5 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure this changes in a newer version of rubocop, but that change is I believe breaking so we can change that back when we update it.

16 changes: 15 additions & 1 deletion bin/check-es-circuit-breakers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ 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',
Expand All @@ -89,7 +94,16 @@ 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].to_s,
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'
Expand Down
16 changes: 15 additions & 1 deletion bin/check-es-cluster-status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -102,7 +107,16 @@ 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].to_s,
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'
Expand Down
9 changes: 4 additions & 5 deletions bin/check-es-indices-sizes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +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 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
# TODO: come back and cleanup all these rubocop disables with a little refactor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not the code that was changed but somehow rubocop started complaining. This is super ugly and hard to read, we should come back and refactor this later.

# 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
Expand Down
11 changes: 10 additions & 1 deletion bin/check-es-node-status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ 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].to_s,
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'
Expand Down
16 changes: 15 additions & 1 deletion bin/metrics-es-cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -108,7 +113,16 @@ 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].to_s,
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'
Expand Down
16 changes: 15 additions & 1 deletion bin/metrics-es-node-graphite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -128,7 +133,16 @@ 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].to_s,
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'
Expand Down
16 changes: 15 additions & 1 deletion bin/metrics-es-node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -89,7 +94,16 @@ 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].to_s,
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'
Expand Down
8 changes: 4 additions & 4 deletions sensu-plugins-elasticsearch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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