From e114567d6492f537a601822dc750b23261a08968 Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Wed, 21 Oct 2026 20:58:57 +0200 Subject: [PATCH] How big the app's data is, and a webhook delivery log with Send again Settings -> Data -> Storage measures the database, backups and sessions and every table (size, rows, growth, how long it is kept, how far back it reaches), and flags histories that are not being trimmed or have no limit. Event webhooks now keep a delivery log (last 100 per webhook, 14 days): what was sent, how it went, the message itself, and Send again, which resends it exactly as it was (same id and signature). Resends are audited and in the Change log. Co-Authored-By: Claude Sonnet 5.5 --- DATABASE.md | 31 +- README.md | 6 +- ROLES.md | 1 + docs/MONITORING.md | 5 + docs/WEBHOOKS.md | 24 +- server/drizzle/0052_brainy_steve_rogers.sql | 15 + server/drizzle/meta/0052_snapshot.json | 5878 ++++++++++++++++++ server/drizzle/meta/_journal.json | 7 + server/src/app.ts | 2 + server/src/db/schema.ts | 22 + server/src/routes/dataUsage.ts | 12 + server/src/routes/eventWebhooks.ts | 34 +- server/src/services/changeLog.ts | 2 + server/src/services/dataUsage.ts | 191 + server/src/services/eventWebhooks.ts | 35 +- server/test/dataUsageAndDeliveries.test.ts | 269 + web/src/api/client.ts | 50 + web/src/pages/settings/ApiSettings.tsx | 8 +- web/src/pages/settings/SettingsGroups.tsx | 8 +- web/src/pages/settings/StorageSettings.tsx | 164 + web/src/pages/settings/WebhookDeliveries.tsx | 86 + web/src/utils/settingsIndex.ts | 2 + 22 files changed, 6833 insertions(+), 19 deletions(-) create mode 100644 server/drizzle/0052_brainy_steve_rogers.sql create mode 100644 server/drizzle/meta/0052_snapshot.json create mode 100644 server/src/routes/dataUsage.ts create mode 100644 server/src/services/dataUsage.ts create mode 100644 server/test/dataUsageAndDeliveries.test.ts create mode 100644 web/src/pages/settings/StorageSettings.tsx create mode 100644 web/src/pages/settings/WebhookDeliveries.tsx diff --git a/DATABASE.md b/DATABASE.md index 2894420..611ec5f 100644 --- a/DATABASE.md +++ b/DATABASE.md @@ -23,8 +23,8 @@ 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` … `0051`), applied automatically when the server starts. Which ones have run is recorded in the table `__drizzle_migrations`. | -| **Tables** | 61 application tables, plus drizzle's own `__drizzle_migrations`. | +| **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`. | +| **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`. @@ -84,11 +84,12 @@ erDiagram servers ||--o{ update_runs : "cascade" patch_plans ||--o{ patch_plan_runs : "cascade" endpoint_checks ||--o{ endpoint_daily : "cascade" + event_webhooks ||--o{ webhook_deliveries : "cascade" ``` -These 22 tables are without a foreign key to another table, and — but for `integration_credentials`, which `integrations` and `dns_providers` point at — with none from another table to them; where they refer to something else it is by id or name, see +These 21 tables are without a foreign key to another table, and — but for `integration_credentials`, which `integrations` and `dns_providers` point at — with none from another table to them; where they refer to something else it is by id or name, see [soft references](#soft-references-not-foreign-keys): `settings`, `secrets`, `ipam_entries`, `domains`, `diag_log`, `notification_queue`, `consistency_ignores`, `tag_definitions`, -`maintenance_windows`, `maintenance_aliases`, `maintenance_schedules`, `metrics_tokens`, `event_webhooks`, `restore_tests`, `dependencies`, `runbooks`, `renewals`, `assets`, `notes`, +`maintenance_windows`, `maintenance_aliases`, `maintenance_schedules`, `metrics_tokens`, `restore_tests`, `dependencies`, `runbooks`, `renewals`, `assets`, `notes`, `alert_rules`, `alert_snoozes` and `integration_credentials`. ## Tables @@ -994,6 +995,23 @@ URLs sent a signed JSON message when an alert begins or ends or maintenance star | `created_at` | text NOT NULL | | | `last_attempt_at`, `last_result` | text | When it was last sent to and what came back (`200`, or what went wrong). | +#### `webhook_deliveries` + +The log of what was sent to each event webhook (Settings → API and webhooks → Sent): one row per message, with its second try counted in. Trimmed to the newest 100 per webhook and 14 days each time one is added. + +| Column | Type | Notes | +|---|---|---| +| `id` | integer PK | | +| `webhook_id` | integer NOT NULL | FK → `event_webhooks.id`, cascade. Indexed with `created_at`. | +| `event` | text NOT NULL | `alert.opened` … | +| `delivery_id` | text NOT NULL | The message's `id` and `X-HLM-Delivery`; a resend keeps it. | +| `attempts` | integer NOT NULL, default 1 | 2 when the first try failed. | +| `ok` | bool NOT NULL | Whether a `2xx` came back. | +| `result` | text NOT NULL | `200`, or what went wrong. | +| `body` | text NOT NULL | The JSON that was sent, cut at 16 001 characters (longer than 16 000 means it cannot be sent again). | +| `retry_of` | integer | The `id` of the delivery this one sent again by hand. | +| `created_at` | text NOT NULL | ISO. | + #### `share_links` Addresses that open a read-only page without signing in (Settings → Share @@ -1109,7 +1127,7 @@ settings, and aren't part of the app's settings object: | a **server** | Its `scheduled_tasks`, `server_links`, `server_ports`, `server_metrics`, `server_metrics_rollup`, `update_runs` and `network_server_links` are deleted with it. Port forwards that pointed at it stay, with `server_id` cleared. Things that refer to it by id only (notes, to-do items, endpoint checks, heartbeats, alert rules, dependencies, runbooks, maintenance windows) stay, pointing at nothing — see below. | | a **DNS provider** | Its cached zones and records are deleted. | | an **integration** | What was read from it is deleted with it: UniFi devices, networks and server links, Home Assistant watched entities and readings, and the history of its storage pools (`storage_series`, `storage_samples`). | -| an **endpoint check**, a **heartbeat**, an **incident**, a **patch plan**, a **share link** | Their results and summaries (`endpoint_results`, `_hourly`, `_daily`), pings, notes, runs and status-page items. | +| an **endpoint check**, a **heartbeat**, an **incident**, a **patch plan**, a **share link**, an **event webhook** | Their results and summaries (`endpoint_results`, `_hourly`, `_daily`), pings, notes, runs, status-page items and delivery log (`webhook_deliveries`). | | an **integration** or **DNS provider** | The credential row it used is deleted by the app (not by the database). | | an **integration** used for alert tickets | `alert_tickets.integration_id` is cleared; the history stays. | | an **integration credential** | The integration / provider using it keeps existing, with `credential_id` cleared. | @@ -1167,6 +1185,9 @@ are deleted), and `notification_queue` is emptied each time the quiet-hours dige | `ha_readings` | 35 days | | `heartbeat_pings` | 14 days | | `alert_incidents`, `incident_notes` | 400 days after the incident resolved | +| `webhook_deliveries` | the newest 100 per webhook, and 14 days | + +Settings → Data → Storage shows how big each of these is and whether it is being trimmed as listed here. Everything else stays until someone deletes it. diff --git a/README.md b/README.md index 43f59a1..838e8c9 100644 --- a/README.md +++ b/README.md @@ -518,6 +518,10 @@ resolved after it has been missing for a couple of minutes in a row — thirty w never in the first minutes after the app starts, when server alerts are held back on purpose. Resolved incidents are kept for 400 days. The weekly digest has an *Incidents* section. +**How big the data is** (Settings → Data → Storage). The size of the database file, its backups and the signed-in sessions, and every table by the room it takes (with its indexes), its rows, how many it gains a day, how long it is +meant to be kept and how far back it actually reaches. A history that holds far more than its limit is flagged **not trimmed** (the trimming is not running), the logs are flagged **no limit** until purging is switched on +(Settings → Data → Logs), and a history that has not yet grown to its limit is *filling up*. Administrators only; it only measures. + **Database backups** (Settings → Data → Backup). A copy of Homelab Manager's own database is taken every day (03:30 in the notification time zone, the newest 14 kept; on unless you turn it off), checked as it is made, and kept in `data/backups/`. The page lists them with **Download**, **Check**, **Restore…** and **Delete**, @@ -683,7 +687,7 @@ agent versions, alert counts, which integrations work, maintenance, what is abou expire — to a request with a metrics token (a bearer token made on that page, shown once, only its hash kept). Event webhooks send a signed JSON message to a URL when an alert begins or ends or maintenance starts or finishes, for Home Assistant, n8n or a -status board. Both are described, with the exact series and message formats, in +status board; **Sent** on a webhook lists the last 100 messages to it (none older than 14 days) with how each went and the message itself, and **Send again** sends one exactly as it was, same id and signature. Both are described, with the exact series and message formats, in [docs/PROMETHEUS-GRAFANA.md](docs/PROMETHEUS-GRAFANA.md) and [docs/WEBHOOKS.md](docs/WEBHOOKS.md). **Monthly report** (Operations → Monthly report; and, if switched on, a message on a day of the month). How a calendar month went, on one page that can be read, printed and copied as text: diff --git a/ROLES.md b/ROLES.md index 293c33f..66dc0cf 100644 --- a/ROLES.md +++ b/ROLES.md @@ -149,6 +149,7 @@ even further, to admin only: Settings → Sign-in, so admin-only. - **Heartbeats** and the **Coming up** list are visible to everyone signed in; only administrators see a heartbeat's address, and make, change, remove or give a new address to one, and make the calendar feed of Coming up (a share link). **Suggested checks** are administrators' like the checks themselves. A job's call to its address needs no role: the token is the access. +- **The delivery log of an event webhook** (what was sent, with the messages, and sending one again) and **Settings → Data → Storage** (how big the app's data is) are administrator-only; sending a message again is in the audit log. - **Sign-in groups, metrics tokens, event webhooks, share links (the wall display and the status pages, and what is on them) and the Grafana dashboard download** are all under Settings, so admin-only; `/metrics` itself needs a metrics token, not a login. - Everything under **Settings** (notification channels, badge colors, diff --git a/docs/MONITORING.md b/docs/MONITORING.md index f99ade7..787dab4 100644 --- a/docs/MONITORING.md +++ b/docs/MONITORING.md @@ -272,10 +272,15 @@ hand, a config file edited — is not something the app can see. | Proxmox storage and Synology volume use | **400 days**, one reading an hour | | | Home Assistant watched numbers | **35 days**, one reading every few minutes | | | Incidents | **400 days** after they resolve | | +| Messages sent to event webhooks | The last **100 per webhook**, none older than **14 days** — see [WEBHOOKS.md](WEBHOOKS.md#the-delivery-log-and-sending-again) | | | The audit log and the Diagnostic Log | Until automatic purging is switched on under *Settings → Data* (then 90 days by default, configurable) | | A chart asks for 24 hours, 7, 30, 90 days or a year and is drawn from whichever of these is fine enough and still there. +**Is it being trimmed?** *Settings → Data → Storage* measures the database, its backups and sessions, and every table by the room it takes, and for each history says how far back it reaches against how long it is meant to be kept: +*trimmed* (at its limit), *filling up* (not yet old enough to be trimmed), *not trimmed* (it holds far more than it should, so the trimming is not running or has not caught up) or *no limit* (the logs, until purging is +switched on). The last two are listed at the top as needing a look. Nothing there changes anything. + ## Where to see it | | Shows | diff --git a/docs/WEBHOOKS.md b/docs/WEBHOOKS.md index e8c74a5..233a5aa 100644 --- a/docs/WEBHOOKS.md +++ b/docs/WEBHOOKS.md @@ -149,13 +149,33 @@ have handled and refuse repeats, and reject a `createdAt` that is far from your ### Delivery: what to rely on and what not to - Delivery is **best-effort and never holds anything up.** One try; if it does not get a `2xx` answer, **one more after two seconds** (the same message, the same `id` and `X-HLM-Delivery`); then the - result is written on the webhook and forgotten. + result is written on the webhook and in its [delivery log](#the-delivery-log-and-sending-again). - A request is given **five seconds**. **Redirects are not followed** (a redirect counts as a failure) — give the final address. -- **There is no queue and no replay.** A receiver that is down for longer than those two tries **misses the event**. Messages for different events can arrive in any order. If you need to be certain, treat the +- **There is no queue and no automatic replay.** A receiver that is down for longer than those two tries **misses the event** — until someone sends it again from the delivery log. Messages for different events can arrive in any order. If you need to be certain, treat the webhook as a *nudge* and reconcile with the [read API](API.md) (`GET /api/v1/alerts`, `/api/v1/maintenance`), which always says what is true now. - Because a retry reuses the delivery id, **handle each id once** (idempotently). - Answer quickly (`200` is enough) and do slow work afterwards. +### The delivery log and sending again + +Every message sent to a webhook is written down: when, which event, whether it got through, what came back (`200`, or what went wrong, such as `connect ECONNREFUSED` or `500`), whether it needed its second try, and the +message itself. **Settings → API and webhooks → Event webhooks → Sent** opens the log for one webhook, newest first, and **Show the message** unfolds the JSON that was sent. + +**Send again** sends a message from the log **exactly as it was** — the same bytes, the same `id` and `X-HLM-Delivery`, a signature made over the same body — so a receiver that already handled it can recognise it by its id and +ignore it, and one that missed it handles it now. The new attempt is logged as a delivery of its own, marked *sent again by hand*, and updates the webhook's *Last* result. Like the first send it is tried twice. +It is for when the receiver was down or the fault was at its end; it does not repair a wrong address. + +- **The last 100 per webhook, and none older than 14 days,** are kept. Removing a webhook removes its log. +- A message larger than **16 000 characters** is not kept in full, so it is not shown and cannot be sent again (`409 too_large`). The messages the app sends are far smaller. +- **Administrators only** — the log holds what was sent, which names servers and says what is wrong with them. Each resend is in the audit log (*webhook › retry*) and in the **Change log**. + +``` +GET /api/event-webhooks//deliveries?limit=50 the log (limit 1–100) +POST /api/event-webhooks//deliveries//retry send one again → { "ok": true, "result": "200" } +``` + +These are the app's own addresses (they need an administrator's sign-in, not an API token), listed for completeness. + ### Alert keys `alert.key` is the stable identity of a problem: the same problem has the same key every time, so you can match an `opened` with its `resolved`. The shapes: diff --git a/server/drizzle/0052_brainy_steve_rogers.sql b/server/drizzle/0052_brainy_steve_rogers.sql new file mode 100644 index 0000000..b68c74f --- /dev/null +++ b/server/drizzle/0052_brainy_steve_rogers.sql @@ -0,0 +1,15 @@ +CREATE TABLE `webhook_deliveries` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `webhook_id` integer NOT NULL, + `event` text NOT NULL, + `delivery_id` text NOT NULL, + `attempts` integer DEFAULT 1 NOT NULL, + `ok` integer NOT NULL, + `result` text NOT NULL, + `body` text NOT NULL, + `retry_of` integer, + `created_at` text NOT NULL, + FOREIGN KEY (`webhook_id`) REFERENCES `event_webhooks`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE INDEX `webhook_deliveries_webhook_idx` ON `webhook_deliveries` (`webhook_id`,`created_at`); \ No newline at end of file diff --git a/server/drizzle/meta/0052_snapshot.json b/server/drizzle/meta/0052_snapshot.json new file mode 100644 index 0000000..53ad47c --- /dev/null +++ b/server/drizzle/meta/0052_snapshot.json @@ -0,0 +1,5878 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "bd78e385-449c-432f-8615-38726b1e0e3f", + "prevId": "37006591-92e9-4443-ac30-0fb29d47911e", + "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 + }, + "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 + } + }, + "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 9563606..fa7a77e 100644 --- a/server/drizzle/meta/_journal.json +++ b/server/drizzle/meta/_journal.json @@ -365,6 +365,13 @@ "when": 1792531006435, "tag": "0051_next_nitro", "breakpoints": true + }, + { + "idx": 52, + "version": "6", + "when": 1792608282223, + "tag": "0052_brainy_steve_rogers", + "breakpoints": true } ] } \ No newline at end of file diff --git a/server/src/app.ts b/server/src/app.ts index 2c2328c..6ff0826 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -52,6 +52,7 @@ import { notesRouter, todosRouter } from "./routes/todos.js"; import { npmRouter } from "./routes/npm.js"; import { alertRulesRouter } from "./routes/alertRules.js"; import { storageRouter } from "./routes/storage.js"; +import { dataUsageRouter } from "./routes/dataUsage.js"; import { alertActionsRouter } from "./routes/alertActions.js"; import { homeAssistantRouter } from "./routes/homeAssistant.js"; import { publicApiRouter } from "./routes/publicApi.js"; @@ -181,6 +182,7 @@ export function createApp() { app.use("/api/npm", npmRouter); app.use("/api/alert-rules", alertRulesRouter); app.use("/api/storage", storageRouter); + app.use("/api/data-usage", dataUsageRouter); app.use("/api/home-assistant", homeAssistantRouter); app.use("/api/todos", todosRouter); app.use("/api/notes", notesRouter); diff --git a/server/src/db/schema.ts b/server/src/db/schema.ts index e11eb27..527c94c 100644 --- a/server/src/db/schema.ts +++ b/server/src/db/schema.ts @@ -1294,3 +1294,25 @@ export const alertSnoozes = sqliteTable( }, (t) => [uniqueIndex("alert_snoozes_alert_idx").on(t.alertId)], ); + +// ─── What each event webhook was sent, and how it went ────────────────────── + +// One row per message to one webhook (the try and its one retry together), with the exact body so it can be sent again by hand. The last 100 per webhook and no more than two weeks. +export const webhookDeliveries = sqliteTable( + "webhook_deliveries", + { + id: integer("id").primaryKey({ autoIncrement: true }), + webhookId: integer("webhook_id") + .notNull() + .references(() => eventWebhooks.id, { onDelete: "cascade" }), + event: text("event").notNull(), + deliveryId: text("delivery_id").notNull(), // the message's id, which a receiver can use to ignore a repeat + attempts: integer("attempts").notNull().default(1), + ok: integer("ok", { mode: "boolean" }).notNull(), + result: text("result").notNull(), // "200", or what went wrong + body: text("body").notNull(), // the exact JSON that was sent (what the signature covers) + retryOf: integer("retry_of"), // the delivery this one repeats, when somebody pressed Retry + createdAt: text("created_at").notNull(), // ISO + }, + (t) => [index("webhook_deliveries_webhook_idx").on(t.webhookId, t.createdAt)], +); diff --git a/server/src/routes/dataUsage.ts b/server/src/routes/dataUsage.ts new file mode 100644 index 0000000..55f2c9d --- /dev/null +++ b/server/src/routes/dataUsage.ts @@ -0,0 +1,12 @@ +import { Router } from "express"; +import { requireAuth, requireRole } from "../auth/middleware.js"; +import { getDataUsage } from "../services/dataUsage.js"; +import { asyncHandler } from "../utils/asyncHandler.js"; + +/** How big the app's own data is and whether it is being trimmed: for administrators (it names every table and how much each holds). */ +export const dataUsageRouter = Router(); +dataUsageRouter.use(requireAuth, requireRole("admin")); + +dataUsageRouter.get("/", asyncHandler(async (_req, res) => { + res.json(await getDataUsage()); +})); diff --git a/server/src/routes/eventWebhooks.ts b/server/src/routes/eventWebhooks.ts index 5494a25..8b6aa2f 100644 --- a/server/src/routes/eventWebhooks.ts +++ b/server/src/routes/eventWebhooks.ts @@ -1,11 +1,11 @@ import { Router } from "express"; -import { eq } from "drizzle-orm"; +import { and, desc, eq } from "drizzle-orm"; import { z } from "zod"; import { db } from "../db/client.js"; -import { eventWebhooks, webhookEvents } from "../db/schema.js"; +import { eventWebhooks, webhookDeliveries, webhookEvents } from "../db/schema.js"; import { requireAuth, requireRole } from "../auth/middleware.js"; import { recordAudit } from "../services/audit.js"; -import { deliver, parseEvents, sealSecret, type EventWebhookRow } from "../services/eventWebhooks.js"; +import { deliver, MAX_STORED_BODY, parseEvents, redeliver, sealSecret, type EventWebhookRow } from "../services/eventWebhooks.js"; import { asyncHandler } from "../utils/asyncHandler.js"; export const eventWebhooksRouter = Router(); @@ -86,6 +86,34 @@ eventWebhooksRouter.delete("/:id", asyncHandler(async (req, res) => { res.status(204).end(); })); +// What was sent to a webhook lately and how each went, with the message itself, newest first. +eventWebhooksRouter.get("/:id/deliveries", asyncHandler(async (req, res) => { + const id = idOf(req.params.id); + if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" }); + const [row] = await db.select({ id: eventWebhooks.id }).from(eventWebhooks).where(eq(eventWebhooks.id, id)).limit(1); + if (!row) return res.status(404).json({ error: "not_found" }); + const asked = Number(req.query.limit); + const limit = Number.isFinite(asked) ? Math.min(100, Math.max(1, Math.round(asked))) : 50; + const rows = await db.select().from(webhookDeliveries).where(eq(webhookDeliveries.webhookId, id)).orderBy(desc(webhookDeliveries.createdAt), desc(webhookDeliveries.id)).limit(limit); + res.json({ + deliveries: rows.map((r) => ({ id: r.id, event: r.event, deliveryId: r.deliveryId, attempts: r.attempts, ok: r.ok, result: r.result, body: r.body.length > MAX_STORED_BODY ? null : r.body, retryable: r.body.length <= MAX_STORED_BODY, retryOf: r.retryOf, createdAt: r.createdAt })), + }); +})); + +// Sends a delivery again exactly as it was, with the same id — for when the receiver was down, or the fault was at its end. +eventWebhooksRouter.post("/:id/deliveries/:deliveryId/retry", asyncHandler(async (req, res) => { + const id = idOf(req.params.id); + const deliveryRowId = idOf(req.params.deliveryId); + if (!Number.isInteger(id) || !Number.isInteger(deliveryRowId)) return res.status(400).json({ error: "invalid_id" }); + const [hook] = await db.select().from(eventWebhooks).where(eq(eventWebhooks.id, id)).limit(1); + const [earlier] = await db.select().from(webhookDeliveries).where(and(eq(webhookDeliveries.id, deliveryRowId), eq(webhookDeliveries.webhookId, id))).limit(1); + if (!hook || !earlier) return res.status(404).json({ error: "not_found" }); + if (earlier.body.length > MAX_STORED_BODY) return res.status(409).json({ error: "too_large", message: "That message was too large to keep, so it cannot be sent again." }); + const outcome = await redeliver(hook, earlier); + await recordAudit({ actor: req.currentUser!, category: "webhook", action: "retry", targetType: "event_webhook", targetId: id, detail: { label: hook.label, event: earlier.event, ok: outcome.ok } }); + res.json(outcome); +})); + // Sends one test message, signed like the real ones, and says how it went — whether or not the webhook is switched on or wants the event. eventWebhooksRouter.post("/:id/test", asyncHandler(async (req, res) => { const id = idOf(req.params.id); diff --git a/server/src/services/changeLog.ts b/server/src/services/changeLog.ts index 0cde31a..5458cd3 100644 --- a/server/src/services/changeLog.ts +++ b/server/src/services/changeLog.ts @@ -179,6 +179,8 @@ export function describeChange(category: string, action: string, detail: Record< return { title: "Acknowledging several alerts at once was undone", tone: "neutral", detail: null }; case "inventory/bulk_change": return { title: detail.change === "undo" ? "A change to several pieces of hardware was undone" : `${typeof detail.changed === "number" ? detail.changed : "Several"} piece${detail.changed === 1 ? "" : "s"} of hardware changed at once`, tone: "neutral", detail: genericSummary(detail, ["ids", "changed", "change"]) }; + case "webhook/retry": + return { title: `A webhook message was sent again${name ? `: ${name}` : str(detail.label) ? `: ${str(detail.label)}` : ""}`, tone: detail.ok === false ? "bad" : "neutral", detail: str(detail.event) }; case "alert_rule/create": return { title: `Alert rule added${name ? `: ${name}` : ""}`, tone: "neutral", detail: genericSummary(detail) }; case "alert_rule/update": diff --git a/server/src/services/dataUsage.ts b/server/src/services/dataUsage.ts new file mode 100644 index 0000000..d05b02f --- /dev/null +++ b/server/src/services/dataUsage.ts @@ -0,0 +1,191 @@ +/** + * How big the app's own data is, and whether what is meant to be trimmed is being trimmed: the database file and what it holds table by table (rows and bytes), the + * backups and the sessions beside it, and — for each table that keeps a history — how far back it reaches, how fast it is growing and whether that matches how long + * it is meant to be kept. A history that holds far more than its limit means its trimming is not running; one that has no limit at all (the logs, until purging is + * switched on) is said to grow without end. + * + * Nothing here changes anything. It only reads, and the table names it puts in a query come from a fixed list, never from a request. + */ +import { existsSync, readdirSync, statSync } from "node:fs"; +import { join } from "node:path"; +import { client, dbPath } from "../db/client.js"; +import { env } from "../env.js"; +import { resolveDataPath } from "../paths.js"; +import { backupDir } from "./selfBackup.js"; +import { getSettings } from "./settingsStore.js"; + +const DAY_MS = 86_400_000; + +/** How a table with a history is trimmed. `log` follows the log-retention setting. */ +interface HistoryMeta { + /** The column that says when a row is from. */ + time: string; + keep: number | "log" | null; + /** Narrows to the rows the limit is about (an incident is only trimmed once resolved; the daily rows of the summary table). */ + where?: string; + /** Said under the table's name. */ + note?: string; +} + +export const HISTORY: Record = { + server_metrics: { time: "recorded_at", keep: 35, note: "a sample of each server's load, memory and disks every 10–15 minutes" }, + server_metrics_rollup: { time: "at", keep: 800, where: "grain = 'd'", note: "hourly figures are kept 120 days, daily ones about 800" }, + endpoint_results: { time: "at", keep: 14, note: "every answer of every endpoint check" }, + endpoint_hourly: { time: "hour", keep: 120 }, + endpoint_daily: { time: "day", keep: 800 }, + heartbeat_pings: { time: "at", keep: 14 }, + storage_samples: { time: "at", keep: 400, note: "one reading an hour of each Proxmox storage and Synology volume" }, + ha_readings: { time: "at", keep: 35, note: "the watched Home Assistant numbers" }, + alert_incidents: { time: "resolved_at", keep: 400, where: "resolved_at IS NOT NULL", note: "trimmed 400 days after an incident resolved" }, + webhook_deliveries: { time: "created_at", keep: 14, note: "the last 100 per webhook, and none older than two weeks" }, + audit_log: { time: "created_at", keep: "log", note: "who did what" }, + diag_log: { time: "created_at", keep: "log", note: "every call to an integration or DNS provider" }, + notification_queue: { time: "created_at", keep: null, note: "held for quiet hours; emptied when the digest is sent" }, + renewals: { time: "at", keep: null, note: "small; never trimmed" }, +}; + +export type UsageState = "limit" | "filling" | "not_trimmed" | "unlimited" | "plain"; + +export interface TableUsage { + name: string; + rows: number; + /** The table and its indexes, in bytes; null when the database cannot say. */ + bytes: number | null; + /** How long it keeps what it holds, in days; null for no limit. */ + keepDays: number | null; + note: string | null; + /** ISO — the oldest and newest row, for the tables that keep a history. */ + oldest: string | null; + newest: string | null; + /** Rows added a day lately (over the last week, or for as long as it has been going if less). */ + perDay: number | null; + /** How many days its history reaches back. */ + spanDays: number | null; + state: UsageState; + stateText: string; +} + +export interface DataUsage { + generatedAt: string; + database: { file: string; bytes: number; walBytes: number; pages: number; pageSize: number; freePages: number; freeBytes: number; tables: number }; + backups: { files: number; bytes: number }; + sessions: { files: number; bytes: number }; + /** Everything in the data folder that is measured here. */ + totalBytes: number; + tables: TableUsage[]; + /** What needs a look: the tables not trimmed as they should be, and those with no limit. */ + attention: { table: string; text: string }[]; +} + +function folderSize(dir: string): { files: number; bytes: number } { + let files = 0; + let bytes = 0; + try { + if (!existsSync(dir)) return { files, bytes }; + for (const name of readdirSync(dir)) { + try { + const s = statSync(join(dir, name)); + if (s.isFile()) { + files++; + bytes += s.size; + } + } catch { + // gone while looking + } + } + } catch { + // unreadable: counts as nothing + } + return { files, bytes }; +} + +const sizeOf = (path: string) => { + try { + return statSync(path).size; + } catch { + return 0; + } +}; + +/** Database time columns are "2026-10-03 14:05:09" (UTC), ISO, or just a date; all of them become an ISO moment. */ +export function toIso(value: string): string | null { + const t = /^\d{4}-\d{2}-\d{2}$/.test(value) ? Date.parse(`${value}T00:00:00Z`) : /T|Z$/.test(value) ? Date.parse(value) : Date.parse(`${value.replace(" ", "T")}Z`); + return Number.isFinite(t) ? new Date(t).toISOString() : null; +} + +/** Pure: whether a history is being trimmed as it should be, in words. `keepDays` null is no limit. */ +export function judge(input: { keepDays: number | null; spanDays: number | null; rows: number; logsOff?: boolean }): { state: UsageState; text: string } { + const { keepDays, spanDays, rows } = input; + if (keepDays === null) return input.logsOff ? { state: "unlimited", text: "Grows without limit — automatic purging is switched off (Settings → Data → Logs)." } : { state: "plain", text: "" }; + if (rows === 0 || spanDays === null) return { state: "limit", text: "Empty." }; + if (spanDays > keepDays + 2) return { state: "not_trimmed", text: `Reaches back ${Math.round(spanDays)} days, but should keep only ${keepDays} — the trimming is not running, or has not caught up.` }; + if (spanDays < keepDays - 1) return { state: "filling", text: `Holds ${Math.max(1, Math.round(spanDays))} of its ${keepDays} days so far.` }; + return { state: "limit", text: `At its limit: the oldest is about ${Math.round(spanDays)} days old, and it keeps ${keepDays}.` }; +} + +export async function getDataUsage(now: Date = new Date()): Promise { + const settings = await getSettings(); + const names = (await client.execute("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name")).rows.map((r) => String(r.name)); + + // Bytes per table, with its indexes counted in: the database reports its pages by the name of what owns them. + const bytes = new Map(); + let dbstat = true; + try { + const owners = new Map((await client.execute("SELECT name, tbl_name FROM sqlite_master")).rows.map((r) => [String(r.name), String(r.tbl_name)])); + for (const r of (await client.execute("SELECT name, sum(pgsize) AS bytes FROM dbstat GROUP BY name")).rows) { + const owner = owners.get(String(r.name)) ?? String(r.name); + bytes.set(owner, (bytes.get(owner) ?? 0) + Number(r.bytes)); + } + } catch { + dbstat = false; + } + + const tables: TableUsage[] = []; + const weekAgo = new Date(now.getTime() - 7 * DAY_MS).toISOString(); + for (const name of names) { + const rows = Number((await client.execute(`SELECT count(*) AS n FROM "${name}"`)).rows[0].n); + const meta = HISTORY[name]; + let keepDays: number | null = null; + let oldest: string | null = null; + let newest: string | null = null; + let perDay: number | null = null; + let spanDays: number | null = null; + if (meta) { + keepDays = meta.keep === "log" ? (settings.logRetention.enabled ? settings.logRetention.retentionDays : null) : meta.keep; + const where = meta.where ? `WHERE ${meta.where}` : ""; + const r = (await client.execute(`SELECT min("${meta.time}") AS oldest, max("${meta.time}") AS newest FROM "${name}" ${where}`)).rows[0]; + oldest = r.oldest === null ? null : toIso(String(r.oldest)); + newest = r.newest === null ? null : toIso(String(r.newest)); + if (oldest) { + spanDays = Math.max(0, (now.getTime() - Date.parse(oldest)) / DAY_MS); + // The rows of the last week, by the way this table writes its times: a date alone, SQLite's "2026-10-03 14:05:09", or ISO. + const sample = String((await client.execute(`SELECT "${meta.time}" AS t FROM "${name}" WHERE "${meta.time}" IS NOT NULL LIMIT 1`)).rows[0]?.t ?? ""); + const cutoff = /^\d{4}-\d{2}-\d{2}$/.test(sample) ? weekAgo.slice(0, 10) : /^\d{4}-\d{2}-\d{2} /.test(sample) ? weekAgo.slice(0, 19).replace("T", " ") : weekAgo; + const recent = Number((await client.execute({ sql: `SELECT count(*) AS n FROM "${name}" ${where ? `${where} AND` : "WHERE"} "${meta.time}" >= ?`, args: [cutoff] })).rows[0].n); + perDay = Math.round((recent / Math.max(1, Math.min(7, spanDays))) * 10) / 10; + } + } + const logsOff = meta?.keep === "log" && keepDays === null; + const verdict = meta ? judge({ keepDays, spanDays, rows, logsOff }) : { state: "plain" as const, text: "" }; + tables.push({ name, rows, bytes: dbstat ? (bytes.get(name) ?? 0) : null, keepDays, note: meta?.note ?? null, oldest, newest, perDay, spanDays: spanDays === null ? null : Math.round(spanDays * 10) / 10, state: verdict.state, stateText: verdict.text }); + } + tables.sort((a, b) => (b.bytes ?? b.rows) - (a.bytes ?? a.rows) || a.name.localeCompare(b.name)); + + const pages = Number((await client.execute("PRAGMA page_count")).rows[0].page_count); + const pageSize = Number((await client.execute("PRAGMA page_size")).rows[0].page_size); + const freePages = Number((await client.execute("PRAGMA freelist_count")).rows[0].freelist_count); + const fileBytes = sizeOf(dbPath); + const walBytes = sizeOf(`${dbPath}-wal`); + const backups = folderSize(backupDir()); + const sessions = folderSize(resolveDataPath(env.sessionDir)); + + return { + generatedAt: now.toISOString(), + database: { file: dbPath.split(/[\\/]/).pop() ?? "", bytes: fileBytes, walBytes, pages, pageSize, freePages, freeBytes: freePages * pageSize, tables: names.length }, + backups, + sessions, + totalBytes: fileBytes + walBytes + backups.bytes + sessions.bytes, + tables, + attention: tables.filter((t) => t.state === "not_trimmed" || t.state === "unlimited").map((t) => ({ table: t.name, text: t.stateText })), + }; +} diff --git a/server/src/services/eventWebhooks.ts b/server/src/services/eventWebhooks.ts index 6c1c0e4..8228b17 100644 --- a/server/src/services/eventWebhooks.ts +++ b/server/src/services/eventWebhooks.ts @@ -11,9 +11,9 @@ * Settings) and forgotten. */ import { createHmac, randomUUID } from "node:crypto"; -import { eq } from "drizzle-orm"; +import { and, desc, eq, lt, notInArray } from "drizzle-orm"; import { db } from "../db/client.js"; -import { eventWebhooks, webhookEvents, type WebhookEvent } from "../db/schema.js"; +import { eventWebhooks, webhookDeliveries, webhookEvents, type WebhookEvent } from "../db/schema.js"; import { decryptSecret, encryptSecret } from "../crypto.js"; import { env } from "../env.js"; @@ -76,23 +76,50 @@ async function post(row: EventWebhookRow, event: string, body: string, deliveryI } } -/** One message to one webhook, retried once if it didn't go through. The outcome is written on the webhook. */ +/** How many deliveries are kept for each webhook, and for how long. */ +export const KEEP_DELIVERIES = 100; +export const KEEP_DELIVERY_DAYS = 14; +/** A body longer than this is not kept, so it cannot be sent again by hand. */ +export const MAX_STORED_BODY = 16_000; + +/** One message to one webhook, retried once if it didn't go through. The outcome is written on the webhook and in its delivery log. */ export async function deliver(row: EventWebhookRow, event: string, data: unknown, options: { retryAfterMs?: number } = {}): Promise { const deliveryId = randomUUID(); const body = JSON.stringify({ event, id: deliveryId, createdAt: new Date().toISOString(), source: "homelab-manager", data }); + return sendAndNote(row, event, body, deliveryId, options, null); +} + +/** Sends a message that was sent before, exactly as it was (the same id, so a receiver that already handled it can ignore it). Says how it went, and writes that down as a delivery of its own. */ +export async function redeliver(row: EventWebhookRow, earlier: typeof webhookDeliveries.$inferSelect, options: { retryAfterMs?: number } = {}): Promise { + return sendAndNote(row, earlier.event, earlier.body, earlier.deliveryId, options, earlier.id); +} + +async function sendAndNote(row: EventWebhookRow, event: string, body: string, deliveryId: string, options: { retryAfterMs?: number }, retryOf: number | null): Promise { + let attempts = 1; let outcome = await post(row, event, body, deliveryId); if (!outcome.ok) { await new Promise((r) => setTimeout(r, options.retryAfterMs ?? RETRY_AFTER_MS)); outcome = await post(row, event, body, deliveryId); + attempts = 2; } + const now = new Date(); try { - await db.update(eventWebhooks).set({ lastAttemptAt: new Date().toISOString(), lastResult: outcome.result }).where(eq(eventWebhooks.id, row.id)); + await db.update(eventWebhooks).set({ lastAttemptAt: now.toISOString(), lastResult: outcome.result }).where(eq(eventWebhooks.id, row.id)); + await db.insert(webhookDeliveries).values({ webhookId: row.id, event, deliveryId, attempts, ok: outcome.ok, result: outcome.result, body: body.slice(0, MAX_STORED_BODY + 1), retryOf, createdAt: now.toISOString() }); + await pruneDeliveries(row.id, now); } catch (err) { console.error("[webhooks] couldn't note the result:", err); } return outcome; } +/** Keeps the last hundred deliveries of a webhook, and none older than two weeks. */ +export async function pruneDeliveries(webhookId: number, now: Date = new Date()): Promise { + const keep = await db.select({ id: webhookDeliveries.id }).from(webhookDeliveries).where(eq(webhookDeliveries.webhookId, webhookId)).orderBy(desc(webhookDeliveries.createdAt), desc(webhookDeliveries.id)).limit(KEEP_DELIVERIES); + if (keep.length === KEEP_DELIVERIES) await db.delete(webhookDeliveries).where(and(eq(webhookDeliveries.webhookId, webhookId), notInArray(webhookDeliveries.id, keep.map((k) => k.id)))); + await db.delete(webhookDeliveries).where(and(eq(webhookDeliveries.webhookId, webhookId), lt(webhookDeliveries.createdAt, new Date(now.getTime() - KEEP_DELIVERY_DAYS * 86_400_000).toISOString()))); +} + /** * Sends an event to every enabled webhook that wants it. Returns at once — delivery carries on in the background and can never delay or * fail what caused the event. diff --git a/server/test/dataUsageAndDeliveries.test.ts b/server/test/dataUsageAndDeliveries.test.ts new file mode 100644 index 0000000..8020685 --- /dev/null +++ b/server/test/dataUsageAndDeliveries.test.ts @@ -0,0 +1,269 @@ +/** + * How big the app's own data is and whether it is being trimmed, and the delivery log of the event webhooks with its retry. + * + * Run with: npm test --workspace server + */ +import { test, describe, before, after } from "node:test"; +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { createServer, type IncomingMessage, type Server } from "node:http"; +import type { AddressInfo } from "node:net"; + +const dir = mkdtempSync(join(tmpdir(), "hm-usage-")); +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, servers, serverMetrics, endpointChecks, endpointResults, auditLog, eventWebhooks, webhookDeliveries } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const usage = await import("../src/services/dataUsage.js"); +const hooks = await import("../src/services/eventWebhooks.js"); +const { updateSettings } = await import("../src/services/settingsStore.js"); +const { dataUsageRouter } = await import("../src/routes/dataUsage.js"); +const { eventWebhooksRouter } = await import("../src/routes/eventWebhooks.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); +mkdirSync(join(dir, "sessions"), { recursive: true }); +mkdirSync(join(dir, "backups"), { recursive: true }); + +after(() => { + try { + rmSync(dir, { recursive: true, force: true }); + } catch { + // Windows may still hold the database file + } +}); + +const DAY = 86_400_000; +const NOW = new Date("2026-10-20T12:00:00Z"); +const ago = (days: number) => new Date(NOW.getTime() - days * DAY).toISOString(); + +describe("is a history being trimmed?", () => { + test("it reaches back as far as it should, or it is still filling, or it is holding far too much, or it has no limit at all", () => { + assert.deepEqual(usage.judge({ keepDays: 35, spanDays: 34.5, rows: 900 }).state, "limit"); + assert.deepEqual(usage.judge({ keepDays: 35, spanDays: 36, rows: 900 }).state, "limit", "a day or two over is the trimming not having run yet today"); + assert.equal(usage.judge({ keepDays: 35, spanDays: 12, rows: 300 }).state, "filling"); + assert.match(usage.judge({ keepDays: 35, spanDays: 12, rows: 300 }).text, /Holds 12 of its 35 days so far/); + const bad = usage.judge({ keepDays: 35, spanDays: 90, rows: 5000 }); + assert.equal(bad.state, "not_trimmed"); + assert.match(bad.text, /Reaches back 90 days, but should keep only 35/); + assert.equal(usage.judge({ keepDays: null, spanDays: 400, rows: 1000, logsOff: true }).state, "unlimited"); + assert.equal(usage.judge({ keepDays: null, spanDays: 10, rows: 10 }).state, "plain", "no limit and no promise of one"); + assert.equal(usage.judge({ keepDays: 14, spanDays: null, rows: 0 }).text, "Empty."); + }); + + test("the times the database writes, in all three forms, become moments", () => { + assert.equal(usage.toIso("2026-10-03 14:05:09"), "2026-10-03T14:05:09.000Z"); + assert.equal(usage.toIso("2026-10-03T14:05:09.123Z"), "2026-10-03T14:05:09.123Z"); + assert.equal(usage.toIso("2026-10-03"), "2026-10-03T00:00:00.000Z"); + assert.equal(usage.toIso("nonsense"), null); + }); +}); + +describe("what the data folder holds", () => { + before(async () => { + const [s] = await db.insert(servers).values({ name: "web", apiTokenHash: "h", apiTokenPrefix: "p", ipAddresses: "[]" }).returning(); + // Server samples going back 60 days, though only 35 are meant to be kept: the trimming has not run. + for (let d = 60; d >= 0; d -= 2) await db.insert(serverMetrics).values({ serverId: s.id, metric: "cpu", value: 10, recordedAt: ago(d) }); + // An endpoint check's answers for only five days of its fourteen. + const [c] = await db.insert(endpointChecks).values({ name: "Wiki", kind: "http", target: "https://x/" } as never).returning(); + for (let h = 0; h < 5 * 24; h += 6) await db.insert(endpointResults).values({ checkId: c.id, at: new Date(NOW.getTime() - h * 3600_000).toISOString(), ok: true, ms: 40, message: "ok" } as never); + // The audit log, in SQLite's own time format, going back 200 days. + for (let d = 200; d >= 0; d -= 20) await db.insert(auditLog).values({ category: "settings", action: "update", createdAt: ago(d).slice(0, 19).replace("T", " ") }); + writeFileSync(join(dir, "backups", "homelab-manager-2026-10-19-03-30-00.sqlite"), Buffer.alloc(1500)); + writeFileSync(join(dir, "backups", "homelab-manager-2026-10-18-03-30-00.sqlite"), Buffer.alloc(500)); + writeFileSync(join(dir, "sessions", "abc.json"), "{}"); + }); + + test("the file, the backups and the sessions beside it, and the tables by what they hold", async () => { + const u = await usage.getDataUsage(NOW); + assert.ok(u.database.bytes > 100_000 && u.database.pages * u.database.pageSize >= u.database.bytes - 8192, "the file is as big as its pages"); + assert.deepEqual([u.backups.files, u.backups.bytes, u.sessions.files], [2, 2000, 1]); + assert.equal(u.totalBytes, u.database.bytes + u.database.walBytes + 2000 + u.sessions.bytes); + assert.ok(u.database.tables >= 60 && u.tables.length === u.database.tables); + const t = Object.fromEntries(u.tables.map((x) => [x.name, x])); + assert.equal(t.server_metrics.rows, 31); + assert.ok(t.server_metrics.bytes! > 0 && t.users.bytes! > 0, "sizes come from the database's own page count, indexes included"); + assert.ok(u.tables.every((x, i) => i === 0 || (u.tables[i - 1].bytes ?? 0) >= (x.bytes ?? 0)), "the biggest first"); + }); + + test("a history that holds more than it should is said to be untrimmed; one still filling says how far it has got", async () => { + const t = Object.fromEntries((await usage.getDataUsage(NOW)).tables.map((x) => [x.name, x])); + assert.deepEqual([t.server_metrics.state, t.server_metrics.keepDays, Math.round(t.server_metrics.spanDays!)], ["not_trimmed", 35, 60]); + assert.match(t.server_metrics.stateText, /should keep only 35/); + assert.equal(t.server_metrics.oldest, ago(60)); + assert.deepEqual([t.endpoint_results.state, t.endpoint_results.keepDays], ["filling", 14]); + assert.match(t.endpoint_results.stateText, /Holds 5 of its 14 days/); + assert.ok(t.endpoint_results.perDay! >= 4, "four readings a day, over the five days"); + assert.equal(t.server_metrics.perDay, 0.6, "four samples (every other day) in the last week, over seven days"); + }); + + test("the logs have no limit until purging is switched on, and then are judged by it", async () => { + await updateSettings({ logRetention: { enabled: false, retentionDays: 90, intervalHours: 24 } }); + let u = await usage.getDataUsage(NOW); + let audit = u.tables.find((x) => x.name === "audit_log")!; + assert.deepEqual([audit.state, audit.keepDays], ["unlimited", null]); + assert.ok(u.attention.some((a) => a.table === "audit_log" && /switched off/.test(a.text))); + assert.ok(u.attention.some((a) => a.table === "server_metrics"), "and what is not trimmed is on the list too"); + assert.ok(!u.attention.some((a) => a.table === "endpoint_results"), "a table that is merely filling needs no look"); + + await updateSettings({ logRetention: { enabled: true, retentionDays: 90, intervalHours: 24 } }); + u = await usage.getDataUsage(NOW); + audit = u.tables.find((x) => x.name === "audit_log")!; + assert.deepEqual([audit.state, audit.keepDays], ["not_trimmed", 90]); + assert.match(audit.stateText, /Reaches back 200 days, but should keep only 90/); + assert.equal(audit.perDay, 0.1, "the week is counted in the form this table writes its times in"); + }); + + test("only an administrator can ask", async () => { + await db.insert(users).values([ + { oidcSub: "admin", name: "Ada", role: "admin" }, + { oidcSub: "viewer", name: "Vic", role: "viewer" }, + ]); + let who = "viewer"; + const a = express(); + a.use((req, _res, next) => { + (req as unknown as { session: unknown }).session = { user: { sub: who } }; + next(); + }); + a.use("/api/data-usage", dataUsageRouter); + const server = await new Promise((resolve) => { + const s = a.listen(0, "127.0.0.1", () => resolve(s)); + }); + const base = `http://127.0.0.1:${(server.address() as AddressInfo).port}/api/data-usage`; + assert.equal((await fetch(base, { headers: { connection: "close" } })).status, 403); + who = "admin"; + const res = await fetch(base, { headers: { connection: "close" } }); + assert.equal(res.status, 200); + const body = (await res.json()) as any; + assert.ok(body.tables.length > 0 && body.database.bytes > 0 && !JSON.stringify(body).includes(dir.replace(/\\/g, "\\\\")), "no folder path leaves the server"); + server.close(); + }); +}); + +describe("the webhook delivery log", () => { + let receiver: Server; + let receiverUrl = ""; + const got: { headers: IncomingMessage["headers"]; body: string }[] = []; + let mode: "ok" | "fail" = "ok"; + let app: Server; + let base = ""; + let who = "admin"; + let hookId = 0; + + before(async () => { + receiver = await new Promise((resolve) => { + const s = createServer((req, res) => { + let b = ""; + req.on("data", (c) => (b += c)); + req.on("end", () => { + got.push({ headers: req.headers, body: b }); + res.statusCode = mode === "ok" ? 200 : 500; + res.end("x"); + }); + }).listen(0, "127.0.0.1", () => resolve(s)); + }); + receiverUrl = `http://127.0.0.1:${(receiver.address() as AddressInfo).port}/hook`; + const [hook] = await db.insert(eventWebhooks).values({ label: "Receiver", url: receiverUrl, secret: hooks.sealSecret("s3cret"), events: JSON.stringify(["alert.opened"]) }).returning(); + hookId = hook.id; + 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/event-webhooks", eventWebhooksRouter); + 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/event-webhooks`; + }); + after(() => { + receiver.close(); + app.close(); + }); + + const call = (method: string, path: string) => fetch(`${base}${path}`, { method, headers: { connection: "close" } }); + const rowOf = async () => (await db.select().from(eventWebhooks).where(eq(eventWebhooks.id, hookId)))[0]; + + test("every message is logged with how it went: one try that worked, and a failure that was tried twice", async () => { + const hook = await rowOf(); + mode = "ok"; + assert.equal((await hooks.deliver(hook, "alert.opened", { alert: { key: "offline:server:1", message: "web is down" } }, { retryAfterMs: 1 })).ok, true); + mode = "fail"; + assert.equal((await hooks.deliver(hook, "alert.opened", { alert: { key: "offline:server:2", message: "pi is down" } }, { retryAfterMs: 1 })).ok, false); + const rows = await db.select().from(webhookDeliveries).orderBy(webhookDeliveries.id); + assert.deepEqual(rows.map((r) => [r.event, r.attempts, r.ok, r.result]), [["alert.opened", 1, true, "200"], ["alert.opened", 2, false, "500"]]); + assert.equal(got.length, 3, "one, then two"); + assert.equal(JSON.parse(rows[1].body).data.alert.message, "pi is down"); + assert.equal(rows[1].deliveryId, JSON.parse(rows[1].body).id); + assert.equal(rows[1].retryOf, null); + }); + + test("the log is for administrators; it lists newest first, with the message and whether it can be sent again", async () => { + who = "viewer"; + assert.equal((await call("GET", `/${hookId}/deliveries`)).status, 403, "operators and viewers cannot read what was sent"); + who = "admin"; + const res = await call("GET", `/${hookId}/deliveries`); + assert.equal(res.status, 200); + const list = ((await res.json()) as any).deliveries; + assert.deepEqual(list.map((d: any) => [d.ok, d.attempts, d.retryable]), [[false, 2, true], [true, 1, true]]); + assert.equal(JSON.parse(list[0].body).data.alert.key, "offline:server:2"); + assert.equal((await call("GET", "/99999/deliveries")).status, 404); + assert.equal((await call("GET", "/abc/deliveries")).status, 400); + }); + + test("retrying sends the very same message — the same body, the same id, the same signature — and logs it as a delivery of its own", async () => { + const [failed] = await db.select().from(webhookDeliveries).where(eq(webhookDeliveries.ok, false)); + mode = "ok"; + got.length = 0; + const res = await call("POST", `/${hookId}/deliveries/${failed.id}/retry`); + assert.deepEqual([res.status, ((await res.json()) as any).ok], [200, true]); + assert.equal(got.length, 1); + assert.equal(got[0].body, failed.body, "the exact bytes"); + assert.equal(got[0].headers["x-hlm-delivery"], failed.deliveryId); + assert.equal(got[0].headers["x-hlm-signature"], hooks.signBody("s3cret", failed.body), "so a receiver checking the signature is satisfied"); + const rows = await db.select().from(webhookDeliveries).orderBy(webhookDeliveries.id); + assert.deepEqual([rows.length, rows[2].retryOf, rows[2].ok, rows[2].deliveryId], [3, failed.id, true, failed.deliveryId]); + assert.equal((await rowOf()).lastResult, "200", "and the webhook's own last result follows"); + const [audit] = await db.select().from(auditLog).where(eq(auditLog.action, "retry")); + assert.deepEqual([audit.category, audit.targetId, JSON.parse(audit.detail!).event], ["webhook", String(hookId), "alert.opened"]); + assert.equal((await call("POST", `/${hookId}/deliveries/99999/retry`)).status, 404); + assert.equal((await call("POST", `/${hookId + 1}/deliveries/${failed.id}/retry`)).status, 404, "a delivery of another webhook is not this one's"); + who = "viewer"; + assert.equal((await call("POST", `/${hookId}/deliveries/${failed.id}/retry`)).status, 403); + who = "admin"; + }); + + test("a message too big to have been kept cannot be sent again, and says so", async () => { + const [big] = await db.insert(webhookDeliveries).values({ webhookId: hookId, event: "alert.opened", deliveryId: "big", attempts: 1, ok: false, result: "500", body: "x".repeat(hooks.MAX_STORED_BODY + 1), createdAt: new Date().toISOString() }).returning(); + const list = ((await (await call("GET", `/${hookId}/deliveries`)).json()) as any).deliveries; + const row = list.find((d: any) => d.id === big.id); + assert.deepEqual([row.retryable, row.body], [false, null]); + const res = await call("POST", `/${hookId}/deliveries/${big.id}/retry`); + assert.equal(res.status, 409); + await db.delete(webhookDeliveries).where(eq(webhookDeliveries.id, big.id)); + }); + + test("only the last hundred are kept for a webhook, and none older than two weeks; removing the webhook removes its log", async () => { + const hook = await rowOf(); + const base0 = Date.now(); + for (let i = 0; i < 110; i++) await db.insert(webhookDeliveries).values({ webhookId: hookId, event: "alert.opened", deliveryId: `d${i}`, attempts: 1, ok: true, result: "200", body: "{}", createdAt: new Date(base0 - i * 1000).toISOString() }); + await db.insert(webhookDeliveries).values({ webhookId: hookId, event: "alert.opened", deliveryId: "old", attempts: 1, ok: true, result: "200", body: "{}", createdAt: new Date(base0 - 20 * DAY).toISOString() }); + mode = "ok"; + await hooks.deliver(hook, "alert.opened", { alert: { key: "k", message: "m" } }, { retryAfterMs: 1 }); + const rows = await db.select().from(webhookDeliveries).where(eq(webhookDeliveries.webhookId, hookId)); + assert.equal(rows.length, hooks.KEEP_DELIVERIES); + assert.ok(!rows.some((r) => r.deliveryId === "old"), "two weeks and more is gone"); + assert.ok(rows.some((r) => r.deliveryId === "d0") && !rows.some((r) => r.deliveryId === "d109"), "the newest kept, the oldest dropped"); + const removed = await call("DELETE", `/${hookId}`); + assert.equal(removed.status, 204); + assert.equal((await db.select().from(webhookDeliveries).where(eq(webhookDeliveries.webhookId, hookId))).length, 0); + }); +}); diff --git a/web/src/api/client.ts b/web/src/api/client.ts index 7cf6187..8f0887b 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -836,6 +836,51 @@ export interface EventWebhook { lastResult: string | null; } +/** One message sent to an event webhook, and how it went. */ +export interface WebhookDelivery { + id: number; + event: string; + deliveryId: string; + /** 1, or 2 when the first try failed. */ + attempts: number; + ok: boolean; + /** "200", or what went wrong. */ + result: string; + /** The JSON that was sent; null when it was too large to keep. */ + body: string | null; + retryable: boolean; + /** The delivery this one sent again, if it was a retry by hand. */ + retryOf: number | null; + createdAt: string; +} + +export type UsageState = "limit" | "filling" | "not_trimmed" | "unlimited" | "plain"; + +export interface TableUsage { + name: string; + rows: number; + bytes: number | null; + keepDays: number | null; + note: string | null; + oldest: string | null; + newest: string | null; + perDay: number | null; + spanDays: number | null; + state: UsageState; + stateText: string; +} + +/** How big the app's own data is, and whether its histories are trimmed as they should be. */ +export interface DataUsage { + generatedAt: string; + database: { file: string; bytes: number; walBytes: number; pages: number; pageSize: number; freePages: number; freeBytes: number; tables: number }; + backups: { files: number; bytes: number }; + sessions: { files: number; bytes: number }; + totalBytes: number; + tables: TableUsage[]; + attention: { table: string; text: string }[]; +} + export type CoverageStatus = "ok" | "stale" | "failed" | "none" | "unknown"; /** One Proxmox guest and how well it is backed up. */ @@ -2393,6 +2438,11 @@ export const api = { setEnabled: (id: number, enabled: boolean) => request<{ webhook: EventWebhook }>(`/api/event-webhooks/${id}`, { method: "PATCH", body: JSON.stringify({ enabled }) }), remove: (id: number) => request(`/api/event-webhooks/${id}`, { method: "DELETE" }), test: (id: number) => request<{ ok: boolean; result: string }>(`/api/event-webhooks/${id}/test`, { method: "POST" }), + deliveries: (id: number) => request<{ deliveries: WebhookDelivery[] }>(`/api/event-webhooks/${id}/deliveries`), + retryDelivery: (id: number, deliveryId: number) => request<{ ok: boolean; result: string }>(`/api/event-webhooks/${id}/deliveries/${deliveryId}/retry`, { method: "POST" }), + }, + dataUsage: { + get: () => request("/api/data-usage"), }, updateRuns: { list: (serverId?: number) => request<{ runs: UpdateRun[] }>(`/api/update-runs${serverId ? `?serverId=${serverId}` : ""}`), diff --git a/web/src/pages/settings/ApiSettings.tsx b/web/src/pages/settings/ApiSettings.tsx index 390f06b..7cca943 100644 --- a/web/src/pages/settings/ApiSettings.tsx +++ b/web/src/pages/settings/ApiSettings.tsx @@ -8,6 +8,7 @@ import { readableError } from "../../utils/errors"; import { toast } from "../../utils/toast"; import ExportTableButton from "../../components/ExportTableButton"; import { EmptyRow, LoadingRow } from "../../components/EmptyState"; +import WebhookDeliveries from "./WebhookDeliveries"; const EVENT_WORDS: Record = { "alert.opened": "A problem begins", @@ -43,6 +44,7 @@ export default function ApiSettings() { const [hookEvents, setHookEvents] = useState>(new Set(["alert.opened", "alert.resolved"])); const [testResults, setTestResults] = useState>({}); const [busy, setBusy] = useState(false); + const [logOf, setLogOf] = useState(null); function load() { api.metricsTokens @@ -239,7 +241,7 @@ export default function ApiSettings() {

A webhook is sent a JSON message when something happens, for Home Assistant, n8n or a status board. This is separate from the chat-style webhook under Notifications, which carries the sentence a person would read. A problem is announced on the same terms as a - notification — one under maintenance isn't until it ends. If you give a secret, each message carries X-HLM-Signature: sha256=…, an HMAC of the body, so the receiver can tell it came from here. A failed delivery is tried once more. + notification — one under maintenance isn't until it ends. If you give a secret, each message carries X-HLM-Signature: sha256=…, an HMAC of the body, so the receiver can tell it came from here. A failed delivery is tried once more, and what was sent and how it went is kept under Sent — where a message can be sent again exactly as it was.

{adding && (
@@ -336,6 +338,9 @@ export default function ApiSettings() { + @@ -355,6 +360,7 @@ export default function ApiSettings() {
+ {logOf && setLogOf(null)} onChanged={load} />} ); } diff --git a/web/src/pages/settings/SettingsGroups.tsx b/web/src/pages/settings/SettingsGroups.tsx index d0459b2..6aaa81e 100644 --- a/web/src/pages/settings/SettingsGroups.tsx +++ b/web/src/pages/settings/SettingsGroups.tsx @@ -7,6 +7,7 @@ import BadgeSettings from "./BadgeSettings"; import BackupSettings from "./BackupSettings"; import LogSettings from "./LogSettings"; import CacheSettings from "./CacheSettings"; +import StorageSettings from "./StorageSettings"; // Settings used to have twelve tabs of its own. Three of them gather the ones that belong together; each part is the same page it always was, // switched by `?view=` (so it can be linked to, and the old addresses redirect here). @@ -47,11 +48,11 @@ export function DisplayGroup() { ); } -/** The upkeep of the app's own data: its backups, how long its logs are kept, and the DNS record cache. */ +/** The upkeep of the app's own data: its backups, how long its logs are kept, how big it all is, and the DNS record cache. */ export function DataGroup() { const [params] = useSearchParams(); const asked = params.get("view"); - const view = asked === "logs" || asked === "cache" ? asked : "backup"; + const view = asked === "logs" || asked === "cache" || asked === "storage" ? asked : "backup"; return ( <> - {view === "logs" ? : view === "cache" ? : } + {view === "logs" ? : view === "cache" ? : view === "storage" ? : } ); } diff --git a/web/src/pages/settings/StorageSettings.tsx b/web/src/pages/settings/StorageSettings.tsx new file mode 100644 index 0000000..d787338 --- /dev/null +++ b/web/src/pages/settings/StorageSettings.tsx @@ -0,0 +1,164 @@ +import { useEffect, useState } from "react"; +import { Link } from "react-router-dom"; +import { api, type DataUsage, type TableUsage, type UsageState } from "../../api/client"; +import TimeAgo from "../../components/TimeAgo"; +import { ErrorNotice } from "../../components/Notice"; +import { PageSkeleton } from "../../components/Skeleton"; +import { readableError } from "../../utils/errors"; + +export function formatBytes(bytes: number | null): string { + if (bytes === null) return "—"; + const units = ["B", "KB", "MB", "GB", "TB"]; + let value = bytes; + let unit = 0; + while (value >= 1024 && unit < units.length - 1) { + value /= 1024; + unit++; + } + return `${unit === 0 ? value : value.toFixed(value >= 100 ? 0 : 1)} ${units[unit]}`; +} + +const STATE_BADGE: Record = { + limit: { label: "trimmed", cls: "bg-green-lt text-green" }, + filling: { label: "filling up", cls: "bg-blue-lt text-blue" }, + not_trimmed: { label: "not trimmed", cls: "bg-red-lt text-red" }, + unlimited: { label: "no limit", cls: "bg-orange-lt text-orange" }, + plain: null, +}; + +const keepWords = (t: TableUsage) => (t.keepDays === null ? (t.state === "unlimited" ? "forever" : "—") : t.keepDays >= 365 ? `${Math.round((t.keepDays / 365) * 10) / 10} years` : `${t.keepDays} days`); + +const rate = (t: TableUsage) => (t.perDay === null ? "—" : t.perDay >= 10 ? Math.round(t.perDay).toLocaleString() : t.perDay.toLocaleString()); + +/** How big the app's own data is and whether what is meant to be trimmed is being trimmed: the files, then every table by the space it takes. */ +export default function StorageSettings() { + const [usage, setUsage] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(false); + const [showAll, setShowAll] = useState(false); + + function load() { + setLoading(true); + api.dataUsage + .get() + .then((u) => { + setUsage(u); + setError(null); + }) + .catch((err) => setError(readableError(err))) + .finally(() => setLoading(false)); + } + useEffect(load, []); + + if (!usage) return error ? : ; + + const biggest = Math.max(1, ...usage.tables.map((t) => t.bytes ?? t.rows)); + const shown = showAll ? usage.tables : usage.tables.filter((t) => t.state !== "plain" || (t.bytes ?? 0) >= 64 * 1024 || t.rows >= 500).slice(0, 25); + const db = usage.database; + + return ( + <> +
+

Storage

+ +
+ +

+ How much room the app's own data takes, and whether the histories that are meant to be trimmed are. Measured . +

+ + {usage.attention.length > 0 && ( +
+
+
{usage.attention.length === 1 ? "One history needs a look" : `${usage.attention.length} histories need a look`}
+
    + {usage.attention.map((a) => ( +
  • + {a.table} — {a.text} +
  • + ))} +
+
+
+ )} + +
+ {[ + { label: "In total", value: formatBytes(usage.totalBytes), sub: "database, backups and sessions" }, + { label: "Database", value: formatBytes(db.bytes + db.walBytes), sub: `${db.tables} tables${db.freeBytes > 0 ? `, ${formatBytes(db.freeBytes)} of it free` : ""}` }, + { label: "Backups", value: formatBytes(usage.backups.bytes), sub: `${usage.backups.files} ${usage.backups.files === 1 ? "file" : "files"}` }, + { label: "Sessions", value: formatBytes(usage.sessions.bytes), sub: `${usage.sessions.files} signed in ${usage.sessions.files === 1 ? "browser" : "browsers"}` }, + ].map((tile) => ( +
+
+
+
{tile.label}
+
{tile.value}
+
{tile.sub}
+
+
+
+ ))} +
+ +
+
+

What takes the room

+
+ +
+
+
+ + + + + + + + + + + + + + {shown.map((t) => { + const badge = t.rows === 0 && t.state === "limit" ? { label: "empty", cls: "bg-secondary-lt text-secondary" } : STATE_BADGE[t.state]; + return ( + + + + + + + + + + ); + })} + +
TableSizeRowsAdded a dayKeptReaches backTrimming
+ {t.name} + {t.note &&
{t.note}
} +
+ {formatBytes(t.bytes)} + {t.rows.toLocaleString()}{rate(t)}{keepWords(t)}{t.spanDays === null ? — : `${t.spanDays.toLocaleString()} days`} + {badge && {badge.label}} + {t.stateText && t.state !== "limit" &&
{t.stateText}
} +
+
+
+ Sizes count a table with its indexes. Space freed by trimming is reused by the next rows rather than handed back, so the file does not shrink on its own. How long the logs are kept is set under{" "} + Logs; the rest is fixed. +
+
+ + ); +} diff --git a/web/src/pages/settings/WebhookDeliveries.tsx b/web/src/pages/settings/WebhookDeliveries.tsx new file mode 100644 index 0000000..5500999 --- /dev/null +++ b/web/src/pages/settings/WebhookDeliveries.tsx @@ -0,0 +1,86 @@ +import { useEffect, useState } from "react"; +import { api, type EventWebhook, type WebhookDelivery } from "../../api/client"; +import DetailDrawer from "../../components/DetailDrawer"; +import EmptyState from "../../components/EmptyState"; +import TimeAgo from "../../components/TimeAgo"; +import { ErrorNotice } from "../../components/Notice"; +import { BlockSkeleton } from "../../components/Skeleton"; +import { readableError } from "../../utils/errors"; +import { toast } from "../../utils/toast"; + +const pretty = (body: string) => { + try { + return JSON.stringify(JSON.parse(body), null, 2); + } catch { + return body; + } +}; + +/** What was sent to one webhook lately and how each went, with the message itself and a button to send it again exactly as it was. */ +export default function WebhookDeliveries({ hook, onClose, onChanged }: { hook: EventWebhook; onClose: () => void; onChanged: () => void }) { + const [rows, setRows] = useState(null); + const [error, setError] = useState(null); + const [open, setOpen] = useState(null); + const [sending, setSending] = useState(null); + + function load() { + api.eventWebhooks + .deliveries(hook.id) + .then((r) => setRows(r.deliveries)) + .catch((err) => setError(readableError(err))); + } + useEffect(load, [hook.id]); + + async function retry(d: WebhookDelivery) { + setSending(d.id); + try { + const res = await api.eventWebhooks.retryDelivery(hook.id, d.id); + if (res.ok) toast.success(`Sent again — ${hook.label} answered ${res.result}.`); + else toast.error(`Sent again, but ${hook.label} answered ${res.result}.`); + load(); + onChanged(); + } catch (err) { + setError(readableError(err)); + } finally { + setSending(null); + } + } + + return ( + + + {rows === null && !error && } + {rows?.length === 0 && } +
+ {rows?.map((d) => ( +
+
+ {d.ok ? "delivered" : "failed"} + {d.event} + {d.result} + {d.attempts > 1 && tried twice} + {d.retryOf !== null && sent again by hand} + + + +
+
+ + +
+ {!d.retryable &&
This message was too large to keep, so it cannot be shown or sent again.
} + {open === d.id && d.body !== null && ( +
+                {pretty(d.body)}
+              
+ )} +
+ ))} +
+
+ ); +} diff --git a/web/src/utils/settingsIndex.ts b/web/src/utils/settingsIndex.ts index dbe4286..174fb55 100644 --- a/web/src/utils/settingsIndex.ts +++ b/web/src/utils/settingsIndex.ts @@ -48,9 +48,11 @@ export const SETTINGS_INDEX: SettingsEntry[] = [ // API and webhooks { title: "Metrics for Prometheus (tokens)", where: "API and webhooks", to: "/settings/api", words: "prometheus metrics token scrape grafana /metrics" }, { title: "Event webhooks", where: "API and webhooks", to: "/settings/api", words: "webhook event alert opened resolved maintenance hmac secret home assistant" }, + { title: "Webhook delivery log and retry", where: "API and webhooks", to: "/settings/api", words: "webhook deliveries delivery log history failed retry resend again sent receiver response" }, // Data { title: "Export and import configuration", where: "Data › Backup", to: "/settings/data", words: "backup export import configuration move restore database self backup" }, { title: "Log retention and purge", where: "Data › Logs", to: "/settings/data?view=logs", words: "logs purge retention diagnostic audit delete old days" }, + { title: "How big the app's data is, and what is kept how long", where: "Data › Storage", to: "/settings/data?view=storage", words: "storage size database disk space tables rows growing retention kept how long trimmed history wal backups sessions" }, { title: "DNS record cache", where: "Data › Cache", to: "/settings/data?view=cache", words: "dns cache clear zones records resync" }, ];