Skip to main content

SQL

This check connects 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:
schedule: '@every 30s'
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

integer

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

url

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"
# ...