Class: RabbitMQ::HTTP::HealthChecks

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbitmq/http/client/health_checks.rb

Constant Summary collapse

TIME_UNITS =
%w(days weeks months years)

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ HealthChecks

Returns a new instance of HealthChecks.



11
12
13
14
15
# File 'lib/rabbitmq/http/client/health_checks.rb', line 11

def initialize(client)
  @client = client
  @request_helper  = @client.request_helper
  @response_helper = @client.response_helper
end

Instance Method Details

#check_alarmsObject



17
18
19
# File 'lib/rabbitmq/http/client/health_checks.rb', line 17

def check_alarms
  health_check_for("health/checks/alarms")
end

#check_certificate_expiration(within, unit) ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
51
52
# File 'lib/rabbitmq/http/client/health_checks.rb', line 47

def check_certificate_expiration(within, unit)
  raise ArgumentError.new("supported time units are #{TIME_UNITS.join(', ')}, given: #{unit}") if !TIME_UNITS.include?(unit)
  raise ArgumentError.new("the number of time units must be a positive integer") if within <= 0

  health_check_for("health/checks/certificate-expiration/#{@request_helper.encode_uri_path_segment(within)}/#{@request_helper.encode_uri_path_segment(unit)}")
end

#check_if_node_is_mirror_sync_criticalObject



33
34
35
# File 'lib/rabbitmq/http/client/health_checks.rb', line 33

def check_if_node_is_mirror_sync_critical
  health_check_for("health/checks/node-is-mirror-sync-critical")
end

#check_if_node_is_quorum_criticalObject



29
30
31
# File 'lib/rabbitmq/http/client/health_checks.rb', line 29

def check_if_node_is_quorum_critical
  health_check_for("health/checks/node-is-quorum-critical")
end

#check_local_alarmsObject



21
22
23
# File 'lib/rabbitmq/http/client/health_checks.rb', line 21

def check_local_alarms
  health_check_for("health/checks/local-alarms")
end

#check_port_listener(port) ⇒ Object



37
38
39
# File 'lib/rabbitmq/http/client/health_checks.rb', line 37

def check_port_listener(port)
  health_check_for("health/checks/port-listener/#{encode_uri_path_segment(port)}")
end

#check_protocol_listener(proto) ⇒ Object



41
42
43
# File 'lib/rabbitmq/http/client/health_checks.rb', line 41

def check_protocol_listener(proto)
  health_check_for("health/checks/protocol-listener/#{encode_uri_path_segment(proto)}")
end

#check_virtual_hostsObject



25
26
27
# File 'lib/rabbitmq/http/client/health_checks.rb', line 25

def check_virtual_hosts
  health_check_for("health/checks/virtual-hosts")
end

#health_check_for(path) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rabbitmq/http/client/health_checks.rb', line 55

def health_check_for(path)
  begin
      _ = @response_helper.decode_resource(@client.connection.get(path))
      [true, nil]
    rescue Faraday::ServerError => se
      # health check endpoints respond with a 503 if the server fails
      if se.response_status == 503
        [false, @response_helper.decode_response_body(se.response[:body])]
      else
        raise se
      end
  end
end