consul.api.health module

class consul.api.health.Health(agent)[source]

Bases: object

service(service, **kwargs)[source]

Returns a tuple of (index, nodes)

index is the current Consul index, suitable for making subsequent calls to wait for changes since this query was last run.

wait the maximum duration to wait (e.g. ’10s’) to retrieve a given index. this parameter is only applied if index is also specified. the wait time by default is 5 minutes.

nodes are the nodes providing the given service.

Calling with passing set to True will filter results to only those nodes whose checks are currently passing.

Calling with tag will filter the results by tag, multiple tags using list possible.

dc is the datacenter of the node and defaults to this agents datacenter.

near is a node name to sort the resulting list in ascending order based on the estimated round trip time from that node

token is an optional `ACL token`_ to apply to this request.

node_meta is an optional meta data used for filtering, a dictionary formatted as {k1:v1, k2:v2}.

filter_expr is an optional bexpr filter expression to filter the results.

peer is the name of the imported service’s peer, and only applies to imported services.

merge_central_config if set, will return a fully resolved service definition that includes merged values from the proxy-defaults/global and service-defaults/:service config entries. Only applicable to connect-proxy and gateway services.

Parameters:

service (str)

connect(service, **kwargs)[source]

Returns a tuple of (index, nodes) of the nodes providing connect-capable service in the dc datacenter. dc defaults to the current datacenter of this agent.

Request arguments and response format are the same as health.service

ingress(service, index=None, wait=None, passing=None, tag=None, dc=None, near=None, token=None, node_meta=None, filter_expr=None)[source]

Returns a tuple of (index, nodes) of the ingress gateway instances providing the given service.

index is the current Consul index, suitable for making subsequent calls to wait for changes since this query was last run.

wait the maximum duration to wait (e.g. ’10s’) to retrieve a given index. this parameter is only applied if index is also specified. the wait time by default is 5 minutes.

Calling with passing set to True will filter results to only those nodes whose checks are currently passing.

Calling with tag will filter the results by tag, multiple tags using list possible.

dc is the datacenter of the node and defaults to this agents datacenter.

near is a node name to sort the resulting list in ascending order based on the estimated round trip time from that node

token is an optional `ACL token`_ to apply to this request.

node_meta is an optional meta data used for filtering, a dictionary formatted as {k1:v1, k2:v2}.

filter_expr is an optional bexpr filter expression to filter the results.

Unlike connect and service, this endpoint does not support the peer query parameter or the streaming backend for blocking queries.

Parameters:
  • service (str)

  • token (str | None)

  • filter_expr (str | None)

checks(service, index=None, wait=None, dc=None, near=None, token=None, node_meta=None, filter_expr=None)[source]

Returns a tuple of (index, checks) with checks being the checks associated with the service.

service is the name of the service being checked.

index is the current Consul index, suitable for making subsequent calls to wait for changes since this query was last run.

wait the maximum duration to wait (e.g. ’10s’) to retrieve a given index. this parameter is only applied if index is also specified. the wait time by default is 5 minutes.

dc is the datacenter of the node and defaults to this agents datacenter.

near is a node name to sort the resulting list in ascending order based on the estimated round trip time from that node

token is an optional `ACL token`_ to apply to this request.

node_meta is an optional meta data used for filtering, a dictionary formatted as {k1:v1, k2:v2}.

filter_expr is an optional bexpr filter expression to filter the results.

Parameters:
  • token (str | None)

  • filter_expr (str | None)

state(name, index=None, wait=None, dc=None, near=None, token=None, node_meta=None, filter_expr=None)[source]

Returns a tuple of (index, nodes)

name is a supported state. From the Consul docs:

The supported states are any, unknown, passing, warning, or critical. The any state is a wildcard that can be used to return all checks.

index is the current Consul index, suitable for making subsequent calls to wait for changes since this query was last run.

wait the maximum duration to wait (e.g. ’10s’) to retrieve a given index. this parameter is only applied if index is also specified. the wait time by default is 5 minutes.

dc is the datacenter of the node and defaults to this agents datacenter.

near is a node name to sort the resulting list in ascending order based on the estimated round trip time from that node

token is an optional `ACL token`_ to apply to this request.

node_meta is an optional meta data used for filtering, a dictionary formatted as {k1:v1, k2:v2}.

filter_expr is an optional bexpr filter expression to filter the results.

nodes are the nodes providing the given service.

Parameters:
  • name (str)

  • token (str | None)

  • filter_expr (str | None)

node(node, index=None, wait=None, dc=None, token=None, filter_expr=None)[source]

Returns a tuple of (index, checks)

index is the current Consul index, suitable for making subsequent calls to wait for changes since this query was last run.

wait the maximum duration to wait (e.g. ’10s’) to retrieve a given index. this parameter is only applied if index is also specified. the wait time by default is 5 minutes.

dc is the datacenter of the node and defaults to this agents datacenter.

token is an optional `ACL token`_ to apply to this request.

filter_expr is an optional bexpr filter expression to filter the results.

nodes are the nodes providing the given service.

Parameters:
  • token (str | None)

  • filter_expr (str | None)