Skip to content

Commit 93ed51d

Browse files
vin01majormoses
authored andcommitted
Adding --cert-file option for all the checks which use RestClient (#115)
* Adding cert option to all checks using RestClient * Adding --cert-file option to all checks which are using RestClient
1 parent 8e5cbe5 commit 93ed51d

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)
55

66
## [Unreleased]
7+
### Added
8+
- 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)
79

810
## [2.0.1] - 2018-03-27
911
### Security

bin/check-es-file-descriptors.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class ESFileDescriptors < Sensu::Plugin::Check::CLI
8282
short: '-e',
8383
long: '--https'
8484

85+
option :cert_file,
86+
description: 'Cert file to use',
87+
long: '--cert-file CERT'
88+
8589
def get_es_resource(resource)
8690
headers = {}
8791
if config[:user] && config[:password]
@@ -95,7 +99,16 @@ def get_es_resource(resource)
9599
'http'
96100
end
97101

98-
r = RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers)
102+
r = if config[:cert_file]
103+
RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
104+
ssl_ca_file: config[:cert_file].to_s,
105+
timeout: config[:timeout],
106+
headers: headers)
107+
else
108+
RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
109+
timeout: config[:timeout],
110+
headers: headers)
111+
end
99112
JSON.parse(r.get)
100113
rescue Errno::ECONNREFUSED
101114
warning 'Connection refused'

bin/check-es-heap.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class ESHeap < Sensu::Plugin::Check::CLI
9090
short: '-e',
9191
long: '--https'
9292

93+
option :cert_file,
94+
description: 'Cert file to use',
95+
long: '--cert-file CERT'
96+
9397
option :all,
9498
description: 'Check all nodes in the ES cluster',
9599
short: '-a',
@@ -114,7 +118,16 @@ def acquire_es_resource(resource)
114118
'http'
115119
end
116120

117-
r = RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers)
121+
r = if config[:cert_file]
122+
RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
123+
ssl_ca_file: config[:cert_file].to_s,
124+
timeout: config[:timeout],
125+
headers: headers)
126+
else
127+
RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
128+
timeout: config[:timeout],
129+
headers: headers)
130+
end
118131
JSON.parse(r.get)
119132
rescue Errno::ECONNREFUSED
120133
warning 'Connection refused'

bin/check-es-shard-allocation-status.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,27 @@ class ESShardAllocationStatus < Sensu::Plugin::Check::CLI
7676
short: '-P PASS',
7777
long: '--password PASS'
7878

79+
option :cert_file,
80+
description: 'Cert file to use',
81+
long: '--cert-file CERT'
82+
7983
def get_es_resource(resource)
8084
headers = {}
8185
if config[:user] && config[:password]
8286
auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
8387
headers = { 'Authorization' => auth }
8488
end
8589

86-
r = RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}#{resource}", timeout: config[:timeout], headers: headers)
90+
r = if config[:cert_file]
91+
RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}#{resource}",
92+
ssl_ca_file: config[:cert_file].to_s,
93+
timeout: config[:timeout],
94+
headers: headers)
95+
else
96+
RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}#{resource}",
97+
timeout: config[:timeout],
98+
headers: headers)
99+
end
87100
JSON.parse(r.get)
88101
rescue Errno::ECONNREFUSED
89102
warning 'Connection refused'

0 commit comments

Comments
 (0)