# Healthchecks ## List Health Checks `client.Healthchecks.List(ctx, params) (*V4PagePaginationArray[Healthcheck], error)` **get** `/zones/{zone_id}/healthchecks` List configured health checks. ### Parameters - `params HealthcheckListParams` - `ZoneID param.Field[string]` Path param: Identifier - `Page param.Field[float64]` Query param: Page number of paginated results. - `PerPage param.Field[float64]` Query param: Maximum number of results per page. Must be a multiple of 5. ### 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"), ) page, err := client.Healthchecks.List(context.TODO(), healthchecks.HealthcheckListParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### 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, "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` ## Health Check Details `client.Healthchecks.Get(ctx, healthcheckID, query) (*Healthcheck, error)` **get** `/zones/{zone_id}/healthchecks/{healthcheck_id}` Fetch a single configured health check. ### Parameters - `healthcheckID string` Identifier - `query HealthcheckGetParams` - `ZoneID param.Field[string]` Identifier ### 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.Get( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", healthchecks.HealthcheckGetParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) 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 } ``` ## 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 } ``` ## Update Health Check `client.Healthchecks.Update(ctx, healthcheckID, params) (*Healthcheck, error)` **put** `/zones/{zone_id}/healthchecks/{healthcheck_id}` Update a configured health check. ### Parameters - `healthcheckID string` Identifier - `params HealthcheckUpdateParams` - `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.Update( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", healthchecks.HealthcheckUpdateParams{ 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 } ``` ## Patch Health Check `client.Healthchecks.Edit(ctx, healthcheckID, params) (*Healthcheck, error)` **patch** `/zones/{zone_id}/healthchecks/{healthcheck_id}` Patch a configured health check. ### Parameters - `healthcheckID string` Identifier - `params HealthcheckEditParams` - `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.Edit( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", healthchecks.HealthcheckEditParams{ 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 } ``` ## Delete Health Check `client.Healthchecks.Delete(ctx, healthcheckID, body) (*HealthcheckDeleteResponse, error)` **delete** `/zones/{zone_id}/healthchecks/{healthcheck_id}` Delete a health check. ### Parameters - `healthcheckID string` Identifier - `body HealthcheckDeleteParams` - `ZoneID param.Field[string]` Identifier ### Returns - `type HealthcheckDeleteResponse struct{…}` - `ID string` Identifier ### 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.Delete( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", healthchecks.HealthcheckDeleteParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) 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" }, "success": true } ``` ## Domain Types ### Check Region - `type CheckRegion string` WNAM: Western North America, ENAM: Eastern North America, WEU: Western Europe, EEU: Eastern Europe, NSAM: Northern South America, SSAM: Southern South America, OC: Oceania, ME: Middle East, NAF: North Africa, SAF: South Africa, IN: India, SEAS: South East Asia, NEAS: North East Asia, ALL_REGIONS: all regions (BUSINESS and ENTERPRISE customers only). - `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"` ### Healthcheck - `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'. ### HTTP Configuration - `type HTTPConfiguration struct{…}` 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. ### Query Healthcheck - `type QueryHealthcheck struct{…}` - `Address string` The hostname or IP address of the origin server to run health checks on. - `Name string` A short name to identify the health check. Only alphanumeric characters, hyphens and underscores are allowed. - `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. - `Description string` A human-readable description of the health check. - `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. - `Retries int64` The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately. - `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'. ### TCP Configuration - `type TCPConfiguration struct{…}` 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. # Previews ## Health Check Preview Details `client.Healthchecks.Previews.Get(ctx, healthcheckID, query) (*Healthcheck, error)` **get** `/zones/{zone_id}/healthchecks/preview/{healthcheck_id}` Fetch a single configured health check preview. ### Parameters - `healthcheckID string` Identifier - `query PreviewGetParams` - `ZoneID param.Field[string]` Identifier ### 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.Previews.Get( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", healthchecks.PreviewGetParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) 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 } ``` ## Create Preview Health Check `client.Healthchecks.Previews.New(ctx, params) (*Healthcheck, error)` **post** `/zones/{zone_id}/healthchecks/preview` Create a new preview health check. ### Parameters - `params PreviewNewParams` - `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.Previews.New(context.TODO(), healthchecks.PreviewNewParams{ 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 } ``` ## Delete Preview Health Check `client.Healthchecks.Previews.Delete(ctx, healthcheckID, body) (*PreviewDeleteResponse, error)` **delete** `/zones/{zone_id}/healthchecks/preview/{healthcheck_id}` Delete a health check. ### Parameters - `healthcheckID string` Identifier - `body PreviewDeleteParams` - `ZoneID param.Field[string]` Identifier ### Returns - `type PreviewDeleteResponse struct{…}` - `ID string` Identifier ### 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"), ) preview, err := client.Healthchecks.Previews.Delete( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", healthchecks.PreviewDeleteParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", preview.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" }, "success": true } ```