github.com/clly/consul@v1.4.5/website/source/api/agent/check.html.md (about)

     1  ---
     2  layout: api
     3  page_title: Check - Agent - HTTP API
     4  sidebar_current: api-agent-check
     5  description: |-
     6    The /agent/check endpoints interact with checks on the local agent in Consul.
     7  ---
     8  
     9  # Check - Agent HTTP API
    10  
    11  The `/agent/check` endpoints interact with checks on the local agent in Consul.
    12  These should not be confused with checks in the catalog.
    13  
    14  ## List Checks
    15  
    16  This endpoint returns all checks that are registered with the local agent. These
    17  checks were either provided through configuration files or added dynamically
    18  using the HTTP API.
    19  
    20  It is important to note that the checks known by the agent may be different from
    21  those reported by the catalog. This is usually due to changes being made while
    22  there is no leader elected. The agent performs active
    23  [anti-entropy](/docs/internals/anti-entropy.html), so in most situations
    24  everything will be in sync within a few seconds.
    25  
    26  | Method | Path                         | Produces                   |
    27  | ------ | ---------------------------- | -------------------------- |
    28  | `GET`  | `/agent/checks`              | `application/json`         |
    29  
    30  The table below shows this endpoint's support for
    31  [blocking queries](/api/index.html#blocking-queries),
    32  [consistency modes](/api/index.html#consistency-modes),
    33  [agent caching](/api/index.html#agent-caching), and
    34  [required ACLs](/api/index.html#acls).
    35  
    36  | Blocking Queries | Consistency Modes | Agent Caching | ACL Required             |
    37  | ---------------- | ----------------- | ------------- | ------------------------ |
    38  | `NO`             | `none`            | `none`        | `node:read,service:read` |
    39  
    40  ### Sample Request
    41  
    42  ```text
    43  $ curl \
    44      http://127.0.0.1:8500/v1/agent/checks
    45  ```
    46  
    47  ### Sample Response
    48  
    49  ```json
    50  {
    51    "service:redis": {
    52      "Node": "foobar",
    53      "CheckID": "service:redis",
    54      "Name": "Service 'redis' check",
    55      "Status": "passing",
    56      "Notes": "",
    57      "Output": "",
    58      "ServiceID": "redis",
    59      "ServiceName": "redis",
    60      "ServiceTags": ["primary"]
    61    }
    62  }
    63  ```
    64  
    65  ## Register Check
    66  
    67  This endpoint adds a new check to the local agent. Checks may be of script,
    68  HTTP, TCP, or TTL type. The agent is responsible for managing the status of the
    69  check and keeping the Catalog in sync.
    70  
    71  | Method | Path                         | Produces                   |
    72  | ------ | ---------------------------- | -------------------------- |
    73  | `PUT`  | `/agent/check/register`      | `application/json`         |
    74  
    75  The table below shows this endpoint's support for
    76  [blocking queries](/api/index.html#blocking-queries),
    77  [consistency modes](/api/index.html#consistency-modes),
    78  [agent caching](/api/index.html#agent-caching), and
    79  [required ACLs](/api/index.html#acls).
    80  
    81  | Blocking Queries | Consistency Modes | Agent Caching | ACL Required               |
    82  | ---------------- | ----------------- | ------------- | -------------------------- |
    83  | `NO`             | `none`            | `none`        | `node:write,service:write` |
    84  
    85  ### Parameters
    86  
    87  - `Name` `(string: <required>)` - Specifies the name of the check.
    88  
    89  - `ID` `(string: "")` - Specifies a unique ID for this check on the node.
    90    This defaults to the `"Name"` parameter, but it may be necessary to provide an
    91    ID for uniqueness.
    92  
    93  - `Interval` `(string: "")` - Specifies the frequency at which to run this
    94    check. This is required for HTTP and TCP checks.
    95  
    96  - `Notes` `(string: "")` - Specifies arbitrary information for humans. This is
    97    not used by Consul internally.
    98  
    99  - `DeregisterCriticalServiceAfter` `(string: "")` - Specifies that checks
   100    associated with a service should deregister after this time. This is specified
   101    as a time duration with suffix like "10m". If a check is in the critical state
   102    for more than this configured value, then its associated service (and all of
   103    its associated checks) will automatically be deregistered. The minimum timeout
   104    is 1 minute, and the process that reaps critical services runs every 30
   105    seconds, so it may take slightly longer than the configured timeout to trigger
   106    the deregistration. This should generally be configured with a timeout that's
   107    much, much longer than any expected recoverable outage for the given service.
   108  
   109  - `Args` `(array<string>)` - Specifies command arguments to run to update the
   110    status of the check. Prior to Consul 1.0, checks used a single `Script` field
   111    to define the command to run, and would always run in a shell. In Consul
   112    1.0, the `Args` array was added so that checks can be run without a shell. The
   113    `Script` field is deprecated, and you should include the shell in the `Args` to
   114    run under a shell, eg. `"args": ["sh", "-c", "..."]`.
   115  
   116    -> **Note:** Consul 1.0 shipped with an issue where `Args` was erroneously named
   117      `ScriptArgs` in this API. Please use `ScriptArgs` with Consul 1.0 (that will
   118      continue to be accepted in future versions of Consul), and `Args` in Consul
   119      1.0.1 and later.
   120  
   121  - `AliasNode` `(string: "")` - Specifies the ID of the node for an alias check.
   122    If no service is specified, the check will alias the health of the node.
   123    If a service is specified, the check will alias the specified service on
   124    this particular node.
   125  
   126  - `AliasService` `(string: "")` - Specifies the ID of a service for an
   127    alias check. If the service is not registered with the same agent,
   128    `AliasNode` must also be specified. Note this is the service _ID_ and
   129    not the service _name_ (though they are very often the same).
   130  
   131  - `DockerContainerID` `(string: "")` - Specifies that the check is a Docker
   132    check, and Consul will evaluate the script every `Interval` in the given
   133    container using the specified `Shell`. Note that `Shell` is currently only
   134    supported for Docker checks.
   135  
   136  - `GRPC` `(string: "")` - Specifies a `gRPC` check's endpoint that supports the standard
   137    [gRPC health checking protocol](https://github.com/grpc/grpc/blob/master/doc/health-checking.md).
   138    The state of the check will be updated at the given `Interval` by probing the configured
   139    endpoint.
   140  
   141  - `GRPCUseTLS` `(bool: false)` - Specifies whether to use TLS for this `gRPC` health check.
   142    If TLS is enabled, then by default, a valid TLS certificate is expected. Certificate
   143    verification can be turned off by setting `TLSSkipVerify` to `true`.
   144  
   145  - `HTTP` `(string: "")` - Specifies an `HTTP` check to perform a `GET` request
   146    against the value of `HTTP` (expected to be a URL) every `Interval`. If the
   147    response is any `2xx` code, the check is `passing`. If the response is `429
   148    Too Many Requests`, the check is `warning`. Otherwise, the check is
   149    `critical`. HTTP checks also support SSL. By default, a valid SSL certificate
   150    is expected. Certificate verification can be controlled using the
   151    `TLSSkipVerify`.
   152  
   153  - `Method` `(string: "")` - Specifies a different HTTP method to be used
   154    for an `HTTP` check. When no value is specified, `GET` is used.
   155  
   156  - `Header` `(map[string][]string: {})` - Specifies a set of headers that should
   157    be set for `HTTP` checks. Each header can have multiple values.
   158  
   159  - `Timeout` `(duration: 10s)` - Specifies a timeout for outgoing connections in the
   160    case of a Script, HTTP, TCP, or gRPC check. Can be specified in the form of "10s"
   161    or "5m" (i.e., 10 seconds or 5 minutes, respectively).
   162  
   163  - `TLSSkipVerify` `(bool: false)` - Specifies if the certificate for an HTTPS
   164    check should not be verified.
   165  
   166  - `TCP` `(string: "")` - Specifies a `TCP` to connect against the value of `TCP`
   167    (expected to be an IP or hostname plus port combination) every `Interval`. If
   168    the connection attempt is successful, the check is `passing`. If the
   169    connection attempt is unsuccessful, the check is `critical`. In the case of a
   170    hostname that resolves to both IPv4 and IPv6 addresses, an attempt will be
   171    made to both addresses, and the first successful connection attempt will
   172    result in a successful check.
   173  
   174  - `TTL` `(string: "")` - Specifies this is a TTL check, and the TTL endpoint
   175    must be used periodically to update the state of the check.
   176  
   177  - `ServiceID` `(string: "")` - Specifies the ID of a service to associate the
   178    registered check with an existing service provided by the agent.
   179  
   180  - `Status` `(string: "")` - Specifies the initial status of the health check.
   181  
   182  ### Sample Payload
   183  
   184  ```json
   185  {
   186    "ID": "mem",
   187    "Name": "Memory utilization",
   188    "Notes": "Ensure we don't oversubscribe memory",
   189    "DeregisterCriticalServiceAfter": "90m",
   190    "Args": ["/usr/local/bin/check_mem.py"],
   191    "DockerContainerID": "f972c95ebf0e",
   192    "Shell": "/bin/bash",
   193    "HTTP": "https://example.com",
   194    "Method": "POST",
   195    "Header": {"x-foo":["bar", "baz"]},
   196    "TCP": "example.com:22",
   197    "Interval": "10s",
   198    "TTL": "15s",
   199    "TLSSkipVerify": true
   200  }
   201  ```
   202  
   203  ### Sample Request
   204  
   205  ```text
   206  $ curl \
   207     --request PUT \
   208     --data @payload.json \
   209     http://127.0.0.1:8500/v1/agent/check/register
   210  ```
   211  
   212  ## Deregister Check
   213  
   214  This endpoint remove a check from the local agent. The agent will take care of
   215  deregistering the check from the catalog. If the check with the provided ID does
   216  not exist, no action is taken.
   217  
   218  | Method | Path                                | Produces                   |
   219  | ------ | ----------------------------------- | -------------------------- |
   220  | `PUT`  | `/agent/check/deregister/:check_id` | `application/json`         |
   221  
   222  The table below shows this endpoint's support for
   223  [blocking queries](/api/index.html#blocking-queries),
   224  [consistency modes](/api/index.html#consistency-modes),
   225  [agent caching](/api/index.html#agent-caching), and
   226  [required ACLs](/api/index.html#acls).
   227  
   228  | Blocking Queries | Consistency Modes | Agent Caching | ACL Required               |
   229  | ---------------- | ----------------- | ------------- | -------------------------- |
   230  | `NO`             | `none`            | `none`        | `node:write,service:write` |
   231  
   232  ### Parameters
   233  
   234  - `check_id` `(string: "")` - Specifies the unique ID of the check to
   235    deregister. This is specified as part of the URL.
   236  
   237  ### Sample Request
   238  
   239  ```text
   240  $ curl \
   241      --request PUT \
   242      http://127.0.0.1:8500/v1/agent/check/deregister/my-check-id
   243  ```
   244  
   245  ## TTL Check Pass
   246  
   247  This endpoint is used with a TTL type check to set the status of the check to
   248  `passing` and to reset the TTL clock.
   249  
   250  | Method | Path                          | Produces                   |
   251  | ------ | ----------------------------- | -------------------------- |
   252  | `PUT`  | `/agent/check/pass/:check_id` | `application/json`         |
   253  
   254  The table below shows this endpoint's support for
   255  [blocking queries](/api/index.html#blocking-queries),
   256  [consistency modes](/api/index.html#consistency-modes),
   257  [agent caching](/api/index.html#agent-caching), and
   258  [required ACLs](/api/index.html#acls).
   259  
   260  | Blocking Queries | Consistency Modes | Agent Caching | ACL Required               |
   261  | ---------------- | ----------------- | ------------- | -------------------------- |
   262  | `NO`             | `none`            | `none`        | `node:write,service:write` |
   263  
   264  ### Parameters
   265  
   266  - `check_id` `(string: "")` - Specifies the unique ID of the check to
   267    use. This is specified as part of the URL.
   268  
   269  - `note` `(string: "")` - Specifies a human-readable message. This will be
   270    passed through to the check's `Output` field.
   271  
   272  ### Sample Request
   273  
   274  ```text
   275  $ curl \
   276      http://127.0.0.1:8500/v1/agent/check/pass/my-check-id
   277  ```
   278  
   279  ## TTL Check Warn
   280  
   281  This endpoint is used with a TTL type check to set the status of the check to
   282  `warning` and to reset the TTL clock.
   283  
   284  | Method | Path                          | Produces                   |
   285  | ------ | ----------------------------- | -------------------------- |
   286  | `PUT`  | `/agent/check/warn/:check_id` | `application/json`         |
   287  
   288  The table below shows this endpoint's support for
   289  [blocking queries](/api/index.html#blocking-queries),
   290  [consistency modes](/api/index.html#consistency-modes),
   291  [agent caching](/api/index.html#agent-caching), and
   292  [required ACLs](/api/index.html#acls).
   293  
   294  | Blocking Queries | Consistency Modes | Agent Caching | ACL Required               |
   295  | ---------------- | ----------------- | ------------- | -------------------------- |
   296  | `NO`             | `none`            | `none`        | `node:write,service:write` |
   297  
   298  ### Parameters
   299  
   300  - `check_id` `(string: "")` - Specifies the unique ID of the check to
   301    use. This is specified as part of the URL.
   302  
   303  - `note` `(string: "")` - Specifies a human-readable message. This will be
   304    passed through to the check's `Output` field.
   305  
   306  ### Sample Request
   307  
   308  ```text
   309  $ curl \
   310      http://127.0.0.1:8500/v1/agent/check/warn/my-check-id
   311  ```
   312  
   313  ## TTL Check Fail
   314  
   315  This endpoint is used with a TTL type check to set the status of the check to
   316  `critical` and to reset the TTL clock.
   317  
   318  | Method | Path                          | Produces                   |
   319  | ------ | ----------------------------- | -------------------------- |
   320  | `PUT`  | `/agent/check/fail/:check_id` | `application/json`         |
   321  
   322  The table below shows this endpoint's support for
   323  [blocking queries](/api/index.html#blocking-queries),
   324  [consistency modes](/api/index.html#consistency-modes),
   325  [agent caching](/api/index.html#agent-caching), and
   326  [required ACLs](/api/index.html#acls).
   327  
   328  | Blocking Queries | Consistency Modes | Agent Caching | ACL Required               |
   329  | ---------------- | ----------------- | ------------- | -------------------------- |
   330  | `NO`             | `none`            | `none`        | `node:write,service:write` |
   331  
   332  ### Parameters
   333  
   334  - `check_id` `(string: "")` - Specifies the unique ID of the check to
   335    use. This is specified as part of the URL.
   336  
   337  - `note` `(string: "")` - Specifies a human-readable message. This will be
   338    passed through to the check's `Output` field.
   339  
   340  ### Sample Request
   341  
   342  ```text
   343  $ curl \
   344      http://127.0.0.1:8500/v1/agent/check/fail/my-check-id
   345  ```
   346  
   347  ## TTL Check Update
   348  
   349  This endpoint is used with a TTL type check to set the status of the check and
   350  to reset the TTL clock.
   351  
   352  | Method | Path                            | Produces                   |
   353  | ------ | ------------------------------- | -------------------------- |
   354  | `PUT`  | `/agent/check/update/:check_id` | `application/json`         |
   355  
   356  The table below shows this endpoint's support for
   357  [blocking queries](/api/index.html#blocking-queries),
   358  [consistency modes](/api/index.html#consistency-modes),
   359  [agent caching](/api/index.html#agent-caching), and
   360  [required ACLs](/api/index.html#acls).
   361  
   362  | Blocking Queries | Consistency Modes | Agent Caching | ACL Required               |
   363  | ---------------- | ----------------- | ------------- | -------------------------- |
   364  | `NO`             | `none`            | `none`        | `node:write,service:write` |
   365  
   366  ### Parameters
   367  
   368  - `check_id` `(string: "")` - Specifies the unique ID of the check to
   369    use. This is specified as part of the URL.
   370  
   371  - `Status` `(string: "")` - Specifies the status of the check. Valid values are
   372    `"passing"`, `"warning"`, and `"critical"`.
   373  
   374  - `Output` `(string: "")` - Specifies a human-readable message. This will be
   375    passed through to the check's `Output` field.
   376  
   377  ### Sample Payload
   378  
   379  ```json
   380  {
   381    "Status": "passing",
   382    "Output": "curl reported a failure:\n\n..."
   383  }
   384  ```
   385  
   386  ### Sample Request
   387  
   388  ```text
   389  $ curl \
   390      --request PUT \
   391      --data @payload.json \
   392      http://127.0.0.1:8500/v1/agent/check/update/my-check-id
   393  ```