Class: SensuPluginsConsul::Check::Base
- Inherits:
-
Sensu::Plugin::Check::CLI
- Object
- Sensu::Plugin::Check::CLI
- SensuPluginsConsul::Check::Base
- Defined in:
- lib/sensu-plugins-consul/check/base.rb
Instance Method Summary collapse
-
#consul_get(endpoint) ⇒ Object
Fetch and return the parsed JSON data from a specified Consul API endpoint.
Instance Method Details
#consul_get(endpoint) ⇒ Object
Fetch and return the parsed JSON data from a specified Consul API endpoint.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sensu-plugins-consul/check/base.rb', line 90 def consul_get(endpoint) url = "#{config[:protocol]}://#{config[:server]}:#{config[:port]}/" \ "v1/#{endpoint}" = { timeout: config[:timeout], verify_ssl: !config[:insecure], ssl_ca_file: config[:capath], headers: { 'X-Consul-Token' => config[:token] } } JSON.parse(RestClient::Resource.new(url, ).get) rescue Errno::ECONNREFUSED critical 'Consul is not responding' rescue RestClient::RequestTimeout critical 'Consul connection timed out' rescue RestClient::Exception => e if e..include?('403') critical 'ACL token is not authorized to access resource' else unknown "Consul returned: #{e}" end end |