class Diplomat::Health
Methods for interacting with the Consul health API endpoint
Public Instance Methods
Convenience method to get services in any state
# File lib/diplomat/health.rb, line 82 def any state('any') end
Get service checks @param s [String] the service @param options [Hash] :dc string for dc specific query @return [OpenStruct] all data associated with the node
# File lib/diplomat/health.rb, line 27 def checks(s, options = nil) url = ["/v1/health/checks/#{s}"] url << use_named_parameter('dc', options[:dc]) if options && options[:dc] # If the request fails, it's probably due to a bad path # so return a PathNotFound error. ret = @conn.get concat_url url JSON.parse(ret.body).map { |check| OpenStruct.new check } rescue Faraday::ClientError raise Diplomat::PathNotFound end
Convenience method to get services in critical state
# File lib/diplomat/health.rb, line 97 def critical state('critical') end
Get node health @param n [String] the node @param options [Hash] :dc string for dc specific query @return [OpenStruct] all data associated with the node
# File lib/diplomat/health.rb, line 11 def node(n, options = nil) url = ["/v1/health/node/#{n}"] url << use_named_parameter('dc', options[:dc]) if options && options[:dc] # If the request fails, it's probably due to a bad path # so return a PathNotFound error. ret = @conn.get concat_url url JSON.parse(ret.body).map { |node| OpenStruct.new node } rescue Faraday::ClientError raise Diplomat::PathNotFound end
Convenience method to get services in passing state
# File lib/diplomat/health.rb, line 87 def passing state('passing') end
Get service health @param s [String] the service @param options [Hash] :dc string for dc specific query @param options [Hash] :passing boolean to return only checks in passing state @param options [Hash] :tag string for specific tag @return [OpenStruct] all data associated with the node rubocop:disable PerceivedComplexity, CyclomaticComplexity, AbcSize
# File lib/diplomat/health.rb, line 46 def service(s, options = nil) url = ["/v1/health/service/#{s}"] url << use_named_parameter('dc', options[:dc]) if options && options[:dc] url << 'passing' if options && options[:passing] url << use_named_parameter('tag', options[:tag]) if options && options[:tag] url << use_named_parameter('near', options[:near]) if options && options[:near] # If the request fails, it's probably due to a bad path # so return a PathNotFound error. ret = @conn.get concat_url url JSON.parse(ret.body).map { |service| OpenStruct.new service } rescue Faraday::ClientError raise Diplomat::PathNotFound end
Get service health @param s [String] the state (“any”, “passing”, “warning”, or “critical”) @param options [Hash] :dc string for dc specific query @return [OpenStruct] all data associated with the node rubocop:disable AbcSize
# File lib/diplomat/health.rb, line 67 def state(s, options = nil) url = ["/v1/health/state/#{s}"] url << use_named_parameter('dc', options[:dc]) if options && options[:dc] url << use_named_parameter('near', options[:near]) if options && options[:near] # If the request fails, it's probably due to a bad path # so return a PathNotFound error. ret = @conn.get concat_url url JSON.parse(ret.body).map { |status| OpenStruct.new status } rescue Faraday::ClientError raise Diplomat::PathNotFound end
Convenience method to get services in warning state
# File lib/diplomat/health.rb, line 92 def warning state('warning') end