bin/check-consul-leader.rb in sensu-plugins-consul-1.5.0 vs bin/check-consul-leader.rb in sensu-plugins-consul-1.6.0

- old
+ new

@@ -51,10 +51,28 @@ description: 'consul listener scheme', short: '-S SCHEME', long: '--scheme SCHEME', default: 'http' + option :insecure, + description: 'set this flag to disable SSL verification', + short: '-k', + long: '--insecure', + boolean: true, + default: false + + option :capath, + description: 'absolute path to an alternative CA file', + short: '-c CAPATH', + long: '--capath CAPATH' + + option :timeout, + description: 'connection will time out after this many seconds', + short: '-t TIMEOUT_IN_SECONDS', + long: '--timeout TIMEOUT_IN_SECONDS', + default: 5 + def valid_ip(ip) case ip.to_s when Resolv::IPv4::Regex return true when Resolv::IPv6::Regex @@ -75,10 +93,16 @@ return str end end def run - r = RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/status/leader", timeout: 5).get + options = { timeout: config[:timeout], + verify_ssl: (OpenSSL::SSL::VERIFY_NONE if defined? config[:insecure]), + ssl_ca_file: (config[:capath] if defined? config[:capath]) } + url = "#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/status/leader" + + r = RestClient::Resource.new(url, options).get + if r.code == 200 if valid_ip(strip_ip(r.body)) ok 'Consul is UP and has a leader' else critical 'Consul is UP, but it has NO leader'