diff --git a/DATABASE.md b/DATABASE.md index 611ec5f..596756d 100644 --- a/DATABASE.md +++ b/DATABASE.md @@ -23,7 +23,7 @@ what the app actually creates. |---|---| | **File** | `DATABASE_PATH`, default `../data/homelab-manager.sqlite` (relative to `server/`; `/app/data/...` in Docker). The folder is created if missing. | | **Foreign keys** | Switched on for every connection (`PRAGMA foreign_keys = ON`), so the `ON DELETE` rules below are enforced. | -| **Migrations** | SQL files in [`server/drizzle/`](server/drizzle) (`0000` … `0052`), applied automatically when the server starts. Which ones have run is recorded in the table `__drizzle_migrations`. | +| **Migrations** | SQL files in [`server/drizzle/`](server/drizzle) (`0000` … `0053`), applied automatically when the server starts. Which ones have run is recorded in the table `__drizzle_migrations`. | | **Tables** | 62 application tables, plus drizzle's own `__drizzle_migrations`. | **Not in the database, but beside it in the data folder:** the backups of the database itself (`backups/homelab-manager-….sqlite`, taken daily and on request; see [BACKUP.md](BACKUP.md)), and, only while a restore is waiting or has just happened, `restore-pending.sqlite` / `restore-pending.json` and `restore-result.json`. @@ -899,6 +899,9 @@ A web address, TCP port or TLS certificate the app asks about every few minutes | `kind` | text NOT NULL | `http`, `tcp` or `tls`. | | `target`, `port` | text NOT NULL, integer | http: the address. tcp and tls: the host, and the port. | | `expect_status`, `keyword` | text | http only: the good status codes (`200-204, 401`; null = 200–399) and a word the page must contain. | +| `value_path`, `value_op`, `value_expected`, `value_unit` | text | http only: judge a value in a JSON answer — where it is (`data.result[0].value[1]`), how it must compare (`<` `<=` `>` `>=` `=` `!=` `contains` `exists`), what to, and a unit to show. All null for a check that judges no value. | +| `header_name`, `header_value` | text | http only: a header sent with the request. The value is stored encrypted (`enc:v1:`) when an encryption key is set, and is never returned by the API. | +| `last_value` | text | What a value check read the last time. | | `insecure` | bool NOT NULL, default 0 | Accept a certificate that isn't trusted (its expiry is still watched). | | `interval_minutes`, `timeout_seconds`, `failures_before_alert`, `warn_days` | integer NOT NULL | Defaults 5, 10, 2 and 14. | | `server_id` | integer | The server it is about. A plain reference, **not a foreign key**: maintenance on that server silences the check's alerts; one whose server is gone is just unlinked. | @@ -920,6 +923,7 @@ One row per answer, kept for two weeks: uptime, average answer time and the run | `at` | text NOT NULL | ISO. | | `ok` | bool NOT NULL | | | `ms`, `message` | integer, text | | +| `value` | real | The number a value check read, when it is one; what the value chart is drawn from. | #### `heartbeats` diff --git a/README.md b/README.md index 838e8c9..81197d1 100644 --- a/README.md +++ b/README.md @@ -579,7 +579,8 @@ note can run as HTML. **Endpoint checks** (Monitoring → Endpoints). The app asks a **web address**, a **TCP port** or a **TLS certificate** whether it is fine, every few minutes (each check has its own interval, from 1 minute), and remembers how it went: the answer time, uptime over 24 hours and 7 days, a row of the recent results, and — for https addresses and certificate checks — when the certificate runs out. A web check wants a good status (200–399 unless you say otherwise, like `200-204, 401`) and can -also want a word in the page; a certificate that isn't trusted (self-signed, a private authority) fails unless you tick *Accept a certificate that isn't trusted*, and +also want a word in the page, or **a value in a JSON answer within its limit** — `power.now` below 5000, `state` equal to playing, a Prometheus query's result above 0 — with an optional header (a token) sent with the request; +the value read is shown, charted under *History…*, and in `/metrics`; a certificate that isn't trusted (self-signed, a private authority) fails unless you tick *Accept a certificate that isn't trusted*, and its expiry is watched either way. A check that has **failed several times in a row** (2 by default, so a blip isn't) is a *Monitoring* alert and one notification, with another when it answers again; a certificate within its warning time (14 days by default; critical in the last three) is an *Expiry* alert. A check can be linked to a server, so maintenance on it silences the check's alerts and the server's tags can route them. Everyone can look; administrators set checks up (each one makes this diff --git a/ROLES.md b/ROLES.md index 66dc0cf..95651ac 100644 --- a/ROLES.md +++ b/ROLES.md @@ -124,7 +124,7 @@ even further, to admin only: - **Proxy hosts** (Network → Proxy hosts): everyone signed in sees what Nginx Proxy Manager serves; **Read now** needs operator; adding the integration (its login) is an administrator's job. - **Home Assistant** (Monitoring → Home Assistant): everyone signed in sees what is watched, its state and history; choosing what to watch, its limits, stopping and **Read now** need operator (the list of all entities is read live, so only operators see it); adding the integration (its token) is an administrator's job. -- **Endpoints**: everyone sees the checks and how they are doing; adding, changing and removing one is administrator-only (each makes the server connect somewhere); +- **Endpoints**: everyone sees the checks and how they are doing; adding, changing and removing one is administrator-only (each makes the server connect somewhere); that includes the value a check judges and the header (a token) it sends, whose value is never shown again to anyone; *Check now* needs operator. - **Restore tests**: everyone sees them on the Backup coverage page; recording one needs operator; removing one is administrator-only. - **Change log**: operators and administrators (it is made from the audit log, which has the same readers). diff --git a/docs/API.md b/docs/API.md index d62b000..50b3ad3 100644 --- a/docs/API.md +++ b/docs/API.md @@ -253,15 +253,15 @@ device (and port). Wi-Fi passphrases are never read, so they are never here. { "endpoints": [ { "id": 1, "name": "Wiki", "kind": "http", "target": "https://192.168.1.20/", "port": null, "enabled": true, "status": "up", "lastCheckedAt": "2026-10-20T21:50:00.000Z", "lastResponseMs": 41, "lastMessage": null, - "certificateExpiresAt": "2027-01-04T12:00:00.000Z", "uptime24hPercent": 100, "uptime7dPercent": 99.9, + "value": null, "certificateExpiresAt": "2027-01-04T12:00:00.000Z", "uptime24hPercent": 100, "uptime7dPercent": 99.9, "averageResponseMs24h": 44, "serverId": 1 } ] } ``` -`status` is `up`, `down`, `unknown` (never asked yet) or `paused` (switched off). `lastMessage` is set only while it is failing (why). `kind` is `http`, `tcp` or `tls`. +`status` is `up`, `down`, `unknown` (never asked yet) or `paused` (switched off). `lastMessage` is set only while it is failing (why). `kind` is `http`, `tcp` or `tls`. `value` is null unless the check judges a value in the answer, and then `{ "path": "power.now", "operator": "<", "expected": "5000", "unit": "W", "last": "120" }` (`last` is what it read the last time, as text). `/:id/history?days=` answers `{ check: {id, name}, … points … }`: the availability and answer times over 1–365 days, drawn from each answer (up to 2 days), the hourly figures (up to 120 days) or the daily -ones, whichever is fine enough and still kept. +ones, whichever is fine enough and still kept. A check that judges a value also has `values` — `{ unit, days, points: [{t, v, lo, hi}], latest, lowest, highest }` — over as much of that stretch as results are kept (14 days); otherwise `values` is null. ### `GET /api/v1/maintenance` diff --git a/docs/MONITORING.md b/docs/MONITORING.md index 787dab4..9a081d1 100644 --- a/docs/MONITORING.md +++ b/docs/MONITORING.md @@ -150,7 +150,7 @@ offline or has not reported for 45 minutes is not judged. | Kind | What it asks | |---|---| -| `http` | Fetches an `http(s)://` address. Counts as up if the status is in the accepted set (200–399 unless you say otherwise, e.g. `200-299, 301`), and — if you ask — the page contains a keyword. Follows up to 5 redirects. | +| `http` | Fetches an `http(s)://` address. Counts as up if the status is in the accepted set (200–399 unless you say otherwise, e.g. `200-299, 301`), and — if you ask — the page contains a keyword, and/or **a value in a JSON answer is within its limit** (see below). Follows up to 5 redirects when it has a keyword or value to look for. | | `tcp` | Opens a connection to a host and port. | | `tls` | Connects and reads the certificate; the answer is the days left. | @@ -159,6 +159,15 @@ optional **server it is linked to** (maintenance on that server silences it, and daily summaries for the charts and uptime figures. - A check **fails an alert** (critical) after the configured number of failures in a row, and is announced as resolved when it works again. A **certificate** within its warning days is its own alert (`endpoint-cert:…`). +- **Checking a value, not just "is it up".** A web check can read a number or a word out of a JSON answer and judge it. Say **where** it is — `power.now`, `state`, `items[2].name`, or for a Prometheus query + `data.result[0].value[1]` (`[0]` is the first place in a list; `["a.b"]` for a name with a dot in it) — and **how it should compare**: *is below*, *is at most*, *is above*, *is at least*, *is equal to*, *is anything but*, + *contains*, or *is there*. A number given as text (`"42.5"`, which is how Prometheus gives them) counts as a number; equality compares numbers as numbers and anything else as the same text, capital letters + included. An optional **unit** (`W`, `%`) is shown after a number. The status is judged first, then the value: a value outside its limit is a failure that says so ("power.now is 5200 W, but should be below 5000 W"), + and the alert reads *Meter — power.now is 5200 W, but …* rather than "isn't answering". It is also a failure if the answer isn't JSON, the path isn't in it ("it stops at power"), or the answer is more than 64 KB. + The value read is remembered with each result: shown in the *Answer* column, charted under **History…** (as far back as results are kept, 14 days), in `/metrics` as `homelab_endpoint_value` (numbers only) and in the read API. + Examples: Home Assistant's `/api/states/sensor.power` (path `state`), a Plex or Frigate status, an inverter's output, a Prometheus query (`/api/v1/query?query=…`). +- **A header, for an API that wants a token.** A web check can send one header with its request (usually `Authorization: Bearer …`). The value is stored **encrypted** when `CREDENTIALS_ENCRYPTION_KEY` is set, is never sent back + to the browser (the form says *Saved — leave blank to keep it*), and goes only to the address you gave — **not to another host a redirect leads to**. - What an administrator types in cannot be just anything: loopback, link-local and cloud-metadata addresses are refused, and the connection goes to the one address that passed the check. LAN and public hosts are fine. - The app suggests checks it can already work out (a web port a server's agent sees open, a secret with a host) under *Endpoints → Suggested*, and proxied hosts Nginx Proxy Manager serves. diff --git a/docs/PROMETHEUS-GRAFANA.md b/docs/PROMETHEUS-GRAFANA.md index 6136910..5d2a4ae 100644 --- a/docs/PROMETHEUS-GRAFANA.md +++ b/docs/PROMETHEUS-GRAFANA.md @@ -290,6 +290,7 @@ All gauges. The same table is checked by a test against what `/metrics` really s | `homelab_backup_last_age_seconds` | `guest`, `vmid`, `integration` | How long ago a guest's newest backup was. | | `homelab_endpoint_up` | `name`, `kind` | 1 if the endpoint check's last answer was fine, else 0; left out until it has been asked. | | `homelab_endpoint_response_milliseconds` | `name`, `kind` | How long it took to answer the last time. | +| `homelab_endpoint_value` | `name`, `kind` | The number a value check last read from the answer (checks that judge a value only, and only when it is a number). | | `homelab_endpoint_certificate_days_left` | `name`, `kind` | Days until the certificate it shows expires (negative once it has). | | `homelab_heartbeat_up` | `name` | 1 if the job has reported in time and not said it failed, else 0; switched-off heartbeats are left out. | | `homelab_heartbeat_last_ping_timestamp_seconds` | `name` | When the job last reported that it finished (Unix time). | diff --git a/server/drizzle/0053_dashing_stark_industries.sql b/server/drizzle/0053_dashing_stark_industries.sql new file mode 100644 index 0000000..83d0148 --- /dev/null +++ b/server/drizzle/0053_dashing_stark_industries.sql @@ -0,0 +1,8 @@ +ALTER TABLE `endpoint_checks` ADD `value_path` text;--> statement-breakpoint +ALTER TABLE `endpoint_checks` ADD `value_op` text;--> statement-breakpoint +ALTER TABLE `endpoint_checks` ADD `value_expected` text;--> statement-breakpoint +ALTER TABLE `endpoint_checks` ADD `value_unit` text;--> statement-breakpoint +ALTER TABLE `endpoint_checks` ADD `header_name` text;--> statement-breakpoint +ALTER TABLE `endpoint_checks` ADD `header_value` text;--> statement-breakpoint +ALTER TABLE `endpoint_checks` ADD `last_value` text;--> statement-breakpoint +ALTER TABLE `endpoint_results` ADD `value` real; \ No newline at end of file diff --git a/server/drizzle/meta/0053_snapshot.json b/server/drizzle/meta/0053_snapshot.json new file mode 100644 index 0000000..b988eb1 --- /dev/null +++ b/server/drizzle/meta/0053_snapshot.json @@ -0,0 +1,5934 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "7b8dbc1b-c579-41ef-ae52-3aa3b9043b7c", + "prevId": "bd78e385-449c-432f-8615-38726b1e0e3f", + "tables": { + "alert_acks": { + "name": "alert_acks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alert_key": { + "name": "alert_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "assignee_user_id": { + "name": "assignee_user_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_name": { + "name": "assignee_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "acked_by": { + "name": "acked_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "acked_at": { + "name": "acked_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "until": { + "name": "until", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "alert_acks_key_idx": { + "name": "alert_acks_key_idx", + "columns": [ + "alert_key" + ], + "isUnique": true + } + }, + "foreignKeys": { + "alert_acks_assignee_user_id_users_id_fk": { + "name": "alert_acks_assignee_user_id_users_id_fk", + "tableFrom": "alert_acks", + "tableTo": "users", + "columnsFrom": [ + "assignee_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "alert_incidents": { + "name": "alert_incidents", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alert_key": { + "name": "alert_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "peak_severity": { + "name": "peak_severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "link": { + "name": "link", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_name": { + "name": "target_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "caused_by": { + "name": "caused_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "opened_at": { + "name": "opened_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "missing_since": { + "name": "missing_since", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "escalated_step": { + "name": "escalated_step", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "escalated_at": { + "name": "escalated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "alert_incidents_key_idx": { + "name": "alert_incidents_key_idx", + "columns": [ + "alert_key" + ], + "isUnique": false + }, + "alert_incidents_opened_idx": { + "name": "alert_incidents_opened_idx", + "columns": [ + "opened_at" + ], + "isUnique": false + }, + "alert_incidents_target_idx": { + "name": "alert_incidents_target_idx", + "columns": [ + "target_type", + "target_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "alert_rules": { + "name": "alert_rules", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "metric": { + "name": "metric", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mount": { + "name": "mount", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "operator": { + "name": "operator", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'above'" + }, + "threshold": { + "name": "threshold", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "for_minutes": { + "name": "for_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'warning'" + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "alert_snoozes": { + "name": "alert_snoozes", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alert_id": { + "name": "alert_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "condition_key": { + "name": "condition_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "until": { + "name": "until", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "snoozed_by": { + "name": "snoozed_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "snoozed_at": { + "name": "snoozed_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "alert_snoozes_alert_idx": { + "name": "alert_snoozes_alert_idx", + "columns": [ + "alert_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "alert_tickets": { + "name": "alert_tickets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alert_key": { + "name": "alert_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "seen_count": { + "name": "seen_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ticket_number": { + "name": "ticket_number", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "grouped": { + "name": "grouped", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ticketed_at": { + "name": "ticketed_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cleared_at": { + "name": "cleared_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "alert_tickets_key_idx": { + "name": "alert_tickets_key_idx", + "columns": [ + "alert_key" + ], + "isUnique": false + } + }, + "foreignKeys": { + "alert_tickets_integration_id_integrations_id_fk": { + "name": "alert_tickets_integration_id_integrations_id_fk", + "tableFrom": "alert_tickets", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "api_tokens": { + "name": "api_tokens", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_used_at": { + "name": "last_used_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "api_tokens_token_hash_unique": { + "name": "api_tokens_token_hash_unique", + "columns": [ + "token_hash" + ], + "isUnique": true + } + }, + "foreignKeys": { + "api_tokens_user_id_users_id_fk": { + "name": "api_tokens_user_id_users_id_fk", + "tableFrom": "api_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "assets": { + "name": "assets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'other'" + }, + "manufacturer": { + "name": "manufacturer", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "serial": { + "name": "serial", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "purchase_date": { + "name": "purchase_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "purchase_price": { + "name": "purchase_price", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "warranty_until": { + "name": "warranty_until", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "end_of_support": { + "name": "end_of_support", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "replacement_cost": { + "name": "replacement_cost", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rack_unit": { + "name": "rack_unit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "power_watts": { + "name": "power_watts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "audit_log": { + "name": "audit_log", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "actor_label": { + "name": "actor_label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "audit_log_actor_user_id_users_id_fk": { + "name": "audit_log_actor_user_id_users_id_fk", + "tableFrom": "audit_log", + "tableTo": "users", + "columnsFrom": [ + "actor_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "consistency_ignores": { + "name": "consistency_ignores", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "consistency_ignores_key_unique": { + "name": "consistency_ignores_key_unique", + "columns": [ + "key" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dependencies": { + "name": "dependencies", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "from_type": { + "name": "from_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "from_id": { + "name": "from_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "to_type": { + "name": "to_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "to_id": { + "name": "to_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "dependencies_edge_idx": { + "name": "dependencies_edge_idx", + "columns": [ + "from_type", + "from_id", + "to_type", + "to_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "diag_log": { + "name": "diag_log", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "operation": { + "name": "operation", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ok": { + "name": "ok", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "latency_ms": { + "name": "latency_ms", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dns_providers": { + "name": "dns_providers", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider_type": { + "name": "provider_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credential_id": { + "name": "credential_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "config": { + "name": "config", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "dns_providers_credential_id_integration_credentials_id_fk": { + "name": "dns_providers_credential_id_integration_credentials_id_fk", + "tableFrom": "dns_providers", + "tableTo": "integration_credentials", + "columnsFrom": [ + "credential_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dns_records_cache": { + "name": "dns_records_cache", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider_id": { + "name": "provider_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "zone_id": { + "name": "zone_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "record_id": { + "name": "record_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ttl": { + "name": "ttl", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxied": { + "name": "proxied", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "dns_records_cache_provider_id_dns_providers_id_fk": { + "name": "dns_records_cache_provider_id_dns_providers_id_fk", + "tableFrom": "dns_records_cache", + "tableTo": "dns_providers", + "columnsFrom": [ + "provider_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dns_zones_cache": { + "name": "dns_zones_cache", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider_id": { + "name": "provider_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "zone_id": { + "name": "zone_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "zone_name": { + "name": "zone_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "synced_at": { + "name": "synced_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "dns_zones_cache_provider_zone_idx": { + "name": "dns_zones_cache_provider_zone_idx", + "columns": [ + "provider_id", + "zone_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "dns_zones_cache_provider_id_dns_providers_id_fk": { + "name": "dns_zones_cache_provider_id_dns_providers_id_fk", + "tableFrom": "dns_zones_cache", + "tableTo": "dns_providers", + "columnsFrom": [ + "provider_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "domains": { + "name": "domains", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "origin": { + "name": "origin", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'manual'" + }, + "expires_at": { + "name": "expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "registrar": { + "name": "registrar", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lookup_source": { + "name": "lookup_source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_checked_ok_at": { + "name": "last_checked_ok_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_check_error": { + "name": "last_check_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "domains_name_unique": { + "name": "domains_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "endpoint_checks": { + "name": "endpoint_checks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target": { + "name": "target", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "port": { + "name": "port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expect_status": { + "name": "expect_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "keyword": { + "name": "keyword", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "insecure": { + "name": "insecure", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "value_path": { + "name": "value_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "value_op": { + "name": "value_op", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "value_expected": { + "name": "value_expected", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "value_unit": { + "name": "value_unit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "header_name": { + "name": "header_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "header_value": { + "name": "header_value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_value": { + "name": "last_value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "interval_minutes": { + "name": "interval_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 5 + }, + "timeout_seconds": { + "name": "timeout_seconds", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 10 + }, + "failures_before_alert": { + "name": "failures_before_alert", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 2 + }, + "warn_days": { + "name": "warn_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 14 + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_ok": { + "name": "last_ok", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_message": { + "name": "last_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_response_ms": { + "name": "last_response_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cert_expires_at": { + "name": "cert_expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "last_change_at": { + "name": "last_change_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "endpoint_daily": { + "name": "endpoint_daily", + "columns": { + "check_id": { + "name": "check_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "day": { + "name": "day", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "total": { + "name": "total", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "ok": { + "name": "ok", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "ms_sum": { + "name": "ms_sum", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "ms_count": { + "name": "ms_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "endpoint_daily_check_id_endpoint_checks_id_fk": { + "name": "endpoint_daily_check_id_endpoint_checks_id_fk", + "tableFrom": "endpoint_daily", + "tableTo": "endpoint_checks", + "columnsFrom": [ + "check_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "endpoint_daily_check_id_day_pk": { + "columns": [ + "check_id", + "day" + ], + "name": "endpoint_daily_check_id_day_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "endpoint_hourly": { + "name": "endpoint_hourly", + "columns": { + "check_id": { + "name": "check_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hour": { + "name": "hour", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "total": { + "name": "total", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "ok": { + "name": "ok", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "ms_sum": { + "name": "ms_sum", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "ms_count": { + "name": "ms_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "ms_max": { + "name": "ms_max", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "endpoint_hourly_check_id_endpoint_checks_id_fk": { + "name": "endpoint_hourly_check_id_endpoint_checks_id_fk", + "tableFrom": "endpoint_hourly", + "tableTo": "endpoint_checks", + "columnsFrom": [ + "check_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "endpoint_hourly_check_id_hour_pk": { + "columns": [ + "check_id", + "hour" + ], + "name": "endpoint_hourly_check_id_hour_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "endpoint_results": { + "name": "endpoint_results", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "check_id": { + "name": "check_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "at": { + "name": "at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ok": { + "name": "ok", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ms": { + "name": "ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "endpoint_results_check_idx": { + "name": "endpoint_results_check_idx", + "columns": [ + "check_id", + "at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "endpoint_results_check_id_endpoint_checks_id_fk": { + "name": "endpoint_results_check_id_endpoint_checks_id_fk", + "tableFrom": "endpoint_results", + "tableTo": "endpoint_checks", + "columnsFrom": [ + "check_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "event_webhooks": { + "name": "event_webhooks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "events": { + "name": "events", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_attempt_at": { + "name": "last_attempt_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_result": { + "name": "last_result", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ha_entities": { + "name": "ha_entities", + "columns": { + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "friendly_name": { + "name": "friendly_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "device_class": { + "name": "device_class", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_changed": { + "name": "last_changed", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "unavailable_since": { + "name": "unavailable_since", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "ha_entities_integration_id_integrations_id_fk": { + "name": "ha_entities_integration_id_integrations_id_fk", + "tableFrom": "ha_entities", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "ha_entities_integration_id_entity_id_pk": { + "columns": [ + "integration_id", + "entity_id" + ], + "name": "ha_entities_integration_id_entity_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ha_readings": { + "name": "ha_readings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "at": { + "name": "at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "ha_readings_lookup_idx": { + "name": "ha_readings_lookup_idx", + "columns": [ + "integration_id", + "entity_id", + "at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "ha_readings_integration_id_integrations_id_fk": { + "name": "ha_readings_integration_id_integrations_id_fk", + "tableFrom": "ha_readings", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ha_watched": { + "name": "ha_watched", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "above": { + "name": "above", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "below": { + "name": "below", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "ha_watched_unique": { + "name": "ha_watched_unique", + "columns": [ + "integration_id", + "entity_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "ha_watched_integration_id_integrations_id_fk": { + "name": "ha_watched_integration_id_integrations_id_fk", + "tableFrom": "ha_watched", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "heartbeat_pings": { + "name": "heartbeat_pings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "heartbeat_id": { + "name": "heartbeat_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "at": { + "name": "at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "heartbeat_pings_idx": { + "name": "heartbeat_pings_idx", + "columns": [ + "heartbeat_id", + "at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "heartbeat_pings_heartbeat_id_heartbeats_id_fk": { + "name": "heartbeat_pings_heartbeat_id_heartbeats_id_fk", + "tableFrom": "heartbeat_pings", + "tableTo": "heartbeats", + "columnsFrom": [ + "heartbeat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "heartbeats": { + "name": "heartbeats", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "period_minutes": { + "name": "period_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "grace_minutes": { + "name": "grace_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 10 + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_ping_at": { + "name": "last_ping_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_status": { + "name": "last_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_message": { + "name": "last_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_duration_ms": { + "name": "last_duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_start_at": { + "name": "last_start_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ping_count": { + "name": "ping_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "heartbeats_token_unique": { + "name": "heartbeats_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "incident_notes": { + "name": "incident_notes", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "incident_id": { + "name": "incident_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "author": { + "name": "author", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "incident_notes_incident_idx": { + "name": "incident_notes_incident_idx", + "columns": [ + "incident_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "incident_notes_incident_id_alert_incidents_id_fk": { + "name": "incident_notes_incident_id_alert_incidents_id_fk", + "tableFrom": "incident_notes", + "tableTo": "alert_incidents", + "columnsFrom": [ + "incident_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "integration_credentials": { + "name": "integration_credentials", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "encrypted_secret": { + "name": "encrypted_secret", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "integrations": { + "name": "integrations", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_url": { + "name": "base_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credential_id": { + "name": "credential_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "config": { + "name": "config", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "integrations_credential_id_integration_credentials_id_fk": { + "name": "integrations_credential_id_integration_credentials_id_fk", + "tableFrom": "integrations", + "tableTo": "integration_credentials", + "columnsFrom": [ + "credential_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ipam_entries": { + "name": "ipam_entries", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "vendor": { + "name": "vendor", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "ipam_entries_ip_address_unique": { + "name": "ipam_entries_ip_address_unique", + "columns": [ + "ip_address" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "maintenance_aliases": { + "name": "maintenance_aliases", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "maintenance_aliases_unique_idx": { + "name": "maintenance_aliases_unique_idx", + "columns": [ + "address", + "target_type", + "target_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "maintenance_schedules": { + "name": "maintenance_schedules", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "targets": { + "name": "targets", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "days": { + "name": "days", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration_minutes": { + "name": "duration_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "maintenance_windows": { + "name": "maintenance_windows", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ends_at": { + "name": "ends_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "metrics_tokens": { + "name": "metrics_tokens", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_used_at": { + "name": "last_used_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "metrics_tokens_token_hash_unique": { + "name": "metrics_tokens_token_hash_unique", + "columns": [ + "token_hash" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "network_devices": { + "name": "network_devices", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "site_name": { + "name": "site_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'other'" + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mac": { + "name": "mac", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'other'" + }, + "uptime_seconds": { + "name": "uptime_seconds", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "firmware": { + "name": "firmware", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "firmware_updatable": { + "name": "firmware_updatable", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "uplink_external_id": { + "name": "uplink_external_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "offline_since": { + "name": "offline_since", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_online_at": { + "name": "last_online_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "network_devices_unique": { + "name": "network_devices_unique", + "columns": [ + "integration_id", + "external_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "network_devices_integration_id_integrations_id_fk": { + "name": "network_devices_integration_id_integrations_id_fk", + "tableFrom": "network_devices", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "network_segments": { + "name": "network_segments", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "site_name": { + "name": "site_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "vlan_id": { + "name": "vlan_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "subnet": { + "name": "subnet", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "purpose": { + "name": "purpose", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "security": { + "name": "security", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "network_name": { + "name": "network_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "network_segments_unique": { + "name": "network_segments_unique", + "columns": [ + "integration_id", + "kind", + "external_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "network_segments_integration_id_integrations_id_fk": { + "name": "network_segments_integration_id_integrations_id_fk", + "tableFrom": "network_segments", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "network_server_links": { + "name": "network_server_links", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "device_external_id": { + "name": "device_external_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "client_mac": { + "name": "client_mac", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "port": { + "name": "port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wired": { + "name": "wired", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "network_server_links_unique": { + "name": "network_server_links_unique", + "columns": [ + "integration_id", + "server_id", + "client_mac" + ], + "isUnique": true + } + }, + "foreignKeys": { + "network_server_links_integration_id_integrations_id_fk": { + "name": "network_server_links_integration_id_integrations_id_fk", + "tableFrom": "network_server_links", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "network_server_links_server_id_servers_id_fk": { + "name": "network_server_links_server_id_servers_id_fk", + "tableFrom": "network_server_links", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "notes": { + "name": "notes", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "notes_target_idx": { + "name": "notes_target_idx", + "columns": [ + "target_type", + "target_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "notification_queue": { + "name": "notification_queue", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "audience": { + "name": "audience", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "patch_plan_runs": { + "name": "patch_plan_runs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "plan_id": { + "name": "plan_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "plan_name": { + "name": "plan_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "started_by": { + "name": "started_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "finished_at": { + "name": "finished_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "patch_plan_runs_plan_idx": { + "name": "patch_plan_runs_plan_idx", + "columns": [ + "plan_id", + "started_at" + ], + "isUnique": false + }, + "patch_plan_runs_status_idx": { + "name": "patch_plan_runs_status_idx", + "columns": [ + "status" + ], + "isUnique": false + } + }, + "foreignKeys": { + "patch_plan_runs_plan_id_patch_plans_id_fk": { + "name": "patch_plan_runs_plan_id_patch_plans_id_fk", + "tableFrom": "patch_plan_runs", + "tableTo": "patch_plans", + "columnsFrom": [ + "plan_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "patch_plans": { + "name": "patch_plans", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "days": { + "name": "days", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tags": { + "name": "tags", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "server_ids": { + "name": "server_ids", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "template_name": { + "name": "template_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "limit_from": { + "name": "limit_from", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'name'" + }, + "stop_on_failure": { + "name": "stop_on_failure", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "only_with_updates": { + "name": "only_with_updates", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "silence_dependents": { + "name": "silence_dependents", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "window_minutes": { + "name": "window_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 90 + }, + "last_run_date": { + "name": "last_run_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "port_forwards": { + "name": "port_forwards", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "external_port": { + "name": "external_port", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "protocol": { + "name": "protocol", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'tcp'" + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "destination": { + "name": "destination", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "internal_port": { + "name": "internal_port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "port_forwards_server_id_servers_id_fk": { + "name": "port_forwards_server_id_servers_id_fk", + "tableFrom": "port_forwards", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "push_subscriptions": { + "name": "push_subscriptions", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_success_at": { + "name": "last_success_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "min_severity": { + "name": "min_severity", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "categories": { + "name": "categories", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "push_subscriptions_endpoint_unique": { + "name": "push_subscriptions_endpoint_unique", + "columns": [ + "endpoint" + ], + "isUnique": true + } + }, + "foreignKeys": { + "push_subscriptions_user_id_users_id_fk": { + "name": "push_subscriptions_user_id_users_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "renewals": { + "name": "renewals", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "at": { + "name": "at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "from_date": { + "name": "from_date", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "to_date": { + "name": "to_date", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "renewals_at_idx": { + "name": "renewals_at_idx", + "columns": [ + "at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "restore_tests": { + "name": "restore_tests", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "subject_key": { + "name": "subject_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tested_at": { + "name": "tested_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "result": { + "name": "result", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tested_by": { + "name": "tested_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "restore_tests_subject_idx": { + "name": "restore_tests_subject_idx", + "columns": [ + "subject_key", + "tested_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "runbooks": { + "name": "runbooks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "runbooks_target_idx": { + "name": "runbooks_target_idx", + "columns": [ + "target_type", + "target_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "scheduled_tasks": { + "name": "scheduled_tasks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "schedule_type": { + "name": "schedule_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "origin": { + "name": "origin", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'agent'" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "command": { + "name": "command", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "schedule_expression": { + "name": "schedule_expression", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "next_run_at": { + "name": "next_run_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_metadata": { + "name": "raw_metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_stale": { + "name": "is_stale", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "scheduled_tasks_server_id_servers_id_fk": { + "name": "scheduled_tasks_server_id_servers_id_fk", + "tableFrom": "scheduled_tasks", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "secrets": { + "name": "secrets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'generic'" + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expiry_date": { + "name": "expiry_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "warn_days": { + "name": "warn_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 30 + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "check_host": { + "name": "check_host", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "check_port": { + "name": "check_port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_check_error": { + "name": "last_check_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "server_links": { + "name": "server_links", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "server_links_server_id_servers_id_fk": { + "name": "server_links_server_id_servers_id_fk", + "tableFrom": "server_links", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "server_metrics": { + "name": "server_metrics", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "metric": { + "name": "metric", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "recorded_at": { + "name": "recorded_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "server_metrics_lookup_idx": { + "name": "server_metrics_lookup_idx", + "columns": [ + "server_id", + "metric", + "recorded_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "server_metrics_server_id_servers_id_fk": { + "name": "server_metrics_server_id_servers_id_fk", + "tableFrom": "server_metrics", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "server_metrics_rollup": { + "name": "server_metrics_rollup", + "columns": { + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "metric": { + "name": "metric", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "grain": { + "name": "grain", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "at": { + "name": "at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sum": { + "name": "sum", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "min": { + "name": "min", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "max": { + "name": "max", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "server_metrics_rollup_server_id_servers_id_fk": { + "name": "server_metrics_rollup_server_id_servers_id_fk", + "tableFrom": "server_metrics_rollup", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "server_metrics_rollup_server_id_metric_grain_at_pk": { + "columns": [ + "server_id", + "metric", + "grain", + "at" + ], + "name": "server_metrics_rollup_server_id_metric_grain_at_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "server_ports": { + "name": "server_ports", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "port": { + "name": "port", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "protocol": { + "name": "protocol", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'tcp'" + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "open": { + "name": "open", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "last_seen_open_at": { + "name": "last_seen_open_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "server_ports_unique": { + "name": "server_ports_unique", + "columns": [ + "server_id", + "port", + "protocol" + ], + "isUnique": true + } + }, + "foreignKeys": { + "server_ports_server_id_servers_id_fk": { + "name": "server_ports_server_id_servers_id_fk", + "tableFrom": "server_ports", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "servers": { + "name": "servers", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hostname": { + "name": "hostname", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "os_type": { + "name": "os_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'linux'" + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "api_token_hash": { + "name": "api_token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "api_token_prefix": { + "name": "api_token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ip_addresses": { + "name": "ip_addresses", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpu_model": { + "name": "cpu_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpu_cores": { + "name": "cpu_cores", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpu_load_percent": { + "name": "cpu_load_percent", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mem_total_bytes": { + "name": "mem_total_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mem_used_bytes": { + "name": "mem_used_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "disks": { + "name": "disks", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "listening_ports": { + "name": "listening_ports", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_port_scan": { + "name": "last_port_scan", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tags": { + "name": "tags", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxmox_integration_id": { + "name": "proxmox_integration_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxmox_node": { + "name": "proxmox_node", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxmox_guest_type": { + "name": "proxmox_guest_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxmox_vmid": { + "name": "proxmox_vmid", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hide_proxmox_link": { + "name": "hide_proxmox_link", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "parent_server_id": { + "name": "parent_server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "no_parent": { + "name": "no_parent", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "pending_updates": { + "name": "pending_updates", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updates_pending_since": { + "name": "updates_pending_since", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "host_health": { + "name": "host_health", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "agent_diagnostics": { + "name": "agent_diagnostics", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "port_baseline": { + "name": "port_baseline", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "os_id": { + "name": "os_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "os_name": { + "name": "os_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "os_version": { + "name": "os_version", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hw_manufacturer": { + "name": "hw_manufacturer", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hw_model": { + "name": "hw_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hw_serial": { + "name": "hw_serial", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "thresholds": { + "name": "thresholds", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "agent_version": { + "name": "agent_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "servers_proxmox_integration_id_integrations_id_fk": { + "name": "servers_proxmox_integration_id_integrations_id_fk", + "tableFrom": "servers", + "tableTo": "integrations", + "columnsFrom": [ + "proxmox_integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "settings": { + "name": "settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "share_links": { + "name": "share_links", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'summary'" + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'wall'" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "expires_at": { + "name": "expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "share_links_token_hash_unique": { + "name": "share_links_token_hash_unique", + "columns": [ + "token_hash" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "status_items": { + "name": "status_items", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "link_id": { + "name": "link_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "monitor_id": { + "name": "monitor_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "status_items_link_idx": { + "name": "status_items_link_idx", + "columns": [ + "link_id", + "position" + ], + "isUnique": false + } + }, + "foreignKeys": { + "status_items_link_id_share_links_id_fk": { + "name": "status_items_link_id_share_links_id_fk", + "tableFrom": "status_items", + "tableTo": "share_links", + "columnsFrom": [ + "link_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "storage_samples": { + "name": "storage_samples", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "at": { + "name": "at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "storage_samples_series_idx": { + "name": "storage_samples_series_idx", + "columns": [ + "series_id", + "at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "storage_samples_series_id_storage_series_id_fk": { + "name": "storage_samples_series_id_storage_series_id_fk", + "tableFrom": "storage_samples", + "tableTo": "storage_series", + "columnsFrom": [ + "series_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "storage_series": { + "name": "storage_series", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "latest_percent": { + "name": "latest_percent", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "used_bytes": { + "name": "used_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "total_bytes": { + "name": "total_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "storage_series_key_idx": { + "name": "storage_series_key_idx", + "columns": [ + "integration_id", + "key" + ], + "isUnique": true + } + }, + "foreignKeys": { + "storage_series_integration_id_integrations_id_fk": { + "name": "storage_series_integration_id_integrations_id_fk", + "tableFrom": "storage_series", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tag_definitions": { + "name": "tag_definitions", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "tag_definitions_name_unique": { + "name": "tag_definitions_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "todos": { + "name": "todos", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "due_date": { + "name": "due_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_user_id": { + "name": "assignee_user_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_name": { + "name": "assignee_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "done_at": { + "name": "done_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "done_by": { + "name": "done_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "todos_assignee_user_id_users_id_fk": { + "name": "todos_assignee_user_id_users_id_fk", + "tableFrom": "todos", + "tableTo": "users", + "columnsFrom": [ + "assignee_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "update_runs": { + "name": "update_runs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "template_name": { + "name": "template_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "host_limit": { + "name": "host_limit", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "task_id": { + "name": "task_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "task_status": { + "name": "task_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "window_id": { + "name": "window_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "window_created": { + "name": "window_created", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_by": { + "name": "started_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "task_ended_at": { + "name": "task_ended_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "host_reported_at": { + "name": "host_reported_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "finished_at": { + "name": "finished_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updates_before": { + "name": "updates_before", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updates_after": { + "name": "updates_after", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reboot_required": { + "name": "reboot_required", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "poll_errors": { + "name": "poll_errors", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": { + "update_runs_server_idx": { + "name": "update_runs_server_idx", + "columns": [ + "server_id", + "started_at" + ], + "isUnique": false + }, + "update_runs_status_idx": { + "name": "update_runs_status_idx", + "columns": [ + "status" + ], + "isUnique": false + } + }, + "foreignKeys": { + "update_runs_server_id_servers_id_fk": { + "name": "update_runs_server_id_servers_id_fk", + "tableFrom": "update_runs", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "oidc_sub": { + "name": "oidc_sub", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'viewer'" + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_login_at": { + "name": "last_login_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "favorites": { + "name": "favorites", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_looked_at": { + "name": "last_looked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "groups": { + "name": "groups", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dashboard_layout": { + "name": "dashboard_layout", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "picture_url": { + "name": "picture_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "users_oidc_sub_unique": { + "name": "users_oidc_sub_unique", + "columns": [ + "oidc_sub" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "webhook_deliveries": { + "name": "webhook_deliveries", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "webhook_id": { + "name": "webhook_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "event": { + "name": "event", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "delivery_id": { + "name": "delivery_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "ok": { + "name": "ok", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "result": { + "name": "result", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "retry_of": { + "name": "retry_of", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "webhook_deliveries_webhook_idx": { + "name": "webhook_deliveries_webhook_idx", + "columns": [ + "webhook_id", + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "webhook_deliveries_webhook_id_event_webhooks_id_fk": { + "name": "webhook_deliveries_webhook_id_event_webhooks_id_fk", + "tableFrom": "webhook_deliveries", + "tableTo": "event_webhooks", + "columnsFrom": [ + "webhook_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/server/drizzle/meta/_journal.json b/server/drizzle/meta/_journal.json index fa7a77e..607d6a9 100644 --- a/server/drizzle/meta/_journal.json +++ b/server/drizzle/meta/_journal.json @@ -372,6 +372,13 @@ "when": 1792608282223, "tag": "0052_brainy_steve_rogers", "breakpoints": true + }, + { + "idx": 53, + "version": "6", + "when": 1792609540216, + "tag": "0053_dashing_stark_industries", + "breakpoints": true } ] } \ No newline at end of file diff --git a/server/src/db/schema.ts b/server/src/db/schema.ts index 527c94c..23791b0 100644 --- a/server/src/db/schema.ts +++ b/server/src/db/schema.ts @@ -141,6 +141,13 @@ export const endpointChecks = sqliteTable("endpoint_checks", { expectStatus: text("expect_status"), // http: "200-299, 301"; null = 200-399 keyword: text("keyword"), // http: text the page must contain insecure: integer("insecure", { mode: "boolean" }).notNull().default(false), // accept a certificate that isn't trusted (self-signed, a private CA) + valuePath: text("value_path"), // http: where in a JSON answer the value to judge is ("data.result[0].value[1]") + valueOp: text("value_op"), // http: "<" "<=" ">" ">=" "=" "!=" "contains" "exists" + valueExpected: text("value_expected"), // http: what it is compared with (a number, or text for "=", "!=" and "contains") + valueUnit: text("value_unit"), // http: shown after the value ("W", "%", "°C") + headerName: text("header_name"), // http: a header to send with the request ("Authorization") + headerValue: text("header_value"), // its value, encrypted at rest like the notification channels' secrets; never returned by the API + lastValue: text("last_value"), // http: what was read the last time, as text intervalMinutes: integer("interval_minutes").notNull().default(5), timeoutSeconds: integer("timeout_seconds").notNull().default(10), failuresBeforeAlert: integer("failures_before_alert").notNull().default(2), @@ -170,6 +177,7 @@ export const endpointResults = sqliteTable( ok: integer("ok", { mode: "boolean" }).notNull(), ms: integer("ms"), message: text("message"), + value: real("value"), // the number read from the answer, for a check that judges a value }, (t) => [index("endpoint_results_check_idx").on(t.checkId, t.at)], ); diff --git a/server/src/routes/endpoints.ts b/server/src/routes/endpoints.ts index 3b8144b..68ea2d1 100644 --- a/server/src/routes/endpoints.ts +++ b/server/src/routes/endpoints.ts @@ -6,7 +6,9 @@ import { endpointChecks, servers } from "../db/schema.js"; import { requireAuth, requireRole } from "../auth/middleware.js"; import { recordAudit } from "../services/audit.js"; import { invalidateAlertsCache } from "../services/alerts.js"; -import { CHECK_KINDS, getEndpointHistory, isStatusSpec, loadStats, runCheck } from "../services/endpointChecks.js"; +import { CHECK_KINDS, getEndpointHistory, isStatusSpec, loadStats, runCheck, type CheckRow } from "../services/endpointChecks.js"; +import { sealSecret } from "../services/sealed.js"; +import { VALUE_OPS, valueProblem } from "../services/valueCheck.js"; import { loadDismissed, loadSuggestions, saveDismissed } from "../services/endpointSuggestions.js"; import { asyncHandler } from "../utils/asyncHandler.js"; @@ -16,6 +18,17 @@ endpointsRouter.use(requireAuth); const MAX_CHECKS = 100; +/** A blank text field is no value. */ +function blank(v: string | null | undefined): string | null { + return v === undefined || v === null || v.trim() === "" ? null : v.trim(); +} + +/** A check as the API shows it: the header's value is never sent back, only that there is one. */ +function publicCheck(row: CheckRow) { + const { headerValue, ...rest } = row; + return { ...rest, hasHeader: !!row.headerName && !!headerValue }; +} + const checkSchema = z .object({ name: z.string().trim().min(1).max(100), @@ -24,6 +37,13 @@ const checkSchema = z port: z.number().int().min(1).max(65535).nullable().optional(), expectStatus: z.string().trim().max(60).nullable().optional(), keyword: z.string().max(200).nullable().optional(), + valuePath: z.string().trim().max(200).nullable().optional(), + valueOp: z.enum(VALUE_OPS).nullable().optional(), + valueExpected: z.string().max(200).nullable().optional(), + valueUnit: z.string().trim().max(12).nullable().optional(), + headerName: z.string().trim().max(100).nullable().optional(), + /** Left out or blank on an edit keeps the one already saved. */ + headerValue: z.string().max(2000).nullable().optional(), insecure: z.boolean().optional(), intervalMinutes: z.number().int().min(1).max(1440).optional(), timeoutSeconds: z.number().int().min(1).max(60).optional(), @@ -43,14 +63,17 @@ const checkSchema = z } if (!ok) ctx.addIssue({ code: "custom", path: ["target"], message: "A web check needs an address that starts with http:// or https://." }); if (v.expectStatus && !isStatusSpec(v.expectStatus)) ctx.addIssue({ code: "custom", path: ["expectStatus"], message: "Use status codes like 200, or ranges like 200-299, separated by commas." }); + const problem = valueProblem(blank(v.valuePath), v.valueOp ?? null, blank(v.valueExpected)); + if (problem) ctx.addIssue({ code: "custom", path: ["valuePath"], message: problem }); + const name = blank(v.headerName); + if (name && !/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(name)) ctx.addIssue({ code: "custom", path: ["headerName"], message: "A header name is letters, digits and dashes, like Authorization." }); + if (name && /^(host|content-length|transfer-encoding|connection)$/i.test(name)) ctx.addIssue({ code: "custom", path: ["headerName"], message: `${name} is set by the app and can't be changed.` }); } else { if (v.port == null) ctx.addIssue({ code: "custom", path: ["port"], message: v.kind === "tcp" ? "A port check needs a port." : "A certificate check needs a port (usually 443)." }); if (/[/\s]/.test(v.target)) ctx.addIssue({ code: "custom", path: ["target"], message: "Give just the host name or address, without http:// or a path." }); } }); -/** A blank text field is no value. */ -const blank = (v: string | null | undefined) => (v === undefined || v === null || v.trim() === "" ? null : v.trim()); // Everyone signed in can see how things are doing, like the pages the same information appears on. endpointsRouter.get("/", asyncHandler(async (_req, res) => { @@ -58,7 +81,7 @@ endpointsRouter.get("/", asyncHandler(async (_req, res) => { const stats = await loadStats(rows.map((r) => r.id)); const serverNames = new Map((await db.select({ id: servers.id, name: servers.name }).from(servers)).map((s) => [s.id, s.name])); res.json({ - checks: rows.map((r) => ({ ...r, server: r.serverId !== null && serverNames.has(r.serverId) ? { id: r.serverId, name: serverNames.get(r.serverId)! } : null, stats: stats.get(r.id) })), + checks: rows.map((r) => ({ ...publicCheck(r), server: r.serverId !== null && serverNames.has(r.serverId) ? { id: r.serverId, name: serverNames.get(r.serverId)! } : null, stats: stats.get(r.id) })), servers: [...serverNames].map(([id, name]) => ({ id, name })).sort((a, b) => a.name.localeCompare(b.name)), }); })); @@ -74,8 +97,19 @@ endpointsRouter.get("/:id/history", asyncHandler(async (req, res) => { res.json({ check, ...(await getEndpointHistory(id, days)) }); })); -function valuesOf(d: z.infer) { +function valuesOf(d: z.infer, before?: CheckRow) { + const http = d.kind === "http"; + const hasValue = http && !!blank(d.valuePath); + const headerName = http ? blank(d.headerName) : null; + // What is already saved stays unless a new value is given; clearing the name removes the header. + const headerValue = !headerName ? null : blank(d.headerValue) !== null ? sealSecret(d.headerValue!.trim()) : (before?.headerValue ?? null); return { + valuePath: hasValue ? blank(d.valuePath) : null, + valueOp: hasValue ? (d.valueOp ?? null) : null, + valueExpected: hasValue && d.valueOp !== "exists" ? blank(d.valueExpected) : null, + valueUnit: hasValue ? blank(d.valueUnit) : null, + headerName, + headerValue, name: d.name, kind: d.kind, target: d.target, @@ -142,15 +176,21 @@ endpointsRouter.post("/suggestions/restore", requireRole("admin"), asyncHandler( res.json(await loadSuggestions()); })); +/** A header named with nothing to send, and nothing saved to send either. */ +function v0HeaderMissing(d: z.infer, before?: CheckRow): boolean { + return d.kind === "http" && !!blank(d.headerName) && blank(d.headerValue) === null && !before?.headerValue; +} + // Asking things on the network is an administrator's to set up. endpointsRouter.post("/",requireRole("admin"), asyncHandler(async (req, res) => { const parsed = checkSchema.safeParse(req.body); if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: parsed.error.issues[0]?.message ?? "That isn't a check.", details: parsed.error.flatten() }); + if (v0HeaderMissing(parsed.data)) return res.status(400).json({ error: "invalid_body", message: "Give the header a value." }); if ((await db.select({ id: endpointChecks.id }).from(endpointChecks)).length >= MAX_CHECKS) return res.status(409).json({ error: "too_many", message: `At most ${MAX_CHECKS} checks.` }); if (!(await serverExists(parsed.data.serverId))) return res.status(400).json({ error: "unknown_server", message: "That server doesn't exist." }); const [row] = await db.insert(endpointChecks).values(valuesOf(parsed.data)).returning(); await recordAudit({ actor: req.currentUser!, category: "endpoint", action: "create", targetType: "endpoint", targetId: row.id, detail: { name: row.name, kind: row.kind, target: row.target } }); - res.status(201).json({ check: row }); + res.status(201).json({ check: publicCheck(row) }); })); endpointsRouter.put("/:id", requireRole("admin"), asyncHandler(async (req, res) => { @@ -160,13 +200,15 @@ endpointsRouter.put("/:id", requireRole("admin"), asyncHandler(async (req, res) const [before] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, id)).limit(1); if (!before) return res.status(404).json({ error: "not_found" }); if (!(await serverExists(parsed.data.serverId))) return res.status(400).json({ error: "unknown_server", message: "That server doesn't exist." }); - const v = valuesOf(parsed.data); + if (v0HeaderMissing(parsed.data, before)) return res.status(400).json({ error: "invalid_body", message: "Give the header a value." }); + const v = valuesOf(parsed.data, before); // What is asked changed, so what was last found out about it no longer stands. - const reset = v.kind !== before.kind || v.target !== before.target || v.port !== before.port ? { lastCheckedAt: null, lastOk: null, lastMessage: null, lastResponseMs: null, certExpiresAt: null, consecutiveFailures: 0 } : {}; + const changed = v.kind !== before.kind || v.target !== before.target || v.port !== before.port || v.valuePath !== before.valuePath || v.valueOp !== before.valueOp || v.valueExpected !== before.valueExpected || v.headerName !== before.headerName; + const reset = changed ? { lastCheckedAt: null, lastOk: null, lastMessage: null, lastResponseMs: null, lastValue: null, certExpiresAt: null, consecutiveFailures: 0 } : {}; const [row] = await db.update(endpointChecks).set({ ...v, ...reset }).where(eq(endpointChecks.id, id)).returning(); await recordAudit({ actor: req.currentUser!, category: "endpoint", action: "update", targetType: "endpoint", targetId: id, detail: { name: row.name, kind: row.kind, target: row.target } }); invalidateAlertsCache(); - res.json({ check: row }); + res.json({ check: publicCheck(row) }); })); endpointsRouter.delete("/:id", requireRole("admin"), asyncHandler(async (req, res) => { diff --git a/server/src/services/endpointChecks.ts b/server/src/services/endpointChecks.ts index 970a997..bdc58e9 100644 --- a/server/src/services/endpointChecks.ts +++ b/server/src/services/endpointChecks.ts @@ -3,6 +3,9 @@ * went — answer time, uptime, when the certificate runs out. A check that keeps failing becomes an alert (and a notification), and so does a * certificate that is about to expire. This is for the simple "is it up?" that doesn't need a monitoring server of its own. * + * A web check can also judge a value in a JSON answer (services/valueCheck.ts): the power is under 5 000 W, the player's state is "playing", the query + * returned a number. The value read is remembered with each result, so it can be charted. + * * What is asked is typed in by an administrator, so it can't be just anything: loopback, link-local (cloud metadata) and similar addresses * are refused, and the connection goes to the one address that passed the check rather than to the name again (utils/networkGuard.ts). * LAN and public hosts are fine; that is what these are for. @@ -18,6 +21,8 @@ import { endpointChecks, endpointDaily, endpointHourly, endpointResults } from " import { getInternalFlag, setInternalFlag } from "./settingsStore.js"; import { noteRenewal } from "./renewals.js"; import { resolveTarget } from "../utils/networkGuard.js"; +import { openSecret } from "./sealed.js"; +import { isValueOp, judgeValue, readPath, type ValueOp } from "./valueCheck.js"; export const CHECK_KINDS = ["http", "tcp", "tls"] as const; export type CheckKind = (typeof CHECK_KINDS)[number]; @@ -30,6 +35,9 @@ export interface ProbeResult { message: string; /** ISO — when the certificate it showed runs out (https and tls checks). */ certExpiresAt?: string | null; + /** What was read from the answer, as text, for a check that judges a value; the number, when it is one. */ + value?: string | null; + valueNumber?: number | null; } export const KEEP_RESULT_DAYS = 14; @@ -78,10 +86,12 @@ interface OnceResult { status: number; location: string | null; body: string; + /** The answer reached the most that is read, so what is here may be only the start of it. */ + truncated: boolean; cert: string | null; } -function requestOnce(url: URL, address: string, insecure: boolean, timeoutMs: number, wantBody: boolean): Promise { +function requestOnce(url: URL, address: string, insecure: boolean, timeoutMs: number, wantBody: boolean, extraHeaders: Record = {}): Promise { const family = net.isIP(address) === 6 ? 6 : 4; return new Promise((resolve, reject) => { const isHttps = url.protocol === "https:"; @@ -92,7 +102,7 @@ function requestOnce(url: URL, address: string, insecure: boolean, timeoutMs: nu port: url.port ? Number(url.port) : isHttps ? 443 : 80, method: "GET", path: `${url.pathname}${url.search}`, - headers: { "user-agent": "HomelabManager-endpoint-check", accept: "*/*", host: url.host }, + headers: { "user-agent": "HomelabManager-endpoint-check", accept: "*/*", ...extraHeaders, host: url.host }, // Connect to the address that passed the check, not to the name again. lookup: ((_host: string, options: { all?: boolean }, cb: (...args: unknown[]) => void) => (options?.all ? cb(null, [{ address, family }]) : cb(null, address, family))) as never, timeout: timeoutMs, @@ -102,7 +112,7 @@ function requestOnce(url: URL, address: string, insecure: boolean, timeoutMs: nu const cert = isHttps ? certExpiry(res.socket) : null; const chunks: Buffer[] = []; let size = 0; - const finish = () => resolve({ status: res.statusCode ?? 0, location: typeof res.headers.location === "string" ? res.headers.location : null, body: Buffer.concat(chunks).toString("utf8"), cert }); + const finish = () => resolve({ status: res.statusCode ?? 0, location: typeof res.headers.location === "string" ? res.headers.location : null, body: Buffer.concat(chunks).toString("utf8"), truncated: size >= MAX_BODY_BYTES, cert }); if (!wantBody) { res.resume(); res.on("end", finish); @@ -138,6 +148,15 @@ async function probeHttp(c: CheckRow): Promise { } catch { return { ok: false, ms: null, message: "The address isn't a web address (it should start with http:// or https://)." }; } + // A header the person set (a token for an API) goes to the address they gave, and to nowhere a redirect leads to on another host. + let header: Record = {}; + if (c.headerName) { + const value = openSecret(c.headerValue); + if (value === null) return { ok: false, ms: null, message: `The value of the ${c.headerName} header can't be read — enter it again.` }; + header = { [c.headerName]: value }; + } + const origin = url.origin; + const wantBody = !!c.keyword || !!c.valuePath; let cert: string | null = null; for (let hops = 0; ; hops++) { const left = timeoutMs - (performance.now() - started); @@ -145,7 +164,7 @@ async function probeHttp(c: CheckRow): Promise { let once: OnceResult; try { const address = await resolveTarget(url.hostname.replace(/^\[|\]$/g, ""), { allowPrivate: true }); - once = await requestOnce(url, address, c.insecure, left, !!c.keyword); + once = await requestOnce(url, address, c.insecure, left, wantBody, url.origin === origin ? header : {}); } catch (err) { const e = err as NodeJS.ErrnoException; const text = err instanceof Error ? err.message : String(err); @@ -153,18 +172,32 @@ async function probeHttp(c: CheckRow): Promise { return { ok: false, ms: null, message: trust ? trustProblem(e.code, text) : text, certExpiresAt: cert }; } cert = once.cert ?? cert; - // Redirects are only followed when there is a keyword to look for in the page they lead to; otherwise a redirect is an answer. - if (c.keyword && [301, 302, 303, 307, 308].includes(once.status) && once.location && hops < MAX_REDIRECTS) { + // Redirects are only followed when there is something to look for in the page they lead to; otherwise a redirect is an answer. + if (wantBody && [301, 302, 303, 307, 308].includes(once.status) && once.location && hops < MAX_REDIRECTS) { url = new URL(once.location, url); continue; } const ms = Math.round(performance.now() - started); if (!accepts(once.status)) return { ok: false, ms, message: `answered ${once.status}`, certExpiresAt: cert }; if (c.keyword && !once.body.includes(c.keyword)) return { ok: false, ms, message: `answered ${once.status}, but the page doesn't contain “${c.keyword}”`, certExpiresAt: cert }; + if (c.valuePath && c.valueOp && isValueOp(c.valueOp)) return judgeAnswer(c, c.valuePath, c.valueOp, once.body, once.truncated, ms, cert); return { ok: true, ms, message: `answered ${once.status} in ${ms} ms`, certExpiresAt: cert }; } } +/** The answer, read as JSON, and the value in it judged. */ +function judgeAnswer(c: CheckRow, path: string, op: ValueOp, body: string, truncated: boolean, ms: number, cert: string | null): ProbeResult { + if (truncated) return { ok: false, ms, message: `the answer is more than ${MAX_BODY_BYTES / 1024} KB, which is more than is read`, certExpiresAt: cert }; + let json: unknown; + try { + json = JSON.parse(body); + } catch { + return { ok: false, ms, message: "the answer isn't JSON", certExpiresAt: cert }; + } + const v = judgeValue(readPath(json, path), path, op, c.valueExpected, c.valueUnit); + return { ok: v.ok, ms, message: v.message, certExpiresAt: cert, value: v.shown === "" ? null : v.shown, valueNumber: v.number }; +} + async function probeTcp(c: CheckRow): Promise { const started = performance.now(); let address: string; @@ -240,12 +273,14 @@ export async function runCheck(c: CheckRow, now: Date = new Date(), probeFn: (c: lastOk: result.ok, lastMessage: result.message.slice(0, 300), lastResponseMs: result.ms, + // A check that judges a value remembers what it read; one that couldn't reach the answer keeps the last it did read. + lastValue: c.valuePath ? (result.value === undefined ? c.lastValue : result.value) : null, certExpiresAt: result.certExpiresAt === undefined ? c.certExpiresAt : result.certExpiresAt, consecutiveFailures: result.ok ? 0 : c.consecutiveFailures + 1, lastChangeAt: flipped ? iso : c.lastChangeAt, }) .where(eq(endpointChecks.id, c.id)); - await db.insert(endpointResults).values({ checkId: c.id, at: iso, ok: result.ok, ms: result.ms, message: result.message.slice(0, 300) }); + await db.insert(endpointResults).values({ checkId: c.id, at: iso, ok: result.ok, ms: result.ms, message: result.message.slice(0, 300), value: result.valueNumber ?? null }); await addToDaily(c.id, iso, result); await addToHourly(c.id, iso, result); // A certificate that is now good for much longer than it was has been renewed. @@ -387,8 +422,39 @@ export function bucketHistory(rows: HistoryRow[], from: number, to: number, maxP })); } +/** A stretch of the values a check read: the average, with the lowest and highest in it. */ +export interface ValuePoint { + /** ISO. */ + t: string; + v: number; + lo: number; + hi: number; +} + +/** Pure: readings into at most `maxPoints` equal slices of [from, to], each as its average with its lowest and highest. */ +export function bucketValues(rows: { t: number; v: number }[], from: number, to: number, maxPoints: number): ValuePoint[] { + if (rows.length === 0 || to <= from) return []; + const size = Math.max((to - from) / maxPoints, 1); + const buckets = new Map(); + for (const r of rows) { + if (r.t < from || r.t > to) continue; + const key = Math.min(maxPoints - 1, Math.floor((r.t - from) / size)); + const b = buckets.get(key) ?? { sum: 0, n: 0, lo: r.v, hi: r.v, tSum: 0 }; + b.sum += r.v; + b.n += 1; + b.lo = Math.min(b.lo, r.v); + b.hi = Math.max(b.hi, r.v); + b.tSum += r.t; + buckets.set(key, b); + } + const round = (n: number) => Math.round(n * 1000) / 1000; + return [...buckets.entries()].sort((a, b) => a[0] - b[0]).map(([, b]) => ({ t: new Date(b.tSum / b.n).toISOString(), v: round(b.sum / b.n), lo: round(b.lo), hi: round(b.hi) })); +} + export interface EndpointHistory { days: number; + /** The numbers a value check read, as far back as the results are kept (14 days); null for a check that reads none. */ + values: { unit: string | null; days: number; points: ValuePoint[]; latest: number | null; lowest: number | null; highest: number | null } | null; /** Which figures it was drawn from: the results themselves (a day or two), the hourly figures, or the daily ones. */ source: "results" | "hourly" | "daily"; points: HistoryPoint[]; @@ -428,8 +494,28 @@ export async function getEndpointHistory(checkId: number, days: number, now: Dat const checks = rows.reduce((n, r) => n + r.total, 0); const okCount = rows.reduce((n, r) => n + r.ok, 0); const msCount = rows.reduce((n, r) => n + r.msCount, 0); + const valueFrom = Math.max(from, to - KEEP_RESULT_DAYS * 86_400_000); + const read = await db + .select({ at: endpointResults.at, value: endpointResults.value }) + .from(endpointResults) + .where(and(eq(endpointResults.checkId, checkId), gte(endpointResults.at, new Date(valueFrom).toISOString()), sql`${endpointResults.value} IS NOT NULL`)) + .orderBy(asc(endpointResults.at)); + let values: EndpointHistory["values"] = null; + if (read.length > 0) { + const [c] = await db.select({ unit: endpointChecks.valueUnit }).from(endpointChecks).where(eq(endpointChecks.id, checkId)).limit(1); + const nums = read.map((r) => r.value as number); + values = { + unit: c?.unit ?? null, + days: Math.min(days, KEEP_RESULT_DAYS), + points: bucketValues(read.map((r) => ({ t: Date.parse(r.at), v: r.value as number })), valueFrom, to, 200), + latest: nums[nums.length - 1], + lowest: Math.min(...nums), + highest: Math.max(...nums), + }; + } return { days, + values, source, points: bucketHistory(rows, from, to, days <= 2 ? 96 : days <= KEEP_HOURLY_DAYS ? 200 : 370), availability: checks === 0 ? null : Math.round((okCount / checks) * 1000) / 10, @@ -503,7 +589,9 @@ export function endpointConditions(rows: CheckRow[], now: Date): EndpointConditi const left = c.certExpiresAt ? daysLeft(c.certExpiresAt, now) : null; const certGone = left !== null && left < 0; if (c.lastOk === false && c.consecutiveFailures >= c.failuresBeforeAlert && !(c.kind === "tls" && certGone)) { - out.push({ key: `endpoint:${c.id}${suffix}`, source: "endpoint", category: "monitoring", severity: "critical", checkId: c.id, serverId: c.serverId, message: `${c.name} isn't answering — ${c.lastMessage ?? "no answer"}` }); + // A check of a value says what is wrong with it; "isn't answering" would be untrue of one that answered, but not as it should. + const message = c.valuePath ? `${c.name} — ${c.lastMessage ?? "no answer"}` : `${c.name} isn't answering — ${c.lastMessage ?? "no answer"}`; + out.push({ key: `endpoint:${c.id}${suffix}`, source: "endpoint", category: "monitoring", severity: "critical", checkId: c.id, serverId: c.serverId, message }); } if (c.certExpiresAt && left !== null && left <= c.warnDays) { out.push({ diff --git a/server/src/services/eventWebhooks.ts b/server/src/services/eventWebhooks.ts index 8228b17..aea5127 100644 --- a/server/src/services/eventWebhooks.ts +++ b/server/src/services/eventWebhooks.ts @@ -14,30 +14,15 @@ import { createHmac, randomUUID } from "node:crypto"; import { and, desc, eq, lt, notInArray } from "drizzle-orm"; import { db } from "../db/client.js"; import { eventWebhooks, webhookDeliveries, webhookEvents, type WebhookEvent } from "../db/schema.js"; -import { decryptSecret, encryptSecret } from "../crypto.js"; -import { env } from "../env.js"; +import { openSecret, sealSecret } from "./sealed.js"; + +export { sealSecret }; export type EventWebhookRow = typeof eventWebhooks.$inferSelect; -const ENCRYPTED_PREFIX = "enc:v1:"; const TIMEOUT_MS = 5000; const RETRY_AFTER_MS = 2000; -/** The stored form of a secret: encrypted when an encryption key is set, as the notification channels' secrets are. */ -export function sealSecret(plain: string): string { - return env.credentialsEncryptionEnabled ? ENCRYPTED_PREFIX + encryptSecret(plain) : plain; -} - -function openSecret(stored: string | null): string | null { - if (!stored) return null; - if (!stored.startsWith(ENCRYPTED_PREFIX)) return stored; - try { - return decryptSecret(stored.slice(ENCRYPTED_PREFIX.length)); - } catch { - return null; - } -} - export function parseEvents(stored: string): WebhookEvent[] { try { const v = JSON.parse(stored); diff --git a/server/src/services/metrics.ts b/server/src/services/metrics.ts index 653079c..f792175 100644 --- a/server/src/services/metrics.ts +++ b/server/src/services/metrics.ts @@ -62,6 +62,7 @@ async function addEndpointMetrics(out: Exposition, now: Date) { if (!c.enabled || c.lastOk === null) continue; const labels = { name: c.name, kind: c.kind }; out.add("homelab_endpoint_up", "gauge", "1 if the endpoint check's last answer was fine, else 0.", c.lastOk ? 1 : 0, labels); + if (c.valuePath && c.lastValue !== null && c.lastValue.trim() !== "" && Number.isFinite(Number(c.lastValue))) out.add("homelab_endpoint_value", "gauge", "The number a value check last read from the endpoint's answer.", Number(c.lastValue), labels); if (c.lastResponseMs !== null) out.add("homelab_endpoint_response_milliseconds", "gauge", "How long the endpoint took to answer the last time.", c.lastResponseMs, labels); if (c.certExpiresAt) out.add("homelab_endpoint_certificate_days_left", "gauge", "Days until the certificate the endpoint shows expires (negative once it has).", Math.floor((Date.parse(c.certExpiresAt) - now.getTime()) / 86_400_000), labels); } diff --git a/server/src/services/publicApi.ts b/server/src/services/publicApi.ts index d613cd4..94c8378 100644 --- a/server/src/services/publicApi.ts +++ b/server/src/services/publicApi.ts @@ -159,6 +159,7 @@ export async function endpointsV1(now: Date = new Date()) { lastCheckedAt: r.lastCheckedAt, lastResponseMs: r.lastResponseMs, lastMessage: r.lastOk === false ? r.lastMessage : null, + value: r.valuePath ? { path: r.valuePath, operator: r.valueOp, expected: r.valueExpected, unit: r.valueUnit, last: r.lastValue } : null, certificateExpiresAt: r.certExpiresAt, uptime24hPercent: st?.uptime24h ?? null, uptime7dPercent: st?.uptime7d ?? null, diff --git a/server/src/services/sealed.ts b/server/src/services/sealed.ts new file mode 100644 index 0000000..6ed8beb --- /dev/null +++ b/server/src/services/sealed.ts @@ -0,0 +1,24 @@ +/** + * A secret kept in the database: encrypted when an encryption key is set (as the notification channels' secrets are), plain otherwise. The webhooks' signing + * secrets and the header an endpoint check sends use it. + */ +import { decryptSecret, encryptSecret } from "../crypto.js"; +import { env } from "../env.js"; + +const ENCRYPTED_PREFIX = "enc:v1:"; + +/** The stored form of a secret. */ +export function sealSecret(plain: string): string { + return env.credentialsEncryptionEnabled ? ENCRYPTED_PREFIX + encryptSecret(plain) : plain; +} + +/** What was stored, as it was given; null when there is none or it can no longer be decrypted. */ +export function openSecret(stored: string | null): string | null { + if (!stored) return null; + if (!stored.startsWith(ENCRYPTED_PREFIX)) return stored; + try { + return decryptSecret(stored.slice(ENCRYPTED_PREFIX.length)); + } catch { + return null; + } +} diff --git a/server/src/services/valueCheck.ts b/server/src/services/valueCheck.ts new file mode 100644 index 0000000..d2a2dcf --- /dev/null +++ b/server/src/services/valueCheck.ts @@ -0,0 +1,140 @@ +/** + * Judging a value in an answer: "the power is under 5 000 W", "the status is playing", "the Prometheus query returned something". The answer is JSON; a path says + * where the value is in it, and one comparison says whether it is fine. Everything here is pure — the asking is in endpointChecks.ts. + * + * A path is the dots and brackets people already write: `power.now`, `data.result[0].value[1]`, `items[2].name`, and `["a.b"]` for a name with a dot in it. + * A leading `$.` is allowed and means nothing. + */ + +export const VALUE_OPS = ["<", "<=", ">", ">=", "=", "!=", "contains", "exists"] as const; +export type ValueOp = (typeof VALUE_OPS)[number]; + +const NUMERIC_OPS: readonly ValueOp[] = ["<", "<=", ">", ">="]; + +export const isValueOp = (op: string): op is ValueOp => (VALUE_OPS as readonly string[]).includes(op); + +type Step = string | number; + +/** A path into its steps, or null when it can't be read. */ +export function parsePath(path: string): Step[] | null { + let p = path.trim(); + if (p.startsWith("$")) p = p.slice(1); + if (p.startsWith(".")) p = p.slice(1); + const steps: Step[] = []; + let i = 0; + while (i < p.length) { + const c = p[i]; + if (c === ".") { + i++; + if (i >= p.length || p[i] === "." || p[i] === "[") return null; + } else if (c === "[") { + const close = p.indexOf("]", i); + if (close < 0) return null; + const inner = p.slice(i + 1, close).trim(); + i = close + 1; + if (/^\d+$/.test(inner)) steps.push(Number(inner)); + else if (/^(".*"|'.*')$/.test(inner) && inner.length >= 2) steps.push(inner.slice(1, -1)); + else return null; + } else { + const m = /^[^.[\]]+/.exec(p.slice(i)); + if (!m) return null; + steps.push(m[0]); + i += m[0].length; + } + } + return steps.length > 0 ? steps : null; +} + +export const isValuePath = (path: string) => parsePath(path) !== null; + +export type Read = { found: true; value: unknown } | { found: false; at: string }; + +/** What is at a path in a parsed answer. `at` says how far it got when it isn't there. */ +export function readPath(json: unknown, path: string): Read { + const steps = parsePath(path); + if (!steps) return { found: false, at: path }; + let here: unknown = json; + const walked: string[] = []; + for (const step of steps) { + walked.push(typeof step === "number" ? `[${step}]` : walked.length === 0 ? step : `.${step}`); + if (typeof step === "number") { + if (!Array.isArray(here) || step >= here.length) return { found: false, at: walked.join("") }; + here = here[step]; + } else { + if (here === null || typeof here !== "object" || Array.isArray(here) || !Object.prototype.hasOwnProperty.call(here, step)) return { found: false, at: walked.join("") }; + here = (here as Record)[step]; + } + } + return { found: true, value: here }; +} + +/** A value as a number when it is one, or text that is one ("12.5": Prometheus gives its numbers as text); otherwise null. */ +export function asNumber(value: unknown): number | null { + if (typeof value === "number") return Number.isFinite(value) ? value : null; + if (typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value))) return Number(value); + return null; +} + +/** A value as text, short enough to keep and show. */ +export function showValue(value: unknown): string { + const text = typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" || value === null ? String(value) : JSON.stringify(value); + return text.length > 120 ? `${text.slice(0, 117)}…` : text; +} + +export interface Verdict { + ok: boolean; + /** What was read, as text, to show and to remember. */ + shown: string; + /** The number, when it is one. */ + number: number | null; + message: string; +} + +const WORDS: Record = { "<": "below", "<=": "at most", ">": "above", ">=": "at least", "=": "equal to", "!=": "anything but", contains: "containing", exists: "there" }; + +/** How a limit reads: "below 5000 W". */ +export function describeLimit(op: ValueOp, expected: string | null, unit: string | null): string { + if (op === "exists") return "there"; + const n = asNumber(expected); + const quoted = NUMERIC_OPS.includes(op) || n !== null ? String(expected) : `“${expected}”`; + return `${WORDS[op]} ${quoted}${unit && (NUMERIC_OPS.includes(op) || n !== null) ? ` ${unit}` : ""}`; +} + +/** Whether what was read meets the limit, and what to say about it. `read` is what readPath found. */ +export function judgeValue(read: Read, path: string, op: ValueOp, expected: string | null, unit: string | null): Verdict { + if (!read.found) { + // "exists" is satisfied by the value being there, so its absence is the thing to say; the others cannot be judged without it. + return { ok: false, shown: "", number: null, message: `there is no “${path}” in the answer (it stops at ${read.at})` }; + } + const number = asNumber(read.value); + const shown = showValue(read.value); + const withUnit = number !== null && unit ? `${shown} ${unit}` : shown; + const limit = describeLimit(op, expected, unit); + if (op === "exists") return { ok: true, shown, number, message: `${path} is ${withUnit}` }; + let ok: boolean; + if (NUMERIC_OPS.includes(op)) { + const want = asNumber(expected); + if (number === null) return { ok: false, shown, number, message: `${path} is “${shown}”, which isn't a number, so it can't be compared with ${expected}` }; + if (want === null) return { ok: false, shown, number, message: `the limit “${expected}” isn't a number` }; + ok = op === "<" ? number < want : op === "<=" ? number <= want : op === ">" ? number > want : number >= want; + } else if (op === "contains") { + ok = shown.includes(expected ?? ""); + } else { + // Numbers are equal as numbers ("5" and 5.0), anything else as the same text. + const want = asNumber(expected); + const same = number !== null && want !== null ? number === want : shown === (expected ?? ""); + ok = op === "=" ? same : !same; + } + return { ok, shown, number, message: ok ? `${path} is ${withUnit} (should be ${limit})` : `${path} is ${withUnit}, but should be ${limit}` }; +} + +/** Whether a saved check's value settings make sense together: the reason why not, or null. */ +export function valueProblem(path: string | null, op: string | null, expected: string | null): string | null { + if (!path && !op && !expected) return null; + if (!path) return "Say where in the answer the value is, e.g. data.result[0].value[1]."; + if (!isValuePath(path)) return "That isn't a path I can read. Use names separated by dots, and [0] for a place in a list, like data.result[0].value[1]."; + if (!op || !isValueOp(op)) return "Say how the value should compare."; + if (op !== "exists" && (expected === null || expected.trim() === "")) return "Say what to compare it with."; + if (NUMERIC_OPS.includes(op) && asNumber(expected) === null) return "A limit to be above or below has to be a number."; + return null; +} diff --git a/server/test/valueChecks.test.ts b/server/test/valueChecks.test.ts new file mode 100644 index 0000000..176c076 --- /dev/null +++ b/server/test/valueChecks.test.ts @@ -0,0 +1,354 @@ +/** + * Checking a value in an answer: reading a path out of JSON, judging the value against a limit, asking a local server with and without a header, what is + * remembered and charted, and the routes that keep a header's value to themselves. + * + * Run with: npm test --workspace server + */ +import { test, describe, before, after } from "node:test"; +import assert from "node:assert/strict"; +import { createServer as createHttpServer, type IncomingMessage, type Server } from "node:http"; +import { mkdtempSync, rmSync } from "node:fs"; +import { networkInterfaces, tmpdir } from "node:os"; +import { join } from "node:path"; +import type { AddressInfo } from "node:net"; + +const dir = mkdtempSync(join(tmpdir(), "hm-values-")); +process.env.DATABASE_PATH = join(dir, "test.sqlite"); +process.env.SESSION_DIR = join(dir, "sessions"); +process.env.CREDENTIALS_ENCRYPTION_KEY = "ab".repeat(32); +process.env.HEALTH_STARTUP_GRACE_MS = "0"; + +const express = (await import("express")).default; +const { db } = await import("../src/db/client.js"); +const { users, endpointChecks, endpointResults } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const value = await import("../src/services/valueCheck.js"); +const { probe, runCheck, bucketValues, getEndpointHistory, endpointConditions } = await import("../src/services/endpointChecks.js"); +const { endpointsRouter } = await import("../src/routes/endpoints.js"); +const { buildMetrics } = await import("../src/services/metrics.js"); +const { endpointsV1 } = await import("../src/services/publicApi.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); + +describe("where a value is", () => { + test("dots, brackets, quoted names and a leading $", () => { + assert.deepEqual(value.parsePath("power.now"), ["power", "now"]); + assert.deepEqual(value.parsePath("data.result[0].value[1]"), ["data", "result", 0, "value", 1]); + assert.deepEqual(value.parsePath("$.items[2].name"), ["items", 2, "name"]); + assert.deepEqual(value.parsePath('["a.b"].c'), ["a.b", "c"]); + assert.deepEqual(value.parsePath("[0].x"), [0, "x"]); + for (const bad of ["", "a..b", "a.", "a[", "a[x]", "a[]", ".", "$"]) assert.equal(value.parsePath(bad), null, `"${bad}"`); + }); + + test("it reads what is there, and says how far it got when it isn't", () => { + const json = { power: { now: 120.5, unit: "W" }, data: { result: [{ value: [1700, "42.5"] }] }, "a.b": { c: true }, nothing: null, list: [] }; + assert.deepEqual(value.readPath(json, "power.now"), { found: true, value: 120.5 }); + assert.deepEqual(value.readPath(json, "data.result[0].value[1]"), { found: true, value: "42.5" }); + assert.deepEqual(value.readPath(json, '["a.b"].c'), { found: true, value: true }); + assert.deepEqual(value.readPath(json, "nothing"), { found: true, value: null }, "null is a value that is there"); + assert.deepEqual(value.readPath(json, "power.later"), { found: false, at: "power.later" }); + assert.deepEqual(value.readPath(json, "data.result[3]"), { found: false, at: "data.result[3]" }); + assert.deepEqual(value.readPath(json, "list[0]"), { found: false, at: "list[0]" }); + assert.deepEqual(value.readPath(json, "power.now.deeper"), { found: false, at: "power.now.deeper" }, "a number has nothing inside it"); + assert.equal(value.readPath(json, "toString").found, false, "nothing is inherited from the language"); + assert.equal(value.readPath([1, 2], "[1]").found, true); + }); + + test("numbers are numbers, and so is text that is one", () => { + assert.deepEqual([12, "12.5", " 7 ", "", "abc", null, true, Infinity].map(value.asNumber), [12, 12.5, 7, null, null, null, null, null]); + }); +}); + +describe("whether a value is fine", () => { + const read = (v: unknown) => ({ found: true as const, value: v }); + const j = (v: unknown, op: (typeof value.VALUE_OPS)[number], expected: string | null, unit: string | null = null) => value.judgeValue(read(v), "p", op, expected, unit); + + test("below, above and the edges", () => { + assert.equal(j(4999, "<", "5000").ok, true); + assert.equal(j(5000, "<", "5000").ok, false); + assert.equal(j(5000, "<=", "5000").ok, true); + assert.equal(j(5000, ">", "5000").ok, false); + assert.equal(j(5000, ">=", "5000").ok, true); + assert.equal(j("42.5", "<", "50").ok, true, "a number given as text, as Prometheus does"); + }); + + test("equal and not equal compare numbers as numbers and anything else as the same text", () => { + assert.equal(j(5, "=", "5.0").ok, true); + assert.equal(j("5", "=", "5").ok, true); + assert.equal(j("playing", "=", "playing").ok, true); + assert.equal(j("Playing", "=", "playing").ok, false, "case matters"); + assert.equal(j("idle", "!=", "error").ok, true); + assert.equal(j("error", "!=", "error").ok, false); + assert.equal(j(true, "=", "true").ok, true); + }); + + test("contains, and exists (being there is enough, even a null)", () => { + assert.equal(j("all systems go", "contains", "systems").ok, true); + assert.equal(j("all systems go", "contains", "fault").ok, false); + assert.equal(j(null, "exists", null).ok, true); + assert.equal(value.judgeValue({ found: false, at: "x.y" }, "x.y.z", "exists", null, null).ok, false); + }); + + test("it says what it found and what it wanted, with the unit when the value is a number", () => { + assert.equal(j(5200, "<", "5000", "W").message, "p is 5200 W, but should be below 5000 W"); + assert.equal(j(120, "<", "5000", "W").message, "p is 120 W (should be below 5000 W)"); + assert.equal(j("error", "=", "playing").message, "p is error, but should be equal to “playing”"); + assert.equal(j("x", "=", "playing", "W").message, "p is x, but should be equal to “playing”", "no unit on text"); + assert.match(j("hot", "<", "50").message, /“hot”, which isn't a number/); + assert.match(value.judgeValue({ found: false, at: "data" }, "data.x", "<", "5", null).message, /no “data.x” in the answer \(it stops at data\)/); + const long = j("x".repeat(500), "contains", "y"); + assert.ok(long.shown.length <= 120 && long.shown.endsWith("…"), "what is kept is short"); + assert.equal(j({ a: 1 }, "contains", "a").shown, '{"a":1}', "an object is shown as JSON"); + }); + + test("a saved setting is refused when it doesn't make sense, with the reason", () => { + assert.equal(value.valueProblem(null, null, null), null, "no value check at all is fine"); + assert.match(value.valueProblem(null, ">", "5")!, /where in the answer/); + assert.match(value.valueProblem("a..b", ">", "5")!, /path I can read/); + assert.match(value.valueProblem("a", null, "5")!, /how the value should compare/); + assert.match(value.valueProblem("a", ">", null)!, /compare it with/); + assert.match(value.valueProblem("a", ">", "lots")!, /has to be a number/); + assert.equal(value.valueProblem("a", "=", "playing"), null); + assert.equal(value.valueProblem("a", "exists", null), null, "exists needs nothing to compare with"); + }); +}); + +describe("the values over time", () => { + test("readings fall into slices as their average with the lowest and highest, and nothing outside the stretch", () => { + const H = 3_600_000; + const pts = bucketValues([{ t: 0, v: 10 }, { t: H, v: 20 }, { t: 2 * H, v: 30 }, { t: 3 * H, v: 50 }, { t: 99 * H, v: 999 }], 0, 4 * H, 2); + assert.deepEqual(pts.map((p) => [p.v, p.lo, p.hi]), [[15, 10, 20], [40, 30, 50]]); + assert.deepEqual(bucketValues([], 0, 10, 5), []); + }); +}); + +/** An address of this machine that isn't loopback (the checks refuse that), if it has one. */ +function lanAddress(): string | null { + for (const list of Object.values(networkInterfaces())) { + for (const i of list ?? []) if (i.family === "IPv4" && !i.internal && !i.address.startsWith("169.254.")) return i.address; + } + return null; +} +const LAN = lanAddress(); + +describe("asking for a value", { skip: LAN === null && "this machine has no address other than loopback" }, () => { + let web: Server; + let other: Server; + let port = 0; + let otherPort = 0; + let app: Server; + let base = ""; + let who = "admin"; + const seen: { url: string; auth: string | undefined }[] = []; + let power = 120; + + before(async () => { + await db.insert(users).values([ + { oidcSub: "admin", name: "Ada", role: "admin" }, + { oidcSub: "viewer", name: "Vic", role: "viewer" }, + ]); + web = createHttpServer((req: IncomingMessage, res) => { + seen.push({ url: req.url ?? "", auth: req.headers.authorization }); + const json = (o: unknown) => { + res.setHeader("content-type", "application/json"); + res.end(JSON.stringify(o)); + }; + if (req.url === "/power") return json({ power: { now: power }, state: "playing", data: { result: [{ value: [1700000000, "42.5"] }] } }); + if (req.url === "/secure") { + if (req.headers.authorization !== "Bearer s3cret") { + res.statusCode = 401; + return void res.end("no"); + } + return json({ ok: 1 }); + } + if (req.url === "/html") return void res.end("

hello

"); + if (req.url === "/big") return void res.end(`{"x":"${"y".repeat(100_000)}"}`); + if (req.url === "/hop") { + res.statusCode = 302; + res.setHeader("location", `http://${LAN}:${otherPort}/power`); + return void res.end(); + } + res.statusCode = 404; + res.end("no"); + }); + await new Promise((r) => web.listen(0, "0.0.0.0", r)); + port = (web.address() as AddressInfo).port; + other = createHttpServer((req, res) => { + seen.push({ url: `other${req.url}`, auth: req.headers.authorization }); + res.setHeader("content-type", "application/json"); + res.end(JSON.stringify({ power: { now: 1 } })); + }); + await new Promise((r) => other.listen(0, "0.0.0.0", r)); + otherPort = (other.address() as AddressInfo).port; + + const a = express(); + a.use(express.json()); + a.use((req, _res, next) => { + (req as unknown as { session: unknown }).session = { user: { sub: who } }; + next(); + }); + a.use("/api/endpoints", endpointsRouter); + app = await new Promise((resolve) => { + const s = a.listen(0, "127.0.0.1", () => resolve(s)); + }); + base = `http://127.0.0.1:${(app.address() as AddressInfo).port}/api/endpoints`; + }); + + after(() => { + web.close(); + other.close(); + app.close(); + try { + rmSync(dir, { recursive: true, force: true }); + } catch { + // Windows keeps the database file locked until the process exits. + } + }); + + type Row = typeof endpointChecks.$inferSelect; + const check = (path: string, extra: Partial = {}): Row => + ({ + id: 1, name: "Meter", kind: "http", target: `http://${LAN}:${port}${path}`, port: null, expectStatus: null, keyword: null, valuePath: null, valueOp: null, valueExpected: null, valueUnit: null, headerName: null, headerValue: null, lastValue: null, + insecure: false, intervalMinutes: 5, timeoutSeconds: 3, failuresBeforeAlert: 2, warnDays: 14, serverId: null, enabled: true, lastCheckedAt: null, lastOk: null, lastMessage: null, lastResponseMs: null, certExpiresAt: null, consecutiveFailures: 0, lastChangeAt: null, + createdAt: "2026-10-01 00:00:00", ...extra, + }) as Row; + + test("a value under its limit is fine, over it is not, and either way what was read comes back", async () => { + const fine = await probe(check("/power", { valuePath: "power.now", valueOp: "<", valueExpected: "5000", valueUnit: "W" })); + assert.deepEqual([fine.ok, fine.value, fine.valueNumber], [true, "120", 120]); + assert.equal(fine.message, "power.now is 120 W (should be below 5000 W)"); + const over = await probe(check("/power", { valuePath: "power.now", valueOp: "<", valueExpected: "100", valueUnit: "W" })); + assert.deepEqual([over.ok, over.value], [false, "120"]); + assert.equal(over.message, "power.now is 120 W, but should be below 100 W"); + assert.ok(over.ms !== null, "it did answer"); + }); + + test("text, and a number a query gives as text", async () => { + assert.equal((await probe(check("/power", { valuePath: "state", valueOp: "=", valueExpected: "playing" }))).ok, true); + const bad = await probe(check("/power", { valuePath: "state", valueOp: "=", valueExpected: "paused" })); + assert.deepEqual([bad.ok, bad.valueNumber], [false, null]); + const prom = await probe(check("/power", { valuePath: "data.result[0].value[1]", valueOp: ">", valueExpected: "40" })); + assert.deepEqual([prom.ok, prom.valueNumber], [true, 42.5]); + }); + + test("an answer that isn't JSON, a value that isn't there and a path that goes nowhere each say so", async () => { + assert.match((await probe(check("/html", { valuePath: "a", valueOp: "exists" }))).message, /isn't JSON/); + assert.match((await probe(check("/power", { valuePath: "power.gone", valueOp: "exists" }))).message, /no “power.gone” in the answer \(it stops at power.gone\)/); + assert.match((await probe(check("/big", { valuePath: "x", valueOp: "exists" }))).message, /more than 64 KB/); + const wrongStatus = await probe(check("/nope", { valuePath: "a", valueOp: "exists" })); + assert.match(wrongStatus.message, /answered 404/, "the status is judged before the value"); + }); + + test("a header goes with the request, and its value is read back from the sealed form", async () => { + const { sealSecret } = await import("../src/services/sealed.js"); + seen.length = 0; + const ok = await probe(check("/secure", { headerName: "Authorization", headerValue: sealSecret("Bearer s3cret") })); + assert.equal(ok.ok, true); + assert.equal(seen[0].auth, "Bearer s3cret"); + assert.equal((await probe(check("/secure"))).ok, false, "without it the service says no"); + const lost = await probe(check("/secure", { headerName: "Authorization", headerValue: "enc:v1:not-decryptable" })); + assert.match(lost.message, /can't be read — enter it again/); + }); + + test("the header is not sent on to another host a redirect leads to", async () => { + const { sealSecret } = await import("../src/services/sealed.js"); + seen.length = 0; + const r = await probe(check("/hop", { valuePath: "power.now", valueOp: "<", valueExpected: "5", headerName: "Authorization", headerValue: sealSecret("Bearer s3cret") })); + assert.equal(r.ok, true, "the redirect is followed to read the value"); + assert.deepEqual(seen.map((s) => [s.url, s.auth]), [["/hop", "Bearer s3cret"], ["other/power", undefined]]); + }); + + test("a run remembers the value on the check and with the result; one that can't reach it keeps the last it read", async () => { + const [row] = await db.insert(endpointChecks).values({ name: "Meter", kind: "http", target: `http://${LAN}:${port}/power`, valuePath: "power.now", valueOp: "<", valueExpected: "5000", valueUnit: "W" }).returning(); + await runCheck(row, new Date("2026-10-18T10:00:00Z")); + let [after1] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, row.id)); + assert.deepEqual([after1.lastOk, after1.lastValue], [true, "120"]); + power = 160; + await runCheck(after1, new Date("2026-10-18T10:05:00Z")); + const results = await db.select().from(endpointResults).where(eq(endpointResults.checkId, row.id)).orderBy(endpointResults.at); + assert.deepEqual(results.map((r) => r.value), [120, 160]); + [after1] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, row.id)); + await db.update(endpointChecks).set({ target: `http://${LAN}:1/never` }).where(eq(endpointChecks.id, row.id)); + const [gone] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, row.id)); + await runCheck(gone, new Date("2026-10-18T10:10:00Z")); + const [kept] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, row.id)); + assert.deepEqual([kept.lastOk, kept.lastValue], [false, "160"]); + power = 120; + }); + + test("a value that is off is an alert that says what is wrong with it, not that it isn't answering", async () => { + const list = endpointConditions([check("/power", { valuePath: "power.now", valueOp: "<", valueExpected: "100", lastOk: false, consecutiveFailures: 2, lastMessage: "power.now is 120, but should be below 100" }), check("/power", { id: 2, lastOk: false, consecutiveFailures: 2, lastMessage: "answered 500" })], new Date()); + assert.equal(list[0].message, "Meter — power.now is 120, but should be below 100"); + assert.equal(list[1].message, "Meter isn't answering — answered 500"); + }); + + test("the history carries the values, charted as far back as the results are kept", async () => { + const [row] = await db.select().from(endpointChecks).where(eq(endpointChecks.valuePath, "power.now")); + const h = await getEndpointHistory(row.id, 7, new Date("2026-10-18T12:00:00Z")); + assert.ok(h.values); + assert.deepEqual([h.values.unit, h.values.latest, h.values.lowest, h.values.highest], ["W", 160, 120, 160]); + assert.equal(h.values.days, 7); + assert.ok(h.values.points.length >= 1); + const plain = await db.insert(endpointChecks).values({ name: "Plain", kind: "http", target: "https://x/" }).returning(); + assert.equal((await getEndpointHistory(plain[0].id, 7)).values, null, "a check that reads no value has none"); + }); + + test("/metrics and the read API carry it", async () => { + const text = await buildMetrics(); + assert.match(text, /homelab_endpoint_value\{[^}]*name="Meter"[^}]*\} 160/); + const [api] = (await endpointsV1()).filter((e) => e.name === "Meter"); + assert.deepEqual(api.value, { path: "power.now", operator: "<", expected: "5000", unit: "W", last: "160" }); + }); + + const send = (method: string, path: string, body?: unknown) => fetch(`${base}${path}`, { method, headers: { "content-type": "application/json", connection: "close" }, body: body === undefined ? undefined : JSON.stringify(body) }); + + test("a value check is made over the API; a wrong one is refused with the reason; the header's value never comes back", async () => { + const good = { name: "Solar", kind: "http", target: "https://inverter.lan/status", valuePath: "pv.power", valueOp: ">", valueExpected: "10", valueUnit: "W", headerName: "Authorization", headerValue: "Bearer topsecret" }; + const res = await send("POST", "/", good); + assert.equal(res.status, 201); + const created = (await res.json()).check; + assert.deepEqual([created.valuePath, created.valueOp, created.valueExpected, created.headerName, created.hasHeader], ["pv.power", ">", "10", "Authorization", true]); + assert.equal(JSON.stringify(created).includes("topsecret"), false); + assert.equal(JSON.stringify(created).includes("headerValue"), false); + const [stored] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, created.id)); + assert.ok(stored.headerValue && !stored.headerValue.includes("topsecret"), "stored sealed"); + + const list = (await (await send("GET", "/")).json()) as { checks: Record[] }; + assert.equal(JSON.stringify(list).includes("topsecret"), false); + assert.ok(list.checks.every((c) => !("headerValue" in c))); + + for (const bad of [ + { ...good, valuePath: "a..b" }, + { ...good, valuePath: null }, + { ...good, valueOp: "~" }, + { ...good, valueExpected: "lots" }, + { ...good, valueExpected: null }, + { ...good, headerName: "Bad Name" }, + { ...good, headerName: "Host" }, + { name: "x", kind: "http", target: "https://a/", headerName: "Authorization" }, + ]) assert.equal((await send("POST", "/", bad)).status, 400, JSON.stringify(bad)); + who = "viewer"; + assert.equal((await send("POST", "/", good)).status, 403); + who = "admin"; + }); + + test("editing keeps the header's value unless a new one is given, and clearing the name removes it; changing what is asked forgets what was read", async () => { + const [c] = await db.select().from(endpointChecks).where(eq(endpointChecks.name, "Solar")); + await db.update(endpointChecks).set({ lastValue: "55", lastOk: true }).where(eq(endpointChecks.id, c.id)); + const same = { name: "Solar", kind: "http", target: "https://inverter.lan/status", valuePath: "pv.power", valueOp: ">", valueExpected: "10", valueUnit: "W", headerName: "Authorization" }; + assert.equal((await send("PUT", `/${c.id}`, same)).status, 200); + let [now] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, c.id)); + assert.equal(now.headerValue, c.headerValue, "kept"); + assert.equal(now.lastValue, "55", "nothing that matters changed, so what was read stands"); + await send("PUT", `/${c.id}`, { ...same, valueExpected: "20" }); + [now] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, c.id)); + assert.deepEqual([now.lastValue, now.lastOk], [null, null]); + await send("PUT", `/${c.id}`, { ...same, headerValue: "Bearer another" }); + const [replaced] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, c.id)); + assert.notEqual(replaced.headerValue, c.headerValue); + await send("PUT", `/${c.id}`, { ...same, headerName: null, valuePath: null, valueOp: null, valueExpected: null }); + const [cleared] = await db.select().from(endpointChecks).where(eq(endpointChecks.id, c.id)); + assert.deepEqual([cleared.headerName, cleared.headerValue, cleared.valuePath, cleared.valueOp], [null, null, null, null]); + }); +}); diff --git a/web/src/api/client.ts b/web/src/api/client.ts index 8f0887b..de18d47 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -943,6 +943,8 @@ export interface EndpointStats { avgMs24h: number | null; recent: { at: string; ok: boolean; ms: number | null }[]; } +export type EndpointValueOp = "<" | "<=" | ">" | ">=" | "=" | "!=" | "contains" | "exists"; + export interface EndpointCheck { id: number; name: string; @@ -951,6 +953,16 @@ export interface EndpointCheck { port: number | null; expectStatus: string | null; keyword: string | null; + /** A web check can judge a value in a JSON answer: where it is, how it must compare, and what to. */ + valuePath: string | null; + valueOp: EndpointValueOp | null; + valueExpected: string | null; + valueUnit: string | null; + /** A header sent with the request (its value is never sent back, only that there is one). */ + headerName: string | null; + hasHeader: boolean; + /** What was read the last time, as text. */ + lastValue: string | null; insecure: boolean; intervalMinutes: number; timeoutSeconds: number; @@ -972,6 +984,8 @@ export interface EndpointCheck { export interface EndpointHistory { check: { id: number; name: string }; days: number; + /** The numbers a value check read, as far back as the results are kept; null for a check that reads none. */ + values: { unit: string | null; days: number; points: { t: string; v: number; lo: number; hi: number }[]; latest: number | null; lowest: number | null; highest: number | null } | null; /** Which figures it is drawn from: each answer (a day or two), the hourly figures, or the daily ones. */ source: "results" | "hourly" | "daily"; points: { t: string; availability: number | null; avgMs: number | null; maxMs: number | null; checks: number }[]; @@ -998,6 +1012,13 @@ export interface EndpointInput { port?: number | null; expectStatus?: string | null; keyword?: string | null; + valuePath?: string | null; + valueOp?: EndpointValueOp | null; + valueExpected?: string | null; + valueUnit?: string | null; + headerName?: string | null; + /** Left out, an edit keeps the value already saved. */ + headerValue?: string | null; insecure?: boolean; intervalMinutes?: number; timeoutSeconds?: number; diff --git a/web/src/components/EndpointHistory.tsx b/web/src/components/EndpointHistory.tsx index 8c7ce84..e6d1e69 100644 --- a/web/src/components/EndpointHistory.tsx +++ b/web/src/components/EndpointHistory.tsx @@ -39,6 +39,10 @@ export default function EndpointHistory({ checkId, name, onClose }: { checkId: n const from = to - days * 86_400_000; const rangeLabel = CHART_RANGES.find((r) => r.days === days)?.label ?? `${days} days`; + const readings = useMemo( + () => [{ name: "Value", color: "#ae3ec9", points: (history?.values?.points ?? []).map((p) => ({ t: p.t, v: p.v, lo: p.lo, hi: p.hi })) }], + [history], + ); const availability = useMemo(() => [{ name: "Availability", color: "#2fb344", points: (history?.points ?? []).filter((p) => p.availability !== null).map((p) => ({ t: p.t, v: p.availability as number })) }], [history]); // The line is the average answer time; the band reaches up to the slowest. const answer = useMemo(() => [{ name: "Answer time", color: "#4299e1", points: (history?.points ?? []).filter((p) => p.avgMs !== null).map((p) => ({ t: p.t, v: p.avgMs as number, lo: p.avgMs as number, hi: (p.maxMs ?? p.avgMs) as number })) }], [history]); @@ -67,6 +71,20 @@ export default function EndpointHistory({ checkId, name, onClose }: { checkId: n + {history.values && ( + <> +

Value read{history.values.unit ? ` (${history.values.unit})` : ""}

+
+ Now {history.values.latest}, lowest {history.values.lowest}, highest {history.values.highest} + {history.values.unit ? ` ${history.values.unit}` : ""}. +
+
+ `${+v.toPrecision(4)}${history.values?.unit ? ` ${history.values.unit}` : ""}`} label={`${name}: the value read over the last ${Math.min(days, 14)} days`} empty="Nothing read in this stretch yet." /> + {days > 14 &&
Values are kept 14 days, so this reaches back no further.
} +
+ + )} +

Availability

(v >= 99.9 ? "#2fb344" : v >= 90 ? "#f59f00" : "#f03e3e")} empty="No checks in this stretch yet." /> diff --git a/web/src/pages/Endpoints.tsx b/web/src/pages/Endpoints.tsx index c3319ec..ea127ec 100644 --- a/web/src/pages/Endpoints.tsx +++ b/web/src/pages/Endpoints.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; -import { api, type CurrentUser, type EndpointCheck, type EndpointInput, type EndpointKind } from "../api/client"; +import { api, type CurrentUser, type EndpointCheck, type EndpointInput, type EndpointKind, type EndpointValueOp } from "../api/client"; import Pagination from "../components/Pagination"; import SortableTh from "../components/SortableTh"; import TableToolbar from "../components/TableToolbar"; @@ -20,7 +20,7 @@ import EndpointHistory from "../components/EndpointHistory"; const KIND_LABELS: Record = { http: "Web address", tcp: "Port", tls: "Certificate" }; const KIND_HINTS: Record = { - http: "Asks the address and wants a good answer (and, if you like, a word in the page).", + http: "Asks the address and wants a good answer (and, if you like, a word in the page, or a value in a JSON answer within its limits).", tcp: "Opens a connection to the port and sees whether anything answers.", tls: "Reads the certificate the service shows and warns before it runs out.", }; @@ -42,6 +42,19 @@ function stateOf(c: EndpointCheck): State { return c.consecutiveFailures >= c.failuresBeforeAlert ? "down" : "failing"; } +const OP_LABELS: Record = { "<": "is below", "<=": "is at most", ">": "is above", ">=": "is at least", "=": "is equal to", "!=": "is anything but", contains: "contains", exists: "is there" }; +const LIMIT_WORDS: Record = { "<": "below", "<=": "at most", ">": "above", ">=": "at least", "=": "equal to", "!=": "anything but", contains: "containing", exists: "there" }; +const NUMERIC = (op: EndpointValueOp) => op === "<" || op === "<=" || op === ">" || op === ">="; + +/** What a value check wants, in words: "power.now should be below 5000 W". */ +function limitWords(c: EndpointCheck): string { + if (!c.valuePath || !c.valueOp) return ""; + if (c.valueOp === "exists") return `${c.valuePath} should be there`; + if (c.valueOp === "contains") return `${c.valuePath} should contain “${c.valueExpected}”`; + const numeric = NUMERIC(c.valueOp) || (c.valueExpected !== null && c.valueExpected.trim() !== "" && Number.isFinite(Number(c.valueExpected))); + return `${c.valuePath} should be ${LIMIT_WORDS[c.valueOp]} ${numeric ? c.valueExpected : `“${c.valueExpected}”`}${numeric && c.valueUnit ? ` ${c.valueUnit}` : ""}`; +} + const daysLeft = (iso: string | null) => (iso ? Math.floor((Date.parse(iso) - Date.now()) / 86_400_000) : null); interface Row extends EndpointCheck { @@ -71,6 +84,14 @@ interface Draft { port: string; expectStatus: string; keyword: string; + valuePath: string; + valueOp: EndpointValueOp; + valueExpected: string; + valueUnit: string; + headerName: string; + headerValue: string; + /** A header is already saved with this check, so its value may be left blank to keep it. */ + hadHeader: boolean; insecure: boolean; intervalMinutes: string; timeoutSeconds: string; @@ -80,7 +101,7 @@ interface Draft { enabled: boolean; } -const EMPTY: Draft = { id: null, name: "", kind: "http", target: "", port: "", expectStatus: "", keyword: "", insecure: false, intervalMinutes: "5", timeoutSeconds: "10", failuresBeforeAlert: "2", warnDays: "14", serverId: "", enabled: true }; +const EMPTY: Draft = { id: null, name: "", kind: "http", target: "", port: "", expectStatus: "", keyword: "", valuePath: "", valueOp: "<", valueExpected: "", valueUnit: "", headerName: "", headerValue: "", hadHeader: false, insecure: false, intervalMinutes: "5", timeoutSeconds: "10", failuresBeforeAlert: "2", warnDays: "14", serverId: "", enabled: true }; const toDraft = (c: EndpointCheck): Draft => ({ id: c.id, @@ -90,6 +111,13 @@ const toDraft = (c: EndpointCheck): Draft => ({ port: c.port === null ? "" : String(c.port), expectStatus: c.expectStatus ?? "", keyword: c.keyword ?? "", + valuePath: c.valuePath ?? "", + valueOp: c.valueOp ?? "<", + valueExpected: c.valueExpected ?? "", + valueUnit: c.valueUnit ?? "", + headerName: c.headerName ?? "", + headerValue: "", + hadHeader: c.hasHeader, insecure: c.insecure, intervalMinutes: String(c.intervalMinutes), timeoutSeconds: String(c.timeoutSeconds), @@ -106,6 +134,12 @@ const toInput = (d: Draft): EndpointInput => ({ port: d.kind === "http" || d.port.trim() === "" ? null : Number(d.port), expectStatus: d.kind === "http" && d.expectStatus.trim() ? d.expectStatus.trim() : null, keyword: d.kind === "http" && d.keyword ? d.keyword : null, + valuePath: d.kind === "http" && d.valuePath.trim() ? d.valuePath.trim() : null, + valueOp: d.kind === "http" && d.valuePath.trim() ? d.valueOp : null, + valueExpected: d.kind === "http" && d.valuePath.trim() && d.valueOp !== "exists" ? d.valueExpected : null, + valueUnit: d.kind === "http" && d.valuePath.trim() && d.valueUnit.trim() ? d.valueUnit.trim() : null, + headerName: d.kind === "http" && d.headerName.trim() ? d.headerName.trim() : null, + headerValue: d.kind === "http" && d.headerName.trim() && d.headerValue ? d.headerValue : undefined, insecure: d.insecure, intervalMinutes: Number(d.intervalMinutes), timeoutSeconds: Number(d.timeoutSeconds), @@ -199,8 +233,8 @@ export default function Endpoints({ user }: { user: CurrentUser }) { function exportCsv() { downloadCsv( "endpoint-checks.csv", - ["Name", "Kind", "Target", "Port", "Status", "Last answer", "Answer time (ms)", "Uptime 24 h (%)", "Uptime 7 d (%)", "Certificate expires", "Last checked", "Server"], - (sorted ?? []).map((r) => [r.name, KIND_LABELS[r.kind], r.target, r.port ?? "", STATE_BADGE[r.state].label, r.lastMessage ?? "", r.lastResponseMs ?? "", r.stats?.uptime24h ?? "", r.stats?.uptime7d ?? "", r.certExpiresAt?.slice(0, 10) ?? "", r.lastCheckedAt ?? "", r.server?.name ?? ""]), + ["Name", "Kind", "Target", "Port", "Status", "Last answer", "Value read", "Answer time (ms)", "Uptime 24 h (%)", "Uptime 7 d (%)", "Certificate expires", "Last checked", "Server"], + (sorted ?? []).map((r) => [r.name, KIND_LABELS[r.kind], r.target, r.port ?? "", STATE_BADGE[r.state].label, r.lastMessage ?? "", r.lastValue ?? "", r.lastResponseMs ?? "", r.stats?.uptime24h ?? "", r.stats?.uptime7d ?? "", r.certExpiresAt?.slice(0, 10) ?? "", r.lastCheckedAt ?? "", r.server?.name ?? ""]), ); } @@ -319,6 +353,76 @@ export default function Endpoints({ user }: { user: CurrentUser }) {
)} + {draft.kind === "http" && ( +
+
+
Judge a value in the answer (optional)
+
+ For an answer in JSON: say where the value is and what it should be. For example power.now is below 5000, state is equal to playing, or, for a Prometheus query, data.result[0].value[1] is above 0. + Use [0] for the first place in a list. +
+
+
+ + set("valuePath", e.target.value)} /> +
+
+ + +
+ {draft.valueOp !== "exists" && ( +
+ + set("valueExpected", e.target.value)} /> +
+ )} +
+ + set("valueUnit", e.target.value)} /> +
+
+
+
+ + set("headerName", e.target.value)} /> +
+
+ + set("headerValue", e.target.value)} + /> +
For an API that wants a token. It is stored encrypted, never shown again, and only sent to this address — not to another host a redirect leads to.
+
+
+
+
+ )}
+ {c.valuePath &&
{limitWords(c)}
} {c.server && (
about {c.server.name} @@ -425,6 +530,12 @@ export default function Endpoints({ user }: { user: CurrentUser }) { )} + {c.lastValue !== null && ( +
+ {c.lastValue} + {c.valueUnit && Number.isFinite(Number(c.lastValue)) ? ` ${c.valueUnit}` : ""} +
+ )} {c.lastResponseMs === null ? — : `${c.lastResponseMs} ms`} {c.stats?.avgMs24h != null &&
avg {c.stats.avgMs24h} ms
}