refactor query language
This commit is contained in:
Vendored
+1
-1
@@ -20,7 +20,7 @@ const inflight = new Map<string, Promise<MonitorRow[]>>();
|
||||
async function fetchForRegion(region: string): Promise<MonitorRow[]> {
|
||||
return sql<MonitorRow[]>`
|
||||
SELECT id, url, method, request_headers, request_body, timeout_ms, interval_s, query, regions,
|
||||
max_retries, retry_interval_s, created_at
|
||||
max_retries, retry_interval_s, max_redirects, created_at
|
||||
FROM monitors
|
||||
WHERE enabled = true
|
||||
AND (
|
||||
|
||||
@@ -17,6 +17,7 @@ const MonitorBody = t.Object({
|
||||
retry_interval_s: t.Optional(t.Number({ minimum: 1, maximum: 600, default: 30, description: "Seconds between retries" })),
|
||||
resend_interval: t.Optional(t.Number({ minimum: 0, maximum: 1000, default: 0, description: "Re-alert every Nth consecutive down beat. 0 = never resend." })),
|
||||
cert_alert_days: t.Optional(t.Number({ minimum: 0, maximum: 365, default: 0, description: "Alert when TLS cert is within N days of expiry. 0 disables (default)." })),
|
||||
max_redirects: t.Optional(t.Number({ minimum: 0, maximum: 4, default: 1, description: "Follow up to N redirects. 0 = don't follow. Default 1." })),
|
||||
query: t.Optional(t.Any({ description: "PingQL query - filter conditions for up/down" })),
|
||||
regions: t.Optional(t.Array(t.String(), { description: "Regions to run checks from. Empty array = all regions." })),
|
||||
channel_ids: t.Optional(t.Array(t.String(), { description: "Notification channel IDs to attach to this monitor." })),
|
||||
@@ -84,7 +85,7 @@ export const monitors = new Elysia({ prefix: "/monitors" })
|
||||
const tags = body.tags ? dedupeTags(body.tags) : [];
|
||||
const channelIds = body.channel_ids ? await validateChannelIds(accountId, body.channel_ids) : [];
|
||||
const [monitor] = await sql`
|
||||
INSERT INTO monitors (account_id, name, url, method, request_headers, request_body, timeout_ms, interval_s, max_retries, retry_interval_s, resend_interval, cert_alert_days, query, regions, tags, channel_ids)
|
||||
INSERT INTO monitors (account_id, name, url, method, request_headers, request_body, timeout_ms, interval_s, max_retries, retry_interval_s, resend_interval, cert_alert_days, max_redirects, query, regions, tags, channel_ids)
|
||||
VALUES (
|
||||
${accountId}, ${body.name}, ${body.url},
|
||||
${(body.method ?? 'GET').toUpperCase()},
|
||||
@@ -96,6 +97,7 @@ export const monitors = new Elysia({ prefix: "/monitors" })
|
||||
${retryGap},
|
||||
${body.resend_interval ?? 0},
|
||||
${body.cert_alert_days ?? 0},
|
||||
${body.max_redirects ?? 1},
|
||||
${body.query ? sql.json(body.query) : null},
|
||||
${sql.array(regions)},
|
||||
${sql.array(tags)},
|
||||
@@ -157,6 +159,7 @@ export const monitors = new Elysia({ prefix: "/monitors" })
|
||||
retry_interval_s = COALESCE(${body.retry_interval_s ?? null}, retry_interval_s),
|
||||
resend_interval = COALESCE(${body.resend_interval ?? null}, resend_interval),
|
||||
cert_alert_days = COALESCE(${body.cert_alert_days ?? null}, cert_alert_days),
|
||||
max_redirects = COALESCE(${body.max_redirects ?? null}, max_redirects),
|
||||
query = COALESCE(${body.query ? sql.json(body.query) : null}, query),
|
||||
regions = COALESCE(${body.regions ? sql.array(body.regions) : null}, regions),
|
||||
tags = COALESCE(${body.tags ? sql.array(dedupeTags(body.tags)) : null}, tags),
|
||||
|
||||
@@ -196,6 +196,7 @@ export const ingest = new Elysia()
|
||||
up: t.Boolean(),
|
||||
error: t.Optional(t.Nullable(t.String())),
|
||||
cert_expiry_days: t.Optional(t.Nullable(t.Number())),
|
||||
cert_issuer: t.Optional(t.Nullable(t.String())),
|
||||
meta: t.Optional(t.Any()),
|
||||
region: t.Optional(t.Nullable(t.String())),
|
||||
run_id: t.Optional(t.Nullable(t.String())),
|
||||
|
||||
Reference in New Issue
Block a user