HTTP
This check performs queries on HTTP endpoints, and HTTP Namespaces to monitor their activity.
http-check.yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
  name: http-check
spec:
  interval: 30
  http:
    - name: http pass response 200 status code
      endpoint: https://httpbin.demo.aws.flanksource.com/status/200
      thresholdMillis: 3000
      responseCodes: [201, 200, 301]
      maxSSLExpiry: 7
| Field | Description | Scheme | Required | 
|---|---|---|---|
url | string | Yes | |
endpoint | Deprecated, Use url instread | string | |
method | HTTP Request method, default to GET | string | |
headers | Header fields to be used in the query | []EnvVar | |
body | Request Body Contents | string | |
templateBody | If true the body field will be templated using go templates these variables will be available | boo; | |
responseCodes | Expected response codes for the HTTP Request. | []int | |
responseContent | Exact response content expected to be returned by the endpoint. | string | |
thresholdMillis | Maximum duration in milliseconds for the HTTP request. It will fail the check if it takes longer. | int | |
maxSSLExpiry | Maximum number of days until the SSL Certificate expires. | int | |
name | Name of the check, must be unique within the canary | string | Yes | 
description | Description for the check | string | |
icon | Icon for overwriting default icon on the dashboard | string | |
labels | Labels for check | map[string]string | |
test | Evaluate whether a check is healthy | Expression | |
display | Expression to change the formatting of the display | Expression | |
transform | Transform data from a check into multiple individual checks | Expression | |
metrics | Metrics to export from | []Metrics | |
| Connection | |||
connection | Path of existing connection e.g. connection://http/instance Mutually exclusive with username, password  | Connection | |
username | EnvVar | ||
password | EnvVar | ||
url | HTTP URL, if a URL is specified on both the connection and check, the url on the check takes precedence. | string | Yes | 
ntlm | When true will do authentication using NTLM v1 protocol | bool | |
ntlmv2 | When true will do authentication using NTLM v2 protocol | bool | 
Result Variables
Result variables can be used in test, display and transform expressions
| Name | Description | Scheme | 
|---|---|---|
code | HTTP response code | int | 
headers | HTTP response headers | map[string]string | 
elapsed | HTTP Request duration | time.Duration | 
sslAge | Time until SSL certificate expires | time.Duration | 
content | HTTP Response body | string | 
json | If Content-Type=application/json response body converted into JSON object | JSON | 
The above canary (http-check.yaml) is functionally equivalent to http-check-expr.yaml below
http-check-expr.yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
  name: http-check-expr
spec:
  interval: 30
  http:
    - name: http pass response 200 status code
      endpoint: https://httpbin.demo.aws.flanksource.com/status/200
      test:
        expr: "code in [200,201,301] and sslAge > Duration('7d')"
Template Body Variables
| Name | Scheme | 
|---|---|
metadata.name | string | 
metadata.metadata.namespace | string | 
metadata.labels | map[string]string | 
{fields from []env} | any | 
Variables defined in env will be available to template with the name that's configured on the spec.
Eg: In the following spec, the vars my_secret_path and my_secret_var, defined in env, are available during templating.
http-check.yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
  name: http-check
spec:
  interval: 30
  http:
    - name: http pass response 200 status code
      endpoint: https://example.com/{{.my_secret_path}}
      body: |
        {
          "secret": {{.my_secret_var}}
        }
      env:
        - name: my_secret_var
          valueFrom:
            secretKeyRef:
              name: the-secret
              key: key
        - name: my_secret_path
          value: secret_path
Metrics
| HTTP Check Metrics | ||
|---|---|---|
canary_check_http_response_status{status, statusClass, url} | Counter | Response code counter for each endpoint | 
canary_check_http_ssl_expiry{url} | Guage | 
Status class is one of 1xx, 2xx, 3xx, 4xx, 5xx