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}.

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

checks(service, index=None, wait=None, dc=None, near=None, token=None, node_meta=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}.

Parameters:

token (str | None)

state(name, index=None, wait=None, dc=None, near=None, token=None, node_meta=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}.

nodes are the nodes providing the given service.

Parameters:
  • name (str)

  • token (str | None)

node(node, index=None, wait=None, dc=None, token=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.

nodes are the nodes providing the given service.

Parameters:

token (str | None)