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-file option for all the checks which use RestClient #115

Merged
merged 2 commits into from
May 23, 2018
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)

## [Unreleased]
### Added
- check-es-shard-allocation-status.rb, check-es-file-descriptors.rb, check-es-heap.rb: added `--cert-file` option which allows you to specify a ca-cert to be used to verify TLS (@vin01)

## [2.0.1] - 2018-03-27
### Security
Expand Down
15 changes: 14 additions & 1 deletion bin/check-es-file-descriptors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class ESFileDescriptors < Sensu::Plugin::Check::CLI
short: '-e',
long: '--https'

option :cert_file,
description: 'Cert file to use',
long: '--cert-file CERT'

def get_es_resource(resource)
headers = {}
if config[:user] && config[:password]
Expand All @@ -95,7 +99,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_file]
RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
ssl_ca_file: config[:cert_file].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
15 changes: 14 additions & 1 deletion bin/check-es-heap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class ESHeap < Sensu::Plugin::Check::CLI
short: '-e',
long: '--https'

option :cert_file,
description: 'Cert file to use',
long: '--cert-file CERT'

option :all,
description: 'Check all nodes in the ES cluster',
short: '-a',
Expand All @@ -114,7 +118,16 @@ def acquire_es_resource(resource)
'http'
end

r = RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers)
r = if config[:cert_file]
RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
ssl_ca_file: config[:cert_file].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
15 changes: 14 additions & 1 deletion bin/check-es-shard-allocation-status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,27 @@ class ESShardAllocationStatus < Sensu::Plugin::Check::CLI
short: '-P PASS',
long: '--password PASS'

option :cert_file,
description: 'Cert file to use',
long: '--cert-file CERT'

def get_es_resource(resource)
headers = {}
if config[:user] && config[:password]
auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
headers = { 'Authorization' => auth }
end

r = RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers)
r = if config[:cert_file]
RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}#{resource}",
ssl_ca_file: config[:cert_file].to_s,
timeout: config[:timeout],
headers: headers)
else
RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}#{resource}",
timeout: config[:timeout],
headers: headers)
end
JSON.parse(r.get)
rescue Errno::ECONNREFUSED
warning 'Connection refused'
Expand Down