class SensuPluginsConsul::Check::Base
Public Instance Methods
consul_get(endpoint)
click to toggle source
Fetch and return the parsed JSON data from a specified Consul API endpoint.
# File lib/sensu-plugins-consul/check/base.rb, line 90 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], 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 if e.message.include?('403') critical 'ACL token is not authorized to access resource' else unknown "Consul returned: #{e}" end end