Skip to main content

SQL

This check will try to connect to a specified Postgres database, run a query against it and verify the results.

apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: postgres-check
spec:
interval: 30
postgres: # or mysql, mssql
- name: postgres schemas check
url: "postgres://$(username):$(password)@postgres.default.svc:5432/postgres?sslmode=disable"
username:
valueFrom:
secretKeyRef:
name: postgres-credentials
key: USERNAME
password:
valueFrom:
secretKeyRef:
name: postgres-credentials
key: PASSWORD
query: SELECT current_schemas(true)
display:
template: |
{{- range $r := .results.rows }}
{{- $r.current_schemas}}
{{- end}}
results: 1
FieldDescriptionScheme
name*

Name of the check, must be unique within the canary

string

query*

Query to execute against the Postgres database

SQL

results

Number of expected rows in results

int

description

Description for the check

string

display

Expression to change the formatting of the display

Expression

icon

Icon for overwriting default icon on the dashboard

Icon

labels

Labels for check

map[string]string

metrics

Metrics to export from

[]Metrics

test

Evaluate whether a check is healthy

Expression

transform

Transform data from a check into multiple individual checks

Expression

connection

The connection to use, mutually exclusive with username and password

Connection

url

If connection is specified and it also includes a url, this field will take precedence

string

username

EnvVar

password

EnvVar

Result Variables

NameDescriptionScheme
rows[]map[string]interface
countNumber of rows returnedint

SQL Server

# ...
kind: Canary
spec:
mssql:
- url: "server=mssql.default.svc;user id=$(username);password=$(password);port=1433;database=master"
# ...

MySQL

# ...
kind: Canary
spec:
mysql:
- url: "$(username):$(password)@tcp(mysql.default.svc:3306)/mysqldb"
# ...

Postgres

# ...
kind: Canary
spec:
mysql:
- url: "postgres://$(username):$(password)@postgres.default.svc:5432/postgres?sslmode=disable"
# ...