Skip to content
Start here

Create Health Check

client.Healthchecks.New(ctx, params) (*Healthcheck, error)
POST/zones/{zone_id}/healthchecks

Create a new health check.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Health Checks Write
ParametersExpand Collapse
params HealthcheckNewParams
ZoneID param.Field[string]

Path param: Identifier

maxLength32
QueryHealthcheck param.Field[QueryHealthcheck]

Body param

ReturnsExpand Collapse
type Healthcheck struct{…}
ID stringoptional

Identifier

maxLength32
Address stringoptional

The hostname or IP address of the origin server to run health checks on.

CheckRegions []CheckRegionoptional

A list of regions from which to run health checks. Null means Cloudflare will pick a default region.

One of the following:
const CheckRegionWnam CheckRegion = "WNAM"
const CheckRegionEnam CheckRegion = "ENAM"
const CheckRegionWeu CheckRegion = "WEU"
const CheckRegionEeu CheckRegion = "EEU"
const CheckRegionNsam CheckRegion = "NSAM"
const CheckRegionSsam CheckRegion = "SSAM"
const CheckRegionOc CheckRegion = "OC"
const CheckRegionMe CheckRegion = "ME"
const CheckRegionNaf CheckRegion = "NAF"
const CheckRegionSaf CheckRegion = "SAF"
const CheckRegionIn CheckRegion = "IN"
const CheckRegionSeas CheckRegion = "SEAS"
const CheckRegionNeas CheckRegion = "NEAS"
const CheckRegionAllRegions CheckRegion = "ALL_REGIONS"
ConsecutiveFails int64optional

The number of consecutive fails required from a health check before changing the health to unhealthy.

ConsecutiveSuccesses int64optional

The number of consecutive successes required from a health check before changing the health to healthy.

CreatedOn Timeoptional
formatdate-time
Description stringoptional

A human-readable description of the health check.

FailureReason stringoptional

The current failure reason if status is unhealthy.

HTTPConfig HTTPConfigurationoptional

Parameters specific to an HTTP or HTTPS health check.

AllowInsecure booloptional

Do not validate the certificate when the health check uses HTTPS.

ExpectedBody stringoptional

A case-insensitive sub-string to look for in the response body. If this string is not found, the origin will be marked as unhealthy.

ExpectedCodes []stringoptional

The expected HTTP response codes (e.g. "200") or code ranges (e.g. "2xx" for all codes starting with 2) of the health check.

FollowRedirects booloptional

Follow redirects if the origin returns a 3xx status code.

Header map[string, []string]optional

The HTTP request headers to send in the health check. It is recommended you set a Host header by default. The User-Agent header cannot be overridden.

Method HTTPConfigurationMethodoptional

The HTTP method to use for the health check.

One of the following:
const HTTPConfigurationMethodGet HTTPConfigurationMethod = "GET"
const HTTPConfigurationMethodHead HTTPConfigurationMethod = "HEAD"
Path stringoptional

The endpoint path to health check against.

Port int64optional

Port number to connect to for the health check. Defaults to 80 if type is HTTP or 443 if type is HTTPS.

Interval int64optional

The interval between each health check. Shorter intervals may give quicker notifications if the origin status changes, but will increase load on the origin as we check from multiple locations.

ModifiedOn Timeoptional
formatdate-time
Name stringoptional

A short name to identify the health check. Only alphanumeric characters, hyphens and underscores are allowed.

Retries int64optional

The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately.

Status HealthcheckStatusoptional

The current status of the origin server according to the health check.

One of the following:
const HealthcheckStatusUnknown HealthcheckStatus = "unknown"
const HealthcheckStatusHealthy HealthcheckStatus = "healthy"
const HealthcheckStatusUnhealthy HealthcheckStatus = "unhealthy"
const HealthcheckStatusSuspended HealthcheckStatus = "suspended"
Suspended booloptional

If suspended, no health checks are sent to the origin.

TCPConfig TCPConfigurationoptional

Parameters specific to TCP health check.

Method TCPConfigurationMethodoptional

The TCP connection method to use for the health check.

Port int64optional

Port number to connect to for the health check. Defaults to 80.

Timeout int64optional

The timeout (in seconds) before marking the health check as failed.

Type stringoptional

The protocol to use for the health check. Currently supported protocols are 'HTTP', 'HTTPS' and 'TCP'.

Create Health Check

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/healthchecks"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  healthcheck, err := client.Healthchecks.New(context.TODO(), healthchecks.HealthcheckNewParams{
    ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    QueryHealthcheck: healthchecks.QueryHealthcheckParam{
      Address: cloudflare.F("www.example.com"),
      Name: cloudflare.F("server-1"),
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", healthcheck.ID)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "address": "www.example.com",
    "check_regions": [
      "WEU",
      "ENAM"
    ],
    "consecutive_fails": 0,
    "consecutive_successes": 0,
    "created_on": "2014-01-01T05:20:00.12345Z",
    "description": "Health check for www.example.com",
    "failure_reason": "",
    "http_config": {
      "allow_insecure": true,
      "expected_body": "success",
      "expected_codes": [
        "2xx",
        "302"
      ],
      "follow_redirects": true,
      "header": {
        "Host": [
          "example.com"
        ],
        "X-App-ID": [
          "abc123"
        ]
      },
      "method": "GET",
      "path": "/health",
      "port": 0
    },
    "interval": 0,
    "modified_on": "2014-01-01T05:20:00.12345Z",
    "name": "server-1",
    "retries": 0,
    "status": "healthy",
    "suspended": true,
    "tcp_config": {
      "method": "connection_established",
      "port": 0
    },
    "timeout": 0,
    "type": "HTTPS"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "address": "www.example.com",
    "check_regions": [
      "WEU",
      "ENAM"
    ],
    "consecutive_fails": 0,
    "consecutive_successes": 0,
    "created_on": "2014-01-01T05:20:00.12345Z",
    "description": "Health check for www.example.com",
    "failure_reason": "",
    "http_config": {
      "allow_insecure": true,
      "expected_body": "success",
      "expected_codes": [
        "2xx",
        "302"
      ],
      "follow_redirects": true,
      "header": {
        "Host": [
          "example.com"
        ],
        "X-App-ID": [
          "abc123"
        ]
      },
      "method": "GET",
      "path": "/health",
      "port": 0
    },
    "interval": 0,
    "modified_on": "2014-01-01T05:20:00.12345Z",
    "name": "server-1",
    "retries": 0,
    "status": "healthy",
    "suspended": true,
    "tcp_config": {
      "method": "connection_established",
      "port": 0
    },
    "timeout": 0,
    "type": "HTTPS"
  },
  "success": true
}