lib/sensu-plugins-consul/check/base.rb in sensu-plugins-consul-2.1.1 vs lib/sensu-plugins-consul/check/base.rb in sensu-plugins-consul-2.2.0

- old
+ new

@@ -78,26 +78,35 @@ short: '-t TIMEOUT_IN_SECONDS', long: '--timeout TIMEOUT_IN_SECONDS', proc: proc(&:to_i), default: 5 + option :token, + description: 'ACL token', + long: '--token ACL_TOKEN' + # # Fetch and return the parsed JSON data from a specified Consul API endpoint. # def consul_get(endpoint) url = "#{config[:protocol]}://#{config[:server]}:#{config[:port]}/" \ "v1/#{endpoint}" options = { timeout: config[:timeout], verify_ssl: !config[:insecure], - ssl_ca_file: config[:capath] } + ssl_ca_file: config[:capath], + headers: { 'X-Consul-Token' => config[:token] } } JSON.parse(RestClient::Resource.new(url, options).get) rescue Errno::ECONNREFUSED critical 'Consul is not responding' rescue RestClient::RequestTimeout critical 'Consul connection timed out' rescue RestClient::Exception => e - unknown "Consul returned: #{e}" + if e.message.include?('403') + critical 'ACL token is not authorized to access resource' + else + unknown "Consul returned: #{e}" + end end end end end