## Create Health Check `client.Healthchecks.New(ctx, params) (*Healthcheck, error)` **post** `/zones/{zone_id}/healthchecks` Create a new health check. ### Parameters - `params HealthcheckNewParams` - `ZoneID param.Field[string]` Path param: Identifier - `QueryHealthcheck param.Field[QueryHealthcheck]` Body param ### Returns - `type Healthcheck struct{…}` - `ID string` Identifier - `Address string` The hostname or IP address of the origin server to run health checks on. - `CheckRegions []CheckRegion` A list of regions from which to run health checks. Null means Cloudflare will pick a default region. - `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 int64` The number of consecutive fails required from a health check before changing the health to unhealthy. - `ConsecutiveSuccesses int64` The number of consecutive successes required from a health check before changing the health to healthy. - `CreatedOn Time` - `Description string` A human-readable description of the health check. - `FailureReason string` The current failure reason if status is unhealthy. - `HTTPConfig HTTPConfiguration` Parameters specific to an HTTP or HTTPS health check. - `AllowInsecure bool` Do not validate the certificate when the health check uses HTTPS. - `ExpectedBody string` 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 []string` 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 bool` Follow redirects if the origin returns a 3xx status code. - `Header map[string, []string]` 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 HTTPConfigurationMethod` The HTTP method to use for the health check. - `const HTTPConfigurationMethodGet HTTPConfigurationMethod = "GET"` - `const HTTPConfigurationMethodHead HTTPConfigurationMethod = "HEAD"` - `Path string` The endpoint path to health check against. - `Port int64` Port number to connect to for the health check. Defaults to 80 if type is HTTP or 443 if type is HTTPS. - `Interval int64` 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 Time` - `Name string` A short name to identify the health check. Only alphanumeric characters, hyphens and underscores are allowed. - `Retries int64` The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately. - `Status HealthcheckStatus` The current status of the origin server according to the health check. - `const HealthcheckStatusUnknown HealthcheckStatus = "unknown"` - `const HealthcheckStatusHealthy HealthcheckStatus = "healthy"` - `const HealthcheckStatusUnhealthy HealthcheckStatus = "unhealthy"` - `const HealthcheckStatusSuspended HealthcheckStatus = "suspended"` - `Suspended bool` If suspended, no health checks are sent to the origin. - `TCPConfig TCPConfiguration` Parameters specific to TCP health check. - `Method TCPConfigurationMethod` The TCP connection method to use for the health check. - `const TCPConfigurationMethodConnectionEstablished TCPConfigurationMethod = "connection_established"` - `Port int64` Port number to connect to for the health check. Defaults to 80. - `Timeout int64` The timeout (in seconds) before marking the health check as failed. - `Type string` The protocol to use for the health check. Currently supported protocols are 'HTTP', 'HTTPS' and 'TCP'. ### Example ```go 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) } ``` #### Response ```json { "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 } ```