From 18ceed62e87b591415ee7f9ffd5d1387dd24387d Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Tue, 20 Oct 2026 21:47:56 +0200 Subject: [PATCH] Racks, notes and to-do, OS support, suggested dependencies, Nginx Proxy Manager and Home Assistant - Racks page and a network diagram (UniFi tree with servers, printable) - Notes on servers and devices; To do list shown in Coming up and My work - Agents report the operating system (Linux 7, Windows 6); end-of-life badge and alert - Suggested dependencies from where a service is reached - Nginx Proxy Manager integration: proxy hosts page, certificate and host alerts, suggested checks - Home Assistant integration: watch chosen entities, history chart, limit and unavailable alerts - TimeChart gets a "value" scale that fits negatives; docs updated Co-Authored-By: Claude Sonnet 5.5 --- API.md | 2 +- DATABASE.md | 78 +- INTEGRATIONS.md | 32 +- README.md | 27 + ROLES.md | 7 +- agent/linux/report-tasks.sh | 33 +- agent/windows/report-tasks.ps1 | 11 +- server/drizzle/0048_certain_bullseye.sql | 3 + server/drizzle/0049_condemned_warhawk.sql | 25 + server/drizzle/0050_useful_bulldozer.sql | 37 + server/drizzle/meta/0048_snapshot.json | 5023 +++++++++++++++ server/drizzle/meta/0049_snapshot.json | 5192 ++++++++++++++++ server/drizzle/meta/0050_snapshot.json | 5445 +++++++++++++++++ server/drizzle/meta/_journal.json | 21 + server/src/app.ts | 7 + server/src/db/schema.ts | 96 + server/src/index.ts | 2 + server/src/integrations/fieldSchemas.ts | 11 + .../src/integrations/homeassistant/adapter.ts | 91 + server/src/integrations/httpJson.ts | 62 + server/src/integrations/npm/adapter.ts | 145 + server/src/integrations/registry.ts | 6 + server/src/routes/dependencies.ts | 38 + server/src/routes/homeAssistant.ts | 137 + server/src/routes/integrations.ts | 4 + server/src/routes/inventory.ts | 7 + server/src/routes/npm.ts | 47 + server/src/routes/servers.ts | 4 +- server/src/routes/settings.ts | 2 +- server/src/routes/todos.ts | 92 + server/src/services/agenda.ts | 17 +- server/src/services/agentVersions.ts | 1 + server/src/services/alerts.ts | 68 +- server/src/services/changeLog.ts | 2 + server/src/services/dependencySuggestions.ts | 133 + server/src/services/endpointSuggestions.ts | 37 + server/src/services/homeAssistantSync.ts | 182 + server/src/services/myWork.ts | 21 +- server/src/services/notify.ts | 2 + server/src/services/npmReader.ts | 82 + server/src/services/osLifecycle.ts | 212 + server/src/services/publicApi.ts | 10 +- server/src/services/racks.ts | 95 + server/src/services/settingsStore.ts | 4 +- server/src/services/taskSync.ts | 4 + server/src/services/todos.ts | 190 + server/test/agentDiagnostics.test.ts | 4 +- server/test/dependencySuggestions.test.ts | 137 + server/test/npmAndHomeAssistant.test.ts | 415 ++ server/test/osLifecycle.test.ts | 140 + server/test/racks.test.ts | 59 + server/test/todosAndNotes.test.ts | 181 + server/test/windowsAgentHealth.test.ts | 2 +- web/src/App.tsx | 8 + web/src/api/client.ts | 161 +- web/src/components/CommandPalette.tsx | 2 + web/src/components/IntegrationEditForm.tsx | 2 + web/src/components/IntegrationForm.tsx | 2 + web/src/components/NetworkDiagram.tsx | 160 + web/src/components/NotesCard.tsx | 99 + web/src/components/TimeChart.tsx | 24 +- web/src/components/WallView.tsx | 2 + web/src/layout/nav.tsx | 6 + web/src/pages/ComingUp.tsx | 1 + web/src/pages/Dashboard.tsx | 2 +- web/src/pages/HomeAssistant.tsx | 400 ++ web/src/pages/Integrations.tsx | 4 + web/src/pages/Inventory.tsx | 3 + web/src/pages/InventoryRacks.tsx | 140 + web/src/pages/MyWork.tsx | 51 +- web/src/pages/NetworkDevices.tsx | 26 +- web/src/pages/ProxyHosts.tsx | 242 + web/src/pages/ServerDetail.tsx | 13 + web/src/pages/Todo.tsx | 320 + web/src/pages/settings/BadgeSettings.tsx | 2 + .../pages/settings/NotificationSettings.tsx | 11 +- web/src/views/DependencyEditor.tsx | 101 +- 77 files changed, 20432 insertions(+), 35 deletions(-) create mode 100644 server/drizzle/0048_certain_bullseye.sql create mode 100644 server/drizzle/0049_condemned_warhawk.sql create mode 100644 server/drizzle/0050_useful_bulldozer.sql create mode 100644 server/drizzle/meta/0048_snapshot.json create mode 100644 server/drizzle/meta/0049_snapshot.json create mode 100644 server/drizzle/meta/0050_snapshot.json create mode 100644 server/src/integrations/homeassistant/adapter.ts create mode 100644 server/src/integrations/httpJson.ts create mode 100644 server/src/integrations/npm/adapter.ts create mode 100644 server/src/routes/homeAssistant.ts create mode 100644 server/src/routes/npm.ts create mode 100644 server/src/routes/todos.ts create mode 100644 server/src/services/dependencySuggestions.ts create mode 100644 server/src/services/homeAssistantSync.ts create mode 100644 server/src/services/npmReader.ts create mode 100644 server/src/services/osLifecycle.ts create mode 100644 server/src/services/racks.ts create mode 100644 server/src/services/todos.ts create mode 100644 server/test/dependencySuggestions.test.ts create mode 100644 server/test/npmAndHomeAssistant.test.ts create mode 100644 server/test/osLifecycle.test.ts create mode 100644 server/test/racks.test.ts create mode 100644 server/test/todosAndNotes.test.ts create mode 100644 web/src/components/NetworkDiagram.tsx create mode 100644 web/src/components/NotesCard.tsx create mode 100644 web/src/pages/HomeAssistant.tsx create mode 100644 web/src/pages/InventoryRacks.tsx create mode 100644 web/src/pages/ProxyHosts.tsx create mode 100644 web/src/pages/Todo.tsx diff --git a/API.md b/API.md index 6412917..1f4b3f2 100644 --- a/API.md +++ b/API.md @@ -106,7 +106,7 @@ Authorization: Bearer hlm_p_… |---|---| | `GET /api/v1` | The list of these addresses. | | `GET /api/v1/me` | Whose token this is: the person's name and role, and the token's name and end. | -| `GET /api/v1/servers` | Every server: `status` (`online`, `offline`, `unknown`), `lastSeenAt`, `tags`, `ipAddresses`, `cpu`, `memory`, `disks` (with `usedPercent`), `updates`, `hardware`, `url`. Filter with `?tag=` and `?status=`. | +| `GET /api/v1/servers` | Every server: `status` (`online`, `offline`, `unknown`), `lastSeenAt`, `tags`, `ipAddresses`, `cpu`, `memory`, `disks` (with `usedPercent`), `updates`, `hardware`, `operatingSystem` (`name`, `version`, `endsOn`, `state`: `ok`, `soon`, `ended` or `unknown`, `daysLeft`; null until the agent says), `url`. Filter with `?tag=` and `?status=`. | | `GET /api/v1/servers/:id` | One server, the same shape. | | `GET /api/v1/servers/:id/metrics?days=` | Its load, memory and disks as lines of points, 1 to 365 days (7 by default). Points over more than 35 days are hours' or days' averages, with `lo` and `hi`. Disks also carry a `trend` and, when rising steadily, `daysToFull`. | | `GET /api/v1/alerts` | What is wrong now: `needingAttention` (critical, warning, acknowledged), `counts`, `couldntCheck`, and `alerts` with `severity`, `category`, `message`, `silenced`, `flapping`, `target`, `causedBy`, `acknowledgement` (who, when, note, until) and `url`. Filter with `?severity=`, `?category=`, `?acknowledged=true|false`, `?silenced=true|false`. | diff --git a/DATABASE.md b/DATABASE.md index 57a283c..a545c9b 100644 --- a/DATABASE.md +++ b/DATABASE.md @@ -61,6 +61,10 @@ erDiagram integrations ||--o{ network_devices : "cascade" integrations ||--o{ network_segments : "cascade" integrations ||--o{ network_server_links : "cascade" + integrations ||--o{ ha_watched : "cascade" + integrations ||--o{ ha_entities : "cascade" + integrations ||--o{ ha_readings : "cascade" + users ||--o{ todos : "assignee (set null)" servers ||--o{ network_server_links : "cascade" integration_credentials ||--o{ dns_providers : "credential (set null)" dns_providers ||--o{ dns_zones_cache : "cascade" @@ -74,7 +78,7 @@ erDiagram integrations ||--o{ alert_tickets : "osTicket used (set null)" ``` -Seventeen tables stand alone, with no foreign keys: `settings`, `secrets`, +Eighteen tables stand alone, with no foreign keys: `settings`, `notes`, `secrets`, `ipam_entries`, `domains`, `diag_log`, `notification_queue`, `consistency_ignores`, `tag_definitions`, `share_links`, `maintenance_schedules`, `metrics_tokens`, `event_webhooks`, `alert_incidents`, `dependencies`, `endpoint_checks`, `restore_tests`, `heartbeats`. `maintenance_windows` and `maintenance_aliases` also have no foreign key — see [soft references](#soft-references-not-foreign-keys). @@ -238,6 +242,7 @@ what it last reported. | `host_health` | text | JSON `{"failedUnits":[{unit,description}],"smart":[{device,model,healthy,temperatureC,wearPercent}],"zfs":[{name,health,capacityPercent}],"reportedAt":"…"}`. Each part is present only if the agent reported it, and a report that leaves one out leaves it as it was. Null until an agent says anything. Judged by the health check and shown on the server's page. | | `hw_manufacturer`, `hw_model`, `hw_serial` | text | What the machine is, as its firmware says (the agent reports it; placeholders like "To Be Filled By O.E.M." are left out). Each is replaced only when a report has a value, so an agent that can't tell doesn't wipe what it said. Used to fill in the inventory. | | `agent_diagnostics` | text | JSON `{"items":[{check,status,reason?,detail?}],"reportedAt":"…"}`: what the agent says it could not collect (`status` is `unavailable` or `failed`). Replaced by each report that carries the list (an empty list means nothing was missed) and kept when a report doesn't. Turned into words and fixes by the server; never sent to the browser as it is. | +| `os_id`, `os_name`, `os_version` | text | The operating system the agent reports: `os_id` is lower case (`ubuntu`, `debian`, `proxmox-ve`, `windows`…), `os_name` is what to show, `os_version` the release (a Windows build number on Windows). Replaced only by a report that says; null until then. The end-of-life dates are not stored: they are a table in the app. | | `agent_version` | integer | Which version of the agent script runs on it, as the agent says in each report. Null until it says; an agent that predates the number counts as version 1. Compared with the scripts the app serves to say which agents are behind. | #### `scheduled_tasks` @@ -471,6 +476,12 @@ JSON) plus a few internal bookkeeping rows. Details under Internal flag `unifiSync`: a JSON object keyed by integration id, `{ at (ISO — the last *successful* read), ok, error, sites, mode, devices, networks, ssids }`. A controller whose `at` is older than twenty minutes is not judged for offline devices. +Internal flag `homeAssistantSync`: a JSON object keyed by integration id, `{ at (ISO — the last *successful* read), ok, error, entities }`. A Home Assistant whose `at` is older than twenty minutes is not judged. + +Internal flag `dependencySuggestionsDismissed`: a JSON array of the suggestion keys (`integration:3>server:1`) somebody said *Not that* to. + +Setting `healthChecks.osSupportWarnDays` (default 90, 0–365): how many days before an operating system's end of support it is a warning. + Internal flag `flapState`: a JSON object keyed by alert key, `{ raises: number[] (epoch ms of raises in the last hour), flapping: boolean, since, lastEvent, message }`. It is what lets a restart remember which alerts are being held as flapping; entries are dropped once an alert has been calm for an hour. #### `tag_definitions` @@ -728,6 +739,71 @@ The networks (VLANs) and Wi-Fi names of a UniFi controller, replaced as a whole | `security`, `network_name` | text | A Wi-Fi name's security, and the network its clients land on. | | `updated_at` | text NOT NULL | ISO. | +#### `notes` + +A free-text note about a server or a network device. + +| Column | Type | Notes | +|---|---|---| +| `id` | integer PK | | +| `target_type`, `target_id` | text, integer NOT NULL | `server` or `device`, and its id. Unique together: one note each. Not a foreign key (a removed thing's note is ignored). | +| `body` | text NOT NULL | The text, with the small formatting runbooks use. Saving an empty one deletes the row. | +| `updated_by` | text | Who last saved it, as a name. | +| `updated_at` | text NOT NULL | ISO. | + +#### `todos` + +The small jobs of **Operations → To do**. + +| Column | Type | Notes | +|---|---|---| +| `id` | integer PK | | +| `title` | text NOT NULL | | +| `detail` | text | | +| `due_date` | text | `YYYY-MM-DD`. A job with a day, while open, is on the Coming up calendar. | +| `assignee_user_id` | integer → `users.id`, **set null** | Who it is handed to. | +| `assignee_name` | text | Their name when it was handed over, so it still reads if they are removed. | +| `target_type`, `target_id` | text, integer | `server` or `device`, and its id, when the job is about one. Not a foreign key. | +| `created_by`, `created_at` | text | | +| `done_at`, `done_by` | text | ISO and a name; null while open. | + +#### `ha_watched` + +The Home Assistant entities somebody chose to watch (see INTEGRATIONS.md). + +| Column | Type | Notes | +|---|---|---| +| `id` | integer PK | | +| `integration_id` | integer NOT NULL → `integrations.id`, **cascade** | The Home Assistant. Unique together with `entity_id`. | +| `entity_id` | text NOT NULL | `sensor.ups_battery`. | +| `name` | text | What to call it here; the entity's own friendly name when null. | +| `above`, `below` | real | Limits for a numeric value: an alert when it is over `above` or under `below`. | +| `created_at` | text NOT NULL | ISO. | + +#### `ha_entities` + +What the last read said about each watched entity. Primary key (`integration_id`, `entity_id`); `integration_id` is a foreign key with **cascade**. Rows of an entity no longer watched are removed on the next read. + +| Column | Type | Notes | +|---|---|---| +| `friendly_name`, `unit`, `device_class` | text | | +| `state` | text NOT NULL | As Home Assistant says it; `missing` when it is no longer in Home Assistant at all. | +| `value` | real | The state as a number, when it is one. | +| `last_changed` | text | ISO, from Home Assistant. | +| `unavailable_since` | text | ISO. When it was first seen `unavailable`, `unknown` or missing; kept until it speaks again. The alert counts from here. | +| `updated_at` | text NOT NULL | ISO. | + +#### `ha_readings` + +A numeric value of a watched entity at a moment, for the chart: one at most every two minutes, deleted after 35 days. `integration_id` is a foreign key with **cascade**; (`integration_id`, `entity_id`, `at`) is indexed. + +| Column | Type | Notes | +|---|---|---| +| `id` | integer PK | | +| `entity_id` | text NOT NULL | | +| `at` | text NOT NULL | ISO. | +| `value` | real NOT NULL | | + #### `push_subscriptions` A browser or phone that asked for push notifications, one row per device. diff --git a/INTEGRATIONS.md b/INTEGRATIONS.md index 15f12d4..4ea149b 100644 --- a/INTEGRATIONS.md +++ b/INTEGRATIONS.md @@ -6,10 +6,10 @@ Homelab Manager (Integrations → Add integration, or DNS → Add provider). All credentials are entered in-app and encrypted at rest — nothing is read from environment variables. -Every adapter listed here except UniFi performs write actions (starting/stopping +Every adapter listed here except UniFi, Nginx Proxy Manager and Home Assistant performs write actions (starting/stopping things, editing DNS records, etc.), not just reads — a read-only credential will fail as soon as you use one of those actions, even if -the dashboard views themselves load fine. (UniFi only ever reads.) +the dashboard views themselves load fine. (UniFi, Nginx Proxy Manager and Home Assistant only ever read.) ## Integrations @@ -248,6 +248,34 @@ the dashboard views themselves load fine. (UniFi only ever reads.) but nobody has run it against real hardware yet. Every field is read defensively, so one a version renames is left blank rather than breaking the read. If a read fails or comes back empty, the **Diagnostic Log** has what the controller answered; tell us and we'll adjust. +### Nginx Proxy Manager + +- **Config fields:** NPM's admin URL (the address of its web page, usually port 81), an email and a password, and a checkbox to allow a self-signed certificate. +- **Required access:** NPM has no API keys: its API is the one its own web page uses, so the app signs in with an email and password (each read signs in again; nothing is kept). Make a **dedicated user** under + *Users* and, under its *Permissions*, give it **View only** on *Proxy Hosts* and *SSL Certificates* — that is all that is read. **Nothing is ever written** to NPM. +- **What it does:** when **Network → Proxy hosts** is opened (and for the alerts and the suggested checks, at most once a minute) NPM is asked for its proxy hosts and certificates. Nothing is stored in the database: + what is shown is what NPM said a minute ago. + - Each host shows its names, where it forwards to — and the server that is, when the address (or name) is one of a server's own, exactly — its certificate and whether it is working. + - A certificate that an *enabled* host uses and that ends within 14 days (critical within 3) or has ended is an **expiry** alert; a host NPM says could not be set up (its nginx did not accept the configuration) + is a **monitoring** alert. A host that is switched off is left alone. Both link to the Proxy hosts page and can be silenced with maintenance on the integration. + - The hosts it serves are offered as **Endpoints → Suggested** checks (a web check on the name people use; https when there is a certificate), linked to the server it forwards to. + - If NPM cannot be read, the Alerts page says it could not check, and the integration is raised as failing like any other. +- **Not verified against a live NPM** — built from the API its own web page uses (`/api/tokens`, `/api/nginx/proxy-hosts?expand=certificate`, `/api/nginx/certificates`) and tried against a pretend one. Every + field is read defensively. If a read fails or comes back empty, the **Diagnostic Log** has what NPM answered. + +### Home Assistant + +- **Config fields:** Home Assistant's address (with the port, usually 8123), a long-lived access token, and a checkbox to allow a self-signed certificate. +- **Required access:** read only. Make the token on a user's profile page (*Security → Long-lived access tokens*); the user needs no more rights than a viewer's. Only `GET /api/` and `GET /api/states` are used — + **nothing is ever sent** to Home Assistant. +- **What it does:** you choose which entities to watch on **Monitoring → Home Assistant** (search by name, then *Watch*; at most 60 per Home Assistant). Every five minutes (and on **Read now**) Home Assistant's + entities are read in one call and the watched ones are kept: their state, and for a number a reading for the chart (one at most every two minutes, kept 35 days). + - An entity that has been *unavailable* or *unknown* — or has disappeared from Home Assistant — for 15 minutes is an alert. A number past a limit you set (*alert when under / over*) is an alert. Both are in the + *Monitoring* category, link to the page and can be silenced with maintenance on the integration. + - If Home Assistant cannot be read for twenty minutes the watched entities are neither raised nor cleared, the Alerts page says it could not check, and the integration is raised as failing like any other. + - A service reached at a server's address (the integration's URL) is offered as a suggested dependency on that server. +- **Not verified against a live Home Assistant** — built from its published REST API and tried against a pretend one. Every field is read defensively. If a read fails, the **Diagnostic Log** has what it answered. + ## DNS providers ### Cloudflare diff --git a/README.md b/README.md index 5fff9a9..926c468 100644 --- a/README.md +++ b/README.md @@ -853,6 +853,33 @@ what was there before (the earlier acknowledgement text, the earlier tags, the e - **Servers** (operators; press **Select** beside *Compare*): *Tag…* (add a tag to, or take one off, all of them), *Silence…* (maintenance, optionally with what depends on them too), and *Runs on…* (administrators — which server they run on, or back to working it out from Proxmox). - **Inventory** (operators): *Change where / dates…* (where it is, warranty until, end of support — each left as it is, set, or cleared) and *Print labels* for just those pieces. +**Operating-system support.** The agents now report which operating system a server runs (Linux agent 7, Windows agent 6; re-run the install one-liner to update). A server's page shows it in a *System* row with a +badge — *supported*, *ends in N days* or *support ended* — worked out from a table of end-of-life dates for Ubuntu, Debian, CentOS, RHEL and its rebuilds, Fedora, Alpine, openSUSE Leap, Proxmox VE and Windows +(client and server). A server whose system is past its end, or ends within **Settings → Notifications → *Flag an operating system whose support ends within*** (90 days; 0 turns it off) is on the Alerts page in the *Updates* category with a link to the server — a warning once +support has ended, a note while it is only coming. The dates are a static table in the app, not looked up: a release it does not know is shown without a badge, never guessed at. The read API gives it as `operatingSystem`. + +**Suggested dependencies.** Under **Map → Dependencies**, a *Suggested* card offers what the app can work out without being told: a service (Gitea, Semaphore, Uptime Kuma, phpIPAM, Home Assistant…) that is reached at a +server's own address most likely runs there, so it needs that server. *Add* writes it as an ordinary dependency; *Not that* hides the suggestion (*Show the N you said no to* brings them back). Nothing is written until you add it. + +**Notes and a to-do list.** Every server's page has a *Notes* card, and every network device a *Notes* button (operators), for what is worth remembering: free text with the same small formatting as runbooks +(bold, lists, links). **Operations → To do** is a list of the small jobs — "replace the UPS battery", "move the NAS to the new switch" — each with a day it is due, a person it is handed to and a server or device it is +about. A job with a day shows in **Coming up**, a job handed to someone in their **My work** (and its badge), and ticking it off, editing and removing it go in the change log. Operators and administrators write, +everyone signed in reads. + +**Racks and a network diagram.** **Inventory → Racks** draws each rack from the hardware's *where* (the rack's name) and *rack unit* ("U12", or "U12-13" for a tall piece), from the bottom up, with the units used, +the power drawn and a piece that clashes with another in red; hardware that names a rack but no unit is listed beside it. It can be printed. **Network devices → Diagram** draws the UniFi gateway, switches and access +points as a tree by what each is connected through, with the servers plugged into each, a red box for a device that is down, and a *Print* button. + +**Nginx Proxy Manager.** Add it under Integrations (a user that may only *view* proxy hosts and certificates is enough; see INTEGRATIONS.md) and **Network → Proxy hosts** lists each name it serves, where it forwards to +(and which server that is, when the address is one the app knows), its certificate and whether NPM could set the host up. A certificate in use that ends within 14 days (critical in the last three), or has ended, and a +host NPM itself says is not working, are alerts; a host that is switched off is left alone. The hosts it serves are also offered as endpoint checks (Endpoints → Suggested) on the name people really use, linked to the +server it forwards to. It only reads. + +**Home Assistant.** Add it under Integrations with a long-lived access token (made at the bottom of your profile page in Home Assistant). **Monitoring → Home Assistant** is where you *choose* the few entities worth an +alert — a UPS battery, a freezer's temperature, a pump — not all of them. Each is read every five minutes; a number keeps a history (35 days, with a chart), and you can set a limit under and/or over which it is an alert. +An entity that has been *unavailable* (or has gone missing) for 15 minutes is an alert too. If Home Assistant cannot be read for twenty minutes its entities are neither raised nor cleared, and the Alerts page says it +could not check. Nothing is ever sent to Home Assistant. Neither integration has been tried against the real thing — see INTEGRATIONS.md. + **Ports** — each server's detail page has a Ports card for finding free ports and remembering what each one is for. "Scan…" runs a TCP scan of a port range from the app against the server's address (private addresses only, up to diff --git a/ROLES.md b/ROLES.md index 58fc099..8bdba8e 100644 --- a/ROLES.md +++ b/ROLES.md @@ -104,7 +104,12 @@ even further, to admin only: **Settings search** is part of Settings, which is administrators'. - **Network devices** (Network → Network devices): everyone can see the devices, networks and Wi-Fi names read from UniFi controllers; **Read now** and putting a device under maintenance need operator; adding the UniFi integration itself (a key or login) is an administrator's job, like any integration. -- **Dependencies**: everyone can see what needs what; adding and removing one needs operator. +- **Dependencies**: everyone can see what needs what; adding and removing one needs operator. So does adding or hiding a *suggested* one. +- **To do and Notes** (Operations → To do, a server's *Notes*, a device's *Notes*): everyone signed in reads them; adding, editing, ticking off and removing a job, and writing a note, need operator. +- **Racks** (Inventory → Racks) and the **network diagram**: everyone signed in. A rack is made from the hardware's *where* and *rack unit*, which operators edit on the inventory page. +- **Proxy hosts** (Network → Proxy hosts): everyone signed in sees what Nginx Proxy Manager serves; **Read now** needs operator; adding the integration (its login) is an administrator's job. +- **Home Assistant** (Monitoring → Home Assistant): everyone signed in sees what is watched, its state and history; choosing what to watch, its limits, stopping and **Read now** need operator (the list of all + entities is read live, so only operators see it); adding the integration (its token) is an administrator's job. - **Endpoints**: everyone sees the checks and how they are doing; adding, changing and removing one is administrator-only (each makes the server connect somewhere); *Check now* needs operator. - **Restore tests**: everyone sees them on the Backup coverage page; recording one needs operator; removing one is administrator-only. diff --git a/agent/linux/report-tasks.sh b/agent/linux/report-tasks.sh index 2913ea4..64ba997 100644 --- a/agent/linux/report-tasks.sh +++ b/agent/linux/report-tasks.sh @@ -17,7 +17,7 @@ set -euo pipefail # 4 = also reports failed services, disk health (SMART) and ZFS pools, reads pacman, and can update itself when told to # 5 = also says what the machine is (maker, model, serial number), from the firmware, for the inventory # 6 = also says what it could not collect and why (no smartctl, no systemd, a package manager that failed ...), so the server can say what to fix -AGENT_VERSION=6 +AGENT_VERSION=7 ENV_FILE="${ENV_FILE:-/etc/homelab-manager-agent.env}" if [[ -f "$ENV_FILE" ]]; then @@ -356,6 +356,30 @@ collect_hardware() { '{} | (if $maker != "" then . + {manufacturer: $maker} else . end) | (if $model != "" then . + {model: $model} else . end) | (if $serial != "" then . + {serial: $serial} else . end)') || HARDWARE_JSON="null" } +# What the machine runs, as /etc/os-release says (OS_RELEASE_FILE is for the tests): the distribution's id and version, so the app can say when that release stops +# being supported. Proxmox VE is Debian underneath, so it is asked by its own command. "null" when there is nothing to say. +collect_os() { + OS_JSON="null" + local file="${OS_RELEASE_FILE:-/etc/os-release}" id="" version="" pretty="" + if [[ -r "$file" ]]; then + id=$(sed -n 's/^ID=//p' "$file" | head -n 1 | tr -d '"' | tr 'A-Z' 'a-z' | head -c 40) + version=$(sed -n 's/^VERSION_ID=//p' "$file" | head -n 1 | tr -d '"' | head -c 40) + pretty=$(sed -n 's/^PRETTY_NAME=//p' "$file" | head -n 1 | tr -d '"' | head -c 80) + fi + if command -v pveversion >/dev/null 2>&1; then + local pve + pve=$(pveversion 2>/dev/null | sed -n 's#^pve-manager/\([0-9]*\.[0-9]*\).*#\1#p' | head -n 1) + if [[ -n "$pve" ]]; then + id="proxmox-ve" + version="$pve" + pretty="Proxmox VE $pve" + fi + fi + [[ -n "$id" ]] || return 0 + OS_JSON=$(jq -n -c --arg id "$id" --arg version "$version" --arg name "$pretty" \ + '{id: $id} | (if $version != "" then . + {version: $version} else . end) | (if $name != "" then . + {name: $name} else . end)') || OS_JSON="null" +} + # Services (systemd units) that have failed. systemctl is asked the way the timers are, so this works inside the sandbox. collect_failed_units() { FAILED_UNITS_JSON="null" @@ -604,6 +628,8 @@ collect_system_info() { fi HARDWARE_JSON="null" collect_hardware || HARDWARE_JSON="null" + OS_JSON="null" + collect_os || OS_JSON="null" collect_diagnostics HEALTH_JSON=$(jq -n -c --argjson failed "$FAILED_UNITS_JSON" --argjson smart "$SMART_JSON" --argjson zfs "$ZFS_JSON" \ '{} | (if $failed != null then . + {failed_units: $failed} else . end) | (if $smart != null then . + {smart: $smart} else . end) | (if $zfs != null then . + {zfs: $zfs} else . end)') || HEALTH_JSON="{}" @@ -613,6 +639,7 @@ collect_system_info() { --argjson updates "$UPDATES_JSON" \ --argjson health "$HEALTH_JSON" \ --argjson hardware "$HARDWARE_JSON" \ + --argjson os "$OS_JSON" \ --argjson diagnostics "$DIAGNOSTICS_JSON" \ --argjson ip_addresses "$ip_json" \ --argjson listening_ports "$ports_json" \ @@ -631,6 +658,7 @@ collect_system_info() { updates: $updates, health: $health, hardware: $hardware, + os: $os, diagnostics: $diagnostics }') } @@ -652,6 +680,9 @@ if [[ "$MODE" != "report" ]]; then echo "ZFS pools (null means there is no zpool here):" jq . <<<"$ZFS_JSON" collect_hardware || true + collect_os || true + echo "What it runs (null means there is no os-release to read):" + jq . <<<"$OS_JSON" echo "What could not be collected (empty means nothing was missed):" diag_json | jq . self_update diff --git a/agent/windows/report-tasks.ps1 b/agent/windows/report-tasks.ps1 index 0482133..e792e34 100644 --- a/agent/windows/report-tasks.ps1 +++ b/agent/windows/report-tasks.ps1 @@ -36,7 +36,7 @@ $ErrorActionPreference = 'Stop' # 3 = can replace itself with the newer script when an administrator has switched that on in Homelab Manager # 4 = also reports services that have failed, disk health, Storage Spaces pools and what the machine is (maker, model, serial) # 5 = also says what it could not collect and why, so Homelab Manager can say what to fix -$script:AgentVersion = 5 +$script:AgentVersion = 6 $script:DefaultConfigPath = Join-Path $env:ProgramData 'HomelabManager\agent.json' @@ -451,10 +451,19 @@ function Get-SystemInfo($Config = $null) { if (-not $hardware) { Add-Diag 'hardware' 'unavailable' 'not_found' } } catch { Write-Warning "Reading the hardware identity failed. ($($_.Exception.Message))"; Add-Diag 'hardware' 'failed' 'error' $_.Exception.Message } + # What it runs, so the app can say when that release stops being supported: the product's name and its build number (a build is one release of Windows). + # Best-effort and silent: nothing here is worth a note of its own. + $osInfo = $null + try { + $caption = ([string]$os.Caption) -replace '^Microsoft\s+', '' + if ($caption.Trim() -and $os.BuildNumber) { $osInfo = [ordered]@{ id = 'windows'; name = $caption.Trim(); version = [string]$os.BuildNumber } } + } catch { } + return [ordered]@{ updates = $updates health = $health hardware = $hardware + os = $osInfo diagnostics = @($script:Diag) ip_addresses = @($ips) cpu = [ordered]@{ model = [string]($cpus[0].Name).Trim(); cores = [int]$cores; load_percent = $(if ($null -ne $load) { [math]::Round([double]$load, 1) } else { $null }) } diff --git a/server/drizzle/0048_certain_bullseye.sql b/server/drizzle/0048_certain_bullseye.sql new file mode 100644 index 0000000..e27f2e5 --- /dev/null +++ b/server/drizzle/0048_certain_bullseye.sql @@ -0,0 +1,3 @@ +ALTER TABLE `servers` ADD `os_id` text;--> statement-breakpoint +ALTER TABLE `servers` ADD `os_name` text;--> statement-breakpoint +ALTER TABLE `servers` ADD `os_version` text; \ No newline at end of file diff --git a/server/drizzle/0049_condemned_warhawk.sql b/server/drizzle/0049_condemned_warhawk.sql new file mode 100644 index 0000000..efb0952 --- /dev/null +++ b/server/drizzle/0049_condemned_warhawk.sql @@ -0,0 +1,25 @@ +CREATE TABLE `notes` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `target_type` text NOT NULL, + `target_id` integer NOT NULL, + `body` text NOT NULL, + `updated_by` text, + `updated_at` text NOT NULL +); +--> statement-breakpoint +CREATE UNIQUE INDEX `notes_target_idx` ON `notes` (`target_type`,`target_id`);--> statement-breakpoint +CREATE TABLE `todos` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `title` text NOT NULL, + `detail` text, + `due_date` text, + `assignee_user_id` integer, + `assignee_name` text, + `target_type` text, + `target_id` integer, + `created_by` text, + `created_at` text NOT NULL, + `done_at` text, + `done_by` text, + FOREIGN KEY (`assignee_user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null +); diff --git a/server/drizzle/0050_useful_bulldozer.sql b/server/drizzle/0050_useful_bulldozer.sql new file mode 100644 index 0000000..916b432 --- /dev/null +++ b/server/drizzle/0050_useful_bulldozer.sql @@ -0,0 +1,37 @@ +CREATE TABLE `ha_entities` ( + `integration_id` integer NOT NULL, + `entity_id` text NOT NULL, + `friendly_name` text, + `state` text NOT NULL, + `value` real, + `unit` text, + `device_class` text, + `last_changed` text, + `unavailable_since` text, + `updated_at` text NOT NULL, + PRIMARY KEY(`integration_id`, `entity_id`), + FOREIGN KEY (`integration_id`) REFERENCES `integrations`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `ha_readings` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `integration_id` integer NOT NULL, + `entity_id` text NOT NULL, + `at` text NOT NULL, + `value` real NOT NULL, + FOREIGN KEY (`integration_id`) REFERENCES `integrations`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE INDEX `ha_readings_lookup_idx` ON `ha_readings` (`integration_id`,`entity_id`,`at`);--> statement-breakpoint +CREATE TABLE `ha_watched` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `integration_id` integer NOT NULL, + `entity_id` text NOT NULL, + `name` text, + `above` real, + `below` real, + `created_at` text NOT NULL, + FOREIGN KEY (`integration_id`) REFERENCES `integrations`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `ha_watched_unique` ON `ha_watched` (`integration_id`,`entity_id`); \ No newline at end of file diff --git a/server/drizzle/meta/0048_snapshot.json b/server/drizzle/meta/0048_snapshot.json new file mode 100644 index 0000000..92ed4da --- /dev/null +++ b/server/drizzle/meta/0048_snapshot.json @@ -0,0 +1,5023 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "ded18f22-f557-45dd-ad13-6fdde437772d", + "prevId": "b7891424-e6eb-47a3-9166-2f72e36c1a78", + "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_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": {} + }, + "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": {} + }, + "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": {} + }, + "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": {} + }, + "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": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/server/drizzle/meta/0049_snapshot.json b/server/drizzle/meta/0049_snapshot.json new file mode 100644 index 0000000..8e38f2c --- /dev/null +++ b/server/drizzle/meta/0049_snapshot.json @@ -0,0 +1,5192 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "dfa57544-8b4f-4f79-a557-477eca70f061", + "prevId": "ded18f22-f557-45dd-ad13-6fdde437772d", + "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_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": {} + }, + "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": {} + }, + "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": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/server/drizzle/meta/0050_snapshot.json b/server/drizzle/meta/0050_snapshot.json new file mode 100644 index 0000000..442351a --- /dev/null +++ b/server/drizzle/meta/0050_snapshot.json @@ -0,0 +1,5445 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "0f52ff16-362d-476e-a1cb-6ccaaf965f5c", + "prevId": "dfa57544-8b4f-4f79-a557-477eca70f061", + "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_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": {} + }, + "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": {} + } + }, + "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 1bf9c01..1b84802 100644 --- a/server/drizzle/meta/_journal.json +++ b/server/drizzle/meta/_journal.json @@ -337,6 +337,27 @@ "when": 1792519188097, "tag": "0047_eager_dorian_gray", "breakpoints": true + }, + { + "idx": 48, + "version": "6", + "when": 1792522721690, + "tag": "0048_certain_bullseye", + "breakpoints": true + }, + { + "idx": 49, + "version": "6", + "when": 1792523247340, + "tag": "0049_condemned_warhawk", + "breakpoints": true + }, + { + "idx": 50, + "version": "6", + "when": 1792523816802, + "tag": "0050_useful_bulldozer", + "breakpoints": true } ] } \ No newline at end of file diff --git a/server/src/app.ts b/server/src/app.ts index 6bd143c..73ed27d 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -48,6 +48,9 @@ import { mapRouter } from "./routes/map.js"; import { networkRouter } from "./routes/network.js"; import { myWorkRouter } from "./routes/myWork.js"; import { apiTokensRouter } from "./routes/apiTokens.js"; +import { notesRouter, todosRouter } from "./routes/todos.js"; +import { npmRouter } from "./routes/npm.js"; +import { homeAssistantRouter } from "./routes/homeAssistant.js"; import { publicApiRouter } from "./routes/publicApi.js"; import { generatorRouter } from "./routes/generator.js"; import { alertTicketsRouter } from "./routes/alertTickets.js"; @@ -170,6 +173,10 @@ export function createApp() { app.use("/api/map", mapRouter); app.use("/api/network", networkRouter); app.use("/api/my-work", myWorkRouter); + app.use("/api/npm", npmRouter); + app.use("/api/home-assistant", homeAssistantRouter); + app.use("/api/todos", todosRouter); + app.use("/api/notes", notesRouter); app.use("/api/generator", generatorRouter); app.use("/api/alert-tickets", alertTicketsRouter); diff --git a/server/src/db/schema.ts b/server/src/db/schema.ts index 5c32d61..b439b68 100644 --- a/server/src/db/schema.ts +++ b/server/src/db/schema.ts @@ -471,6 +471,12 @@ export const servers = sqliteTable("servers", { // not in this list, and not noted on the Ports page, is a "new port" (services/newPorts.ts). Null until the first report that carries ports. portBaseline: text("port_baseline"), + // What the machine runs, as its agent says (agent 7 and later): the distribution's id ("ubuntu", "debian", "proxmox-ve", "windows"), its pretty name and its release + // (for Windows, the build number). What services/osLifecycle.ts works out when its support ends from. + osId: text("os_id"), + osName: text("os_name"), + osVersion: text("os_version"), + // What the machine is, as its firmware says (agents report it): maker, model and serial number. Used to fill in the inventory. hwManufacturer: text("hw_manufacturer"), hwModel: text("hw_model"), @@ -536,6 +542,8 @@ export const integrationTypes = [ "pbs", "osticket", "unifi", + "npm", + "homeassistant", ] as const; export type IntegrationType = (typeof integrationTypes)[number]; @@ -1088,6 +1096,94 @@ export const metricsTokens = sqliteTable("metrics_tokens", { lastUsedAt: text("last_used_at"), // ISO }); +// ─── Home Assistant: the few things somebody chose to watch ───────────────── + +// An entity (a sensor, a binary sensor, a battery, a UPS) that somebody chose to watch on a Home Assistant integration, and the limits that make it an alert. +export const haWatched = sqliteTable( + "ha_watched", + { + id: integer("id").primaryKey({ autoIncrement: true }), + integrationId: integer("integration_id") + .notNull() + .references(() => integrations.id, { onDelete: "cascade" }), + entityId: text("entity_id").notNull(), // "sensor.ups_battery" + name: text("name"), // what to call it here; the entity's own friendly name when null + above: real("above"), // an alert when a numeric value is above this + below: real("below"), // …or below this + createdAt: text("created_at").notNull(), + }, + (t) => [uniqueIndex("ha_watched_unique").on(t.integrationId, t.entityId)], +); + +// What the last read said about each watched entity. `unavailableSince` is when it was first seen "unavailable" or "unknown", kept until it is not. +export const haEntities = sqliteTable( + "ha_entities", + { + integrationId: integer("integration_id") + .notNull() + .references(() => integrations.id, { onDelete: "cascade" }), + entityId: text("entity_id").notNull(), + friendlyName: text("friendly_name"), + state: text("state").notNull(), + value: real("value"), // the state as a number, when it is one + unit: text("unit"), + deviceClass: text("device_class"), + lastChanged: text("last_changed"), + unavailableSince: text("unavailable_since"), + updatedAt: text("updated_at").notNull(), + }, + (t) => [primaryKey({ columns: [t.integrationId, t.entityId] })], +); + +// A numeric value of a watched entity at a moment, for the chart: one every few minutes, kept 35 days. +export const haReadings = sqliteTable( + "ha_readings", + { + id: integer("id").primaryKey({ autoIncrement: true }), + integrationId: integer("integration_id") + .notNull() + .references(() => integrations.id, { onDelete: "cascade" }), + entityId: text("entity_id").notNull(), + at: text("at").notNull(), // ISO + value: real("value").notNull(), + }, + (t) => [index("ha_readings_lookup_idx").on(t.integrationId, t.entityId, t.at)], +); + +// ─── Notes and the to-do list ─────────────────────────────────────────────── + +// Free-form notes about a server or a network device — what is it, where does it sit, what did I do to it last time — one text per thing, drawn with the same small +// formatting as a runbook. Polymorphic like runbooks and maintenance windows, so no foreign key: the note of something removed is simply not shown. +export const notes = sqliteTable( + "notes", + { + id: integer("id").primaryKey({ autoIncrement: true }), + targetType: text("target_type").$type<"server" | "device">().notNull(), + targetId: integer("target_id").notNull(), + body: text("body").notNull(), + updatedBy: text("updated_by"), + updatedAt: text("updated_at").notNull(), // ISO + }, + (t) => [uniqueIndex("notes_target_idx").on(t.targetType, t.targetId)], +); + +// Things to do: the small jobs of a homelab ("replace the UPS battery", "move the NAS to the new switch"), with a day they are due and optionally a person and +// a thing they are about. Open ones with a due day are in Coming up; the ones handed to someone are in My work. +export const todos = sqliteTable("todos", { + id: integer("id").primaryKey({ autoIncrement: true }), + title: text("title").notNull(), + detail: text("detail"), + dueDate: text("due_date"), // YYYY-MM-DD + assigneeUserId: integer("assignee_user_id").references(() => users.id, { onDelete: "set null" }), + assigneeName: text("assignee_name"), // as it was when handed over, so it still reads if the person is removed + targetType: text("target_type").$type<"server" | "device">(), + targetId: integer("target_id"), + createdBy: text("created_by"), + createdAt: text("created_at").notNull(), // ISO + doneAt: text("done_at"), // ISO; null while open + doneBy: text("done_by"), +}); + // ─── Personal API tokens: read-only access to /api/v1 for scripts and Home Assistant ───── // One person's own: made by them, shown to them once, and gone when they are. Only a hash of the secret is kept. A token only ever reads (the API has no other verbs), diff --git a/server/src/index.ts b/server/src/index.ts index fce68ab..a457782 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -25,6 +25,7 @@ import { initEndpointMonitor } from "./services/endpointMonitor.js"; import { initPatchPlans } from "./services/patchPlans.js"; import { initFlapMonitor } from "./services/flapMonitor.js"; import { initUnifiSync } from "./services/unifiSync.js"; +import { initHomeAssistantSync } from "./services/homeAssistantSync.js"; import { backfillMetricRollups } from "./services/serverMetrics.js"; import { backfillEndpointHourly } from "./services/endpointChecks.js"; import { initSelfBackupScheduler } from "./services/selfBackupScheduler.js"; @@ -71,6 +72,7 @@ initEndpointMonitor(); initPatchPlans(); initFlapMonitor(); initUnifiSync(); +initHomeAssistantSync(); // The hourly and daily figures are built from what is already kept, once, the first time after they were added (in the background: nothing waits for it). void Promise.all([backfillMetricRollups(), backfillEndpointHourly()]).catch((err) => console.error("[history] couldn't build the hourly and daily figures:", err)); diff --git a/server/src/integrations/fieldSchemas.ts b/server/src/integrations/fieldSchemas.ts index 995c067..e76efec 100644 --- a/server/src/integrations/fieldSchemas.ts +++ b/server/src/integrations/fieldSchemas.ts @@ -88,6 +88,17 @@ export const INTEGRATION_FIELDS: Partial; + listEntities(): Promise; +} + +const obj = (v: unknown): Record => (v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Record) : {}); +const str = (v: unknown): string | null => (typeof v === "string" && v.trim() !== "" ? v.trim() : null); + +export function entityFrom(raw: unknown): HaEntity | null { + const e = obj(raw); + const entityId = str(e.entity_id); + if (!entityId) return null; + const attrs = obj(e.attributes); + const state = typeof e.state === "string" ? e.state : e.state === null || e.state === undefined ? "unknown" : String(e.state); + const n = state.trim() === "" ? NaN : Number(state); + const changed = str(e.last_changed); + return { + entityId, + name: str(attrs.friendly_name) ?? entityId, + state, + value: Number.isFinite(n) ? n : null, + unit: str(attrs.unit_of_measurement), + deviceClass: str(attrs.device_class), + lastChanged: changed && Number.isFinite(Date.parse(changed)) ? new Date(changed).toISOString() : null, + unavailable: state === "unavailable" || state === "unknown", + }; +} + +export function createHomeAssistantAdapter(config: HomeAssistantConfig): HomeAssistantAdapter { + const base = config.url.replace(/\/+$/, ""); + const insecure = config.insecure === true; + + async function get(path: string): Promise { + const res = await requestJson(`${base}${path}`, { headers: { Authorization: `Bearer ${config.token}` }, insecure }); + if (res.status === 401 || res.status === 403) throw new Error("Home Assistant did not accept the token (HTTP " + res.status + ")"); + if (res.status === 404) throw new Error("Home Assistant has no REST API at this address — check the address and port (8123), and that the api integration is on"); + if (res.status < 200 || res.status >= 300) throw new Error(`Home Assistant error: HTTP ${res.status}`); + if (res.json === null) throw new Error("Home Assistant answered with something that isn't JSON — is the address its own?"); + return res.json; + } + + async function listEntities(): Promise { + const states = await get("/api/states"); + return (Array.isArray(states) ? states : []).map(entityFrom).filter((e): e is HaEntity => e !== null); + } + + async function ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }> { + const start = Date.now(); + try { + await get("/api/"); + return { ok: true, latencyMs: Date.now() - start }; + } catch (err) { + return { ok: false, error: err instanceof Error ? err.message : String(err) }; + } + } + + return withDiagLogging("homeassistant", { ping, listEntities }); +} diff --git a/server/src/integrations/httpJson.ts b/server/src/integrations/httpJson.ts new file mode 100644 index 0000000..8c8db5b --- /dev/null +++ b/server/src/integrations/httpJson.ts @@ -0,0 +1,62 @@ +/** + * One small way to ask a web API for JSON, for the integrations that speak plain HTTP: a method, headers, an optional JSON body, a timeout, and — for a controller with a + * certificate of its own — a way to accept it. Answers with the status and what was said, parsed if it was JSON; a refused connection or a timeout throws. + */ +import * as http from "node:http"; +import * as https from "node:https"; + +export interface JsonResponse { + status: number; + json: unknown; + text: string; + headers: http.IncomingHttpHeaders; +} + +const TIMEOUT_MS = 15_000; + +export function requestJson(url: string, opts: { method?: "GET" | "POST"; headers?: Record; body?: unknown; insecure?: boolean; timeoutMs?: number } = {}): Promise { + return new Promise((resolve, reject) => { + let parsed: URL; + try { + parsed = new URL(url); + } catch { + return reject(new Error(`"${url}" is not a web address`)); + } + if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return reject(new Error("The address must start with http:// or https://")); + const isHttps = parsed.protocol === "https:"; + const lib = isHttps ? https : http; + const payload = opts.body === undefined ? null : JSON.stringify(opts.body); + const limit = opts.timeoutMs ?? TIMEOUT_MS; + const req = lib.request( + { + hostname: parsed.hostname, + port: parsed.port || (isHttps ? 443 : 80), + path: parsed.pathname + parsed.search, + method: opts.method ?? "GET", + headers: { Accept: "application/json", ...(payload ? { "Content-Type": "application/json", "Content-Length": String(Buffer.byteLength(payload)) } : {}), ...opts.headers }, + timeout: limit, + ...(isHttps ? { rejectUnauthorized: !opts.insecure } : {}), + }, + (res) => { + let text = ""; + res.setEncoding("utf8"); + res.on("data", (chunk) => { + text += chunk; + }); + res.on("end", () => { + let json: unknown = null; + try { + json = text ? JSON.parse(text) : null; + } catch { + // not JSON: the text is still there + } + resolve({ status: res.statusCode ?? 0, json, text, headers: res.headers }); + }); + }, + ); + req.on("timeout", () => req.destroy(new Error(`timed out after ${limit / 1000}s`))); + req.on("error", reject); + if (payload) req.write(payload); + req.end(); + }); +} diff --git a/server/src/integrations/npm/adapter.ts b/server/src/integrations/npm/adapter.ts new file mode 100644 index 0000000..312787c --- /dev/null +++ b/server/src/integrations/npm/adapter.ts @@ -0,0 +1,145 @@ +/** + * Nginx Proxy Manager adapter. + * Requires config: url, email, password; optional: insecure + * + * NPM has no API keys: its API is the one its own web page uses, and signs in with the administrator's email and password (`POST /api/tokens` answers with a bearer + * token, which the rest take). So this logs in for each read — and only ever reads: the proxy hosts (what is proxied to what, with its certificate) and the + * certificates. Use a dedicated user with the "view only" permission on proxy hosts and certificates (Users → Permissions) rather than the administrator's own. + * + * Endpoints and field names are from NPM's own API as the web page uses it (`/api/nginx/proxy-hosts?expand=certificate`, `/api/nginx/certificates`), and have + * not been checked against a live NPM here; every field is read defensively, so one a version renames is left blank rather than breaking the read. + */ +import { requestJson } from "../httpJson.js"; +import { withDiagLogging } from "../../services/diagLog.js"; + +export interface NpmConfig { + url: string; + email: string; + password: string; + insecure?: boolean; +} + +export interface NpmCertificate { + id: number; + name: string; + provider: string; + domains: string[]; + /** ISO, or null when NPM does not say. */ + expiresAt: string | null; +} + +export interface NpmProxyHost { + id: number; + domains: string[]; + forwardScheme: string; + forwardHost: string; + forwardPort: number | null; + enabled: boolean; + sslForced: boolean; + certificate: { id: number; name: string; expiresAt: string | null } | null; + /** NPM says its nginx did not accept this host's configuration. */ + online: boolean; + error: string | null; +} + +export interface NpmSnapshot { + version: string | null; + hosts: NpmProxyHost[]; + certificates: NpmCertificate[]; +} + +export interface NpmAdapter { + ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }>; + fetchSnapshot(): Promise; +} + +const obj = (v: unknown): Record => (v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Record) : {}); +const str = (v: unknown): string | null => (typeof v === "string" && v.trim() !== "" ? v.trim() : null); +const num = (v: unknown): number | null => { + const n = typeof v === "number" ? v : typeof v === "string" && v.trim() !== "" ? Number(v) : NaN; + return Number.isFinite(n) ? n : null; +}; +const domainsOf = (v: unknown): string[] => (Array.isArray(v) ? v.filter((d): d is string => typeof d === "string" && d !== "") : []); + +/** NPM writes times as "2026-12-31 23:59:59" (UTC) or as ISO; either becomes ISO. */ +export function isoOf(v: unknown): string | null { + const s = str(v); + if (!s) return null; + const t = Date.parse(/[zZ]|[+-]\d{2}:?\d{2}$/.test(s) ? s : `${s.replace(" ", "T")}Z`); + return Number.isFinite(t) ? new Date(t).toISOString() : null; +} + +export function certificateFrom(raw: unknown): NpmCertificate | null { + const c = obj(raw); + const id = num(c.id); + if (id === null) return null; + return { id, name: str(c.nice_name) ?? domainsOf(c.domain_names)[0] ?? `certificate ${id}`, provider: str(c.provider) ?? "other", domains: domainsOf(c.domain_names), expiresAt: isoOf(c.expires_on) }; +} + +export function hostFrom(raw: unknown): NpmProxyHost | null { + const h = obj(raw); + const id = num(h.id); + if (id === null) return null; + const cert = h.certificate && typeof h.certificate === "object" ? certificateFrom(h.certificate) : null; + const meta = obj(h.meta); + const err = str(meta.nginx_err); + return { + id, + domains: domainsOf(h.domain_names), + forwardScheme: str(h.forward_scheme) ?? "http", + forwardHost: str(h.forward_host) ?? "", + forwardPort: num(h.forward_port), + enabled: h.enabled !== false && h.enabled !== 0, + sslForced: h.ssl_forced === true || h.ssl_forced === 1, + certificate: cert ? { id: cert.id, name: cert.name, expiresAt: cert.expiresAt } : null, + // NPM says "online" unless its own check of the generated configuration failed. + online: meta.nginx_online !== false && !err, + error: err, + }; +} + +export function createNpmAdapter(config: NpmConfig): NpmAdapter { + const base = config.url.replace(/\/+$/, ""); + const insecure = config.insecure === true; + + async function login(): Promise { + const res = await requestJson(`${base}/api/tokens`, { method: "POST", body: { identity: config.email, secret: config.password }, insecure }); + if (res.status === 401 || res.status === 400 || res.status === 403) throw new Error("Nginx Proxy Manager did not accept the email and password"); + const token = str(obj(res.json).token); + if (res.status < 200 || res.status >= 300 || !token) throw new Error(`Nginx Proxy Manager login failed: HTTP ${res.status}`); + return token; + } + + async function get(token: string, path: string): Promise { + const res = await requestJson(`${base}${path}`, { headers: { Authorization: `Bearer ${token}` }, insecure }); + if (res.status === 401 || res.status === 403) throw new Error(`Nginx Proxy Manager did not allow reading ${path.split("?")[0]} (HTTP ${res.status}) — the user needs view access to proxy hosts and certificates`); + if (res.status < 200 || res.status >= 300) throw new Error(`Nginx Proxy Manager error: HTTP ${res.status}`); + if (res.json === null) throw new Error("Nginx Proxy Manager answered with something that isn't JSON — is the address its admin page's?"); + return res.json; + } + + async function fetchSnapshot(): Promise { + const token = await login(); + const [hosts, certs, status] = await Promise.all([get(token, "/api/nginx/proxy-hosts?expand=certificate"), get(token, "/api/nginx/certificates").catch(() => []), get(token, "/api/").catch(() => null)]); + const v = obj(obj(status).version); + const version = num(v.major) !== null ? `${v.major}.${v.minor ?? 0}.${v.revision ?? 0}` : null; + return { + version, + hosts: (Array.isArray(hosts) ? hosts : []).map(hostFrom).filter((h): h is NpmProxyHost => h !== null), + certificates: (Array.isArray(certs) ? certs : []).map(certificateFrom).filter((c): c is NpmCertificate => c !== null), + }; + } + + async function ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }> { + const start = Date.now(); + try { + const token = await login(); + await get(token, "/api/nginx/proxy-hosts"); + return { ok: true, latencyMs: Date.now() - start }; + } catch (err) { + return { ok: false, error: err instanceof Error ? err.message : String(err) }; + } + } + + return withDiagLogging("npm", { ping, fetchSnapshot }); +} diff --git a/server/src/integrations/registry.ts b/server/src/integrations/registry.ts index 5d459ab..777e4d4 100644 --- a/server/src/integrations/registry.ts +++ b/server/src/integrations/registry.ts @@ -11,6 +11,8 @@ import { createPhpIpamAdapter } from "./phpipam/adapter.js"; import { createPbsAdapter } from "./pbs/adapter.js"; import { createOsTicketAdapter } from "./osticket/adapter.js"; import { createUnifiAdapter } from "./unifi/adapter.js"; +import { createNpmAdapter } from "./npm/adapter.js"; +import { createHomeAssistantAdapter } from "./homeassistant/adapter.js"; export interface PingableAdapter { ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }>; @@ -47,6 +49,10 @@ export function createIntegrationAdapter(type: IntegrationType, config: Integrat return createOsTicketAdapter(config as any); case "unifi": return createUnifiAdapter(config as any); + case "npm": + return createNpmAdapter(config as any); + case "homeassistant": + return createHomeAssistantAdapter(config as any); default: throw new Error(`Integration type "${type}" is not implemented yet`); } diff --git a/server/src/routes/dependencies.ts b/server/src/routes/dependencies.ts index 7a77ca1..87d61f3 100644 --- a/server/src/routes/dependencies.ts +++ b/server/src/routes/dependencies.ts @@ -8,6 +8,7 @@ import { recordAudit } from "../services/audit.js"; import { invalidateAlertsCache } from "../services/alerts.js"; import { dependentsOf, impactOf, loadGraph, nodeKey, nodeTypes, wouldLoop } from "../services/dependencies.js"; import { getSettings } from "../services/settingsStore.js"; +import { loadDependencySuggestions, loadDismissedDependencies, saveDismissedDependencies } from "../services/dependencySuggestions.js"; import { getSourceStatus } from "../services/integrationHealthMonitor.js"; import { serverStatus, type MapStatus } from "../services/topology.js"; import { asyncHandler } from "../utils/asyncHandler.js"; @@ -44,6 +45,43 @@ dependenciesRouter.get("/", asyncHandler(async (_req, res) => { }); })); +// Dependencies worth writing, from what the app already knows (an integration reached at a server's own address). Everyone signed in can see them; operators +// add or dismiss them, as they would any dependency. +dependenciesRouter.get("/suggestions", asyncHandler(async (_req, res) => { + res.json(await loadDependencySuggestions()); +})); + +const keysSchema = z.object({ keys: z.array(z.string().min(1).max(100)).min(1).max(200) }); + +dependenciesRouter.post("/suggestions/add", requireRole("operator"), asyncHandler(async (req, res) => { + const parsed = keysSchema.safeParse(req.body); + if (!parsed.success) return res.status(400).json({ error: "invalid_body" }); + const { suggestions } = await loadDependencySuggestions(); + const wanted = new Set(parsed.data.keys); + const added: { id: number; from: string; to: string }[] = []; + for (const s of suggestions.filter((x) => wanted.has(x.key))) { + const [row] = await db.insert(dependencies).values({ fromType: "integration", fromId: s.from.id, toType: "server", toId: s.to.id }).returning(); + await recordAudit({ actor: req.currentUser!, category: "dependency", action: "create", targetType: "dependency", targetId: row.id, detail: { from: s.from.name, to: s.to.name, fromKey: `integration:${s.from.id}`, toKey: `server:${s.to.id}`, suggested: true } }); + added.push({ id: row.id, from: s.from.name, to: s.to.name }); + } + if (added.length > 0) invalidateAlertsCache(); + res.json({ added, ...(await loadDependencySuggestions()) }); +})); + +dependenciesRouter.post("/suggestions/dismiss", requireRole("operator"), asyncHandler(async (req, res) => { + const parsed = keysSchema.safeParse(req.body); + if (!parsed.success) return res.status(400).json({ error: "invalid_body" }); + const dismissed = await loadDismissedDependencies(); + for (const k of parsed.data.keys) dismissed.add(k); + await saveDismissedDependencies(dismissed); + res.json(await loadDependencySuggestions()); +})); + +dependenciesRouter.post("/suggestions/restore", requireRole("operator"), asyncHandler(async (_req, res) => { + await saveDismissedDependencies(new Set()); + res.json(await loadDependencySuggestions()); +})); + // What a thing would take with it, and what it needs itself: for the maintenance and update pages, which say so before it is done. dependenciesRouter.get("/impact", asyncHandler(async (req, res) => { const type = nodeTypes.find((t) => t === req.query.type); diff --git a/server/src/routes/homeAssistant.ts b/server/src/routes/homeAssistant.ts new file mode 100644 index 0000000..61f9a24 --- /dev/null +++ b/server/src/routes/homeAssistant.ts @@ -0,0 +1,137 @@ +import { Router } from "express"; +import { and, eq, gte } from "drizzle-orm"; +import { z } from "zod"; +import { db } from "../db/client.js"; +import { haEntities, haReadings, haWatched, integrations } from "../db/schema.js"; +import { requireAuth, requireRole } from "../auth/middleware.js"; +import { recordAudit } from "../services/audit.js"; +import { invalidateAlertsCache } from "../services/alerts.js"; +import { createHomeAssistantAdapter } from "../integrations/homeassistant/adapter.js"; +import { loadIntegrationConfig } from "../integrations/loadIntegration.js"; +import { haProblems, haSyncStatuses, isHaFresh, READING_KEEP_DAYS, syncAllHomeAssistants, syncHomeAssistant } from "../services/homeAssistantSync.js"; +import { bucketPoints } from "../services/serverMetrics.js"; +import { asyncHandler } from "../utils/asyncHandler.js"; + +export const homeAssistantRouter = Router(); +homeAssistantRouter.use(requireAuth); + +const idOf = (v: string) => (/^\d+$/.test(v) ? Number(v) : NaN); +const DAY_MS = 86_400_000; + +async function haIntegration(id: number) { + const [row] = await db.select({ id: integrations.id, name: integrations.name, type: integrations.type }).from(integrations).where(eq(integrations.id, id)).limit(1); + return row && row.type === "homeassistant" ? row : null; +} + +/** What is watched in each Home Assistant, with what the last read said; everyone signed in can see it. */ +homeAssistantRouter.get("/", asyncHandler(async (_req, res) => { + const [intRows, watched, entities, statuses] = await Promise.all([ + db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "homeassistant")), + db.select().from(haWatched), + db.select().from(haEntities), + haSyncStatuses(), + ]); + const now = new Date(); + res.json({ + integrations: intRows.map((i) => { + const status = statuses[i.id] ?? null; + const mine = watched.filter((w) => w.integrationId === i.id).sort((a, b) => (a.name ?? a.entityId).localeCompare(b.name ?? b.entityId)); + const rows = new Map(entities.filter((e) => e.integrationId === i.id).map((e) => [e.entityId, e])); + return { + id: i.id, + name: i.name, + enabled: i.enabled, + status, + fresh: isHaFresh(status ?? undefined, now.getTime()), + watched: mine.map((w) => { + const e = rows.get(w.entityId); + return { + entityId: w.entityId, + name: w.name, + above: w.above, + below: w.below, + entity: e ? { friendlyName: e.friendlyName, state: e.state, value: e.value, unit: e.unit, deviceClass: e.deviceClass, lastChanged: e.lastChanged, unavailableSince: e.unavailableSince, updatedAt: e.updatedAt } : null, + }; + }), + problems: isHaFresh(status ?? undefined, now.getTime()) ? haProblems(i.id, i.name, mine, rows, now) : [], + }; + }), + }); +})); + +// Every entity Home Assistant has, to pick from: read live, so only those who may change what is watched see them. +homeAssistantRouter.get("/:id/entities", requireRole("operator"), asyncHandler(async (req, res) => { + const id = idOf(req.params.id); + if (!Number.isInteger(id) || !(await haIntegration(id))) return res.status(404).json({ error: "not_found" }); + const loaded = await loadIntegrationConfig(id); + if (!loaded) return res.status(404).json({ error: "not_found" }); + const q = typeof req.query.q === "string" ? req.query.q.trim().toLowerCase() : ""; + try { + const all = await createHomeAssistantAdapter(loaded.config as never).listEntities(); + const watched = new Set((await db.select({ entityId: haWatched.entityId }).from(haWatched).where(eq(haWatched.integrationId, id))).map((w) => w.entityId)); + const found = all.filter((e) => !q || e.entityId.toLowerCase().includes(q) || e.name.toLowerCase().includes(q)).sort((a, b) => a.entityId.localeCompare(b.entityId)).slice(0, 60); + res.json({ total: all.length, entities: found.map((e) => ({ entityId: e.entityId, name: e.name, state: e.state, unit: e.unit, deviceClass: e.deviceClass, watched: watched.has(e.entityId) })) }); + } catch (err) { + res.status(502).json({ error: "unreachable", message: err instanceof Error ? err.message : String(err) }); + } +})); + +const watchSchema = z.object({ + entityId: z.string().regex(/^[a-z_]+\.[A-Za-z0-9_]+$/, "Not an entity id, like sensor.ups_battery").max(120), + name: z.string().trim().max(80).nullable().optional(), + above: z.number().finite().nullable().optional(), + below: z.number().finite().nullable().optional(), +}); + +// Watch an entity, or change what is said about one already watched (its name, its limits). +homeAssistantRouter.put("/:id/watched", requireRole("operator"), asyncHandler(async (req, res) => { + const id = idOf(req.params.id); + const parsed = watchSchema.safeParse(req.body); + if (!Number.isInteger(id) || !(await haIntegration(id))) return res.status(404).json({ error: "not_found" }); + if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: parsed.error.issues[0]?.message ?? "Not an entity." }); + const d = parsed.data; + if (d.above != null && d.below != null && d.below >= d.above) return res.status(400).json({ error: "invalid_limits", message: "The lower limit has to be below the upper one." }); + const [count] = [(await db.select({ id: haWatched.id }).from(haWatched).where(eq(haWatched.integrationId, id))).length]; + const existing = (await db.select().from(haWatched).where(and(eq(haWatched.integrationId, id), eq(haWatched.entityId, d.entityId))).limit(1))[0]; + if (!existing && count >= 60) return res.status(400).json({ error: "too_many", message: "That is as many as can be watched on one Home Assistant (60)." }); + const values = { name: d.name?.trim() || null, above: d.above ?? null, below: d.below ?? null }; + if (existing) await db.update(haWatched).set(values).where(eq(haWatched.id, existing.id)); + else await db.insert(haWatched).values({ integrationId: id, entityId: d.entityId, ...values, createdAt: new Date().toISOString() }); + await recordAudit({ actor: req.currentUser!, category: "integration", action: existing ? "ha_watch_changed" : "ha_watch", targetType: "integration", targetId: id, detail: { entity: d.entityId, above: values.above, below: values.below } }); + const status = await syncHomeAssistant(id); + invalidateAlertsCache(); + res.json({ ok: true, status }); +})); + +homeAssistantRouter.delete("/:id/watched/:entityId", requireRole("operator"), asyncHandler(async (req, res) => { + const id = idOf(req.params.id); + const entityId = req.params.entityId; + if (!Number.isInteger(id) || !(await haIntegration(id))) return res.status(404).json({ error: "not_found" }); + const [row] = await db.select().from(haWatched).where(and(eq(haWatched.integrationId, id), eq(haWatched.entityId, entityId))).limit(1); + if (!row) return res.status(404).json({ error: "not_found" }); + await db.delete(haWatched).where(eq(haWatched.id, row.id)); + await db.delete(haEntities).where(and(eq(haEntities.integrationId, id), eq(haEntities.entityId, entityId))); + await db.delete(haReadings).where(and(eq(haReadings.integrationId, id), eq(haReadings.entityId, entityId))); + await recordAudit({ actor: req.currentUser!, category: "integration", action: "ha_unwatch", targetType: "integration", targetId: id, detail: { entity: entityId } }); + invalidateAlertsCache(); + res.status(204).end(); +})); + +// The chart of a watched number: up to the 35 days that are kept. +homeAssistantRouter.get("/:id/history", asyncHandler(async (req, res) => { + const id = idOf(req.params.id); + const entity = typeof req.query.entity === "string" ? req.query.entity : ""; + if (!Number.isInteger(id) || !entity) return res.status(400).json({ error: "invalid_query" }); + const requested = Number(req.query.days); + const days = Number.isFinite(requested) ? Math.min(READING_KEEP_DAYS, Math.max(1, Math.round(requested))) : 7; + const to = Date.now(); + const from = to - days * DAY_MS; + const rows = await db.select({ at: haReadings.at, value: haReadings.value }).from(haReadings).where(and(eq(haReadings.integrationId, id), eq(haReadings.entityId, entity), gte(haReadings.at, new Date(from).toISOString()))).orderBy(haReadings.at); + res.json({ days, points: bucketPoints(rows.map((r) => ({ t: Date.parse(r.at), v: r.value })), from, to, 96) }); +})); + +homeAssistantRouter.post("/sync", requireRole("operator"), asyncHandler(async (_req, res) => { + const statuses = await syncAllHomeAssistants(); + invalidateAlertsCache(); + res.json({ statuses }); +})); diff --git a/server/src/routes/integrations.ts b/server/src/routes/integrations.ts index 097b177..722f3d8 100644 --- a/server/src/routes/integrations.ts +++ b/server/src/routes/integrations.ts @@ -26,6 +26,7 @@ import { createOsTicketAdapter } from "../integrations/osticket/adapter.js"; import { attachMatchedServers, summarizeMonitors, toMatchableServers } from "../services/uptimeKumaMatch.js"; import { getSourceStatus } from "../services/integrationHealthMonitor.js"; import { removeIntegrationData, syncUnifiIntegration } from "../services/unifiSync.js"; +import { removeHomeAssistantData, syncHomeAssistant } from "../services/homeAssistantSync.js"; import { invalidateAlertsCache } from "../services/alerts.js"; import { asyncHandler } from "../utils/asyncHandler.js"; import { ID_PATTERNS, isValidId } from "../utils/pathSegment.js"; @@ -125,6 +126,7 @@ integrationsRouter.post("/", requireRole("admin"), asyncHandler(async (req, res) // A new UniFi controller is read at once, so its equipment is there when the person opens the page (not waited for: a slow controller must not slow this). if (type === "unifi") void syncUnifiIntegration(created.id).then(() => invalidateAlertsCache()); + if (type === "homeassistant") void syncHomeAssistant(created.id).then(() => invalidateAlertsCache()); res.status(201).json({ integration: { @@ -226,6 +228,7 @@ integrationsRouter.patch("/:id", requireRole("admin"), asyncHandler(async (req, }); if (updated.type === "unifi" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncUnifiIntegration(updated.id).then(() => invalidateAlertsCache()); + if (updated.type === "homeassistant" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncHomeAssistant(updated.id).then(() => invalidateAlertsCache()); res.json({ integration: { @@ -303,6 +306,7 @@ integrationsRouter.delete("/:id", requireRole("admin"), asyncHandler(async (req, .returning({ id: servers.id }); if (existing.type === "unifi") await removeIntegrationData(id); + if (existing.type === "homeassistant") await removeHomeAssistantData(id); await db.delete(integrations).where(eq(integrations.id, id)); if (existing.credentialId) { await db.delete(integrationCredentials).where(eq(integrationCredentials.id, existing.credentialId)); diff --git a/server/src/routes/inventory.ts b/server/src/routes/inventory.ts index 3510605..f800c20 100644 --- a/server/src/routes/inventory.ts +++ b/server/src/routes/inventory.ts @@ -6,6 +6,7 @@ import { assetKinds, assets, servers } from "../db/schema.js"; import { requireAuth, requireRole } from "../auth/middleware.js"; import { recordAudit } from "../services/audit.js"; import { isRealDate, lifecycleReport } from "../services/inventory.js"; +import { buildRacks } from "../services/racks.js"; import { blanksToFill, differences, hardwareOf } from "../services/inventoryAutofill.js"; import { getSettings, updateSettings } from "../services/settingsStore.js"; import { asyncHandler } from "../utils/asyncHandler.js"; @@ -88,6 +89,12 @@ inventoryRouter.get("/", asyncHandler(async (_req, res) => { })); // What ages out when, for planning what to replace: this year, the next few, later, and what has no date. +// The racks, drawn from the hardware that says which unit it sits in and where. Everyone signed in can see it, as they can the hardware. +inventoryRouter.get("/racks", asyncHandler(async (_req, res) => { + const rows = await db.select().from(assets); + res.json({ racks: buildRacks(rows) }); +})); + inventoryRouter.get("/lifecycle", asyncHandler(async (req, res) => { const asked = Number(req.query.years); const years = Number.isInteger(asked) && asked >= 1 && asked <= 10 ? asked : 5; diff --git a/server/src/routes/npm.ts b/server/src/routes/npm.ts new file mode 100644 index 0000000..dd8662a --- /dev/null +++ b/server/src/routes/npm.ts @@ -0,0 +1,47 @@ +import { Router } from "express"; +import { db } from "../db/client.js"; +import { servers } from "../db/schema.js"; +import { requireAuth } from "../auth/middleware.js"; +import { npmIntegrationIds, npmProblems, readNpm } from "../services/npmReader.js"; +import { matchServerForTarget } from "../services/uptimeKumaMatch.js"; +import { asyncHandler } from "../utils/asyncHandler.js"; + +export const npmRouter = Router(); +npmRouter.use(requireAuth); + +/** + * What Nginx Proxy Manager proxies: each host with where it forwards to (and which server that is, when the address is one the app knows), its certificate and how it is + * doing. Everyone signed in can see it (it is the same picture the alerts and suggested checks draw on). \`?refresh=1\` asks NPM again instead of using the last minute. + */ +npmRouter.get("/", asyncHandler(async (req, res) => { + const force = req.query.refresh === "1"; + const rows = await db.select({ id: servers.id, name: servers.name, hostname: servers.hostname, ipAddresses: servers.ipAddresses }).from(servers); + const matchable = rows.map((s) => { + let ips: string[] = []; + try { + const v = s.ipAddresses ? JSON.parse(s.ipAddresses) : []; + ips = Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []; + } catch { + // none + } + return { id: s.id, name: s.name, hostname: s.hostname, ips }; + }); + const out = []; + for (const i of await npmIntegrationIds()) { + const read = await readNpm(i.id, force); + out.push({ + id: i.id, + name: i.name, + readAt: read.at, + error: read.error, + version: read.snapshot?.version ?? null, + hosts: (read.snapshot?.hosts ?? []).map((h) => { + const server = matchServerForTarget(h.forwardHost, matchable); + return { ...h, server: server ? { id: server.id, name: server.name } : null }; + }), + certificates: read.snapshot?.certificates ?? [], + problems: read.snapshot ? npmProblems(i.id, i.name, read.snapshot, new Date()) : [], + }); + } + res.json({ integrations: out }); +})); diff --git a/server/src/routes/servers.ts b/server/src/routes/servers.ts index fad45be..4cea373 100644 --- a/server/src/routes/servers.ts +++ b/server/src/routes/servers.ts @@ -24,6 +24,7 @@ import { buildServerSummary } from "../services/serverSummary.js"; import { activeSubjects } from "../services/maintenance.js"; import { invalidateAlertsCache } from "../services/alerts.js"; import { getSettings, updateSettings } from "../services/settingsStore.js"; +import { osSummary } from "../services/osLifecycle.js"; export const serversRouter = Router(); @@ -397,7 +398,8 @@ serversRouter.get("/:id/detail", asyncHandler(async (req, res) => { children: [...links2.entries()].filter(([, l]) => l.parentId === id).map(([childId, l]) => ({ id: childId, name: nameOf.get(childId) ?? "", auto: l.auto })).sort((a, b) => a.name.localeCompare(b.name)), }; - res.json({ server: { ...serverOut, tags: parseTags(rawTags), pendingUpdates: parsePendingUpdates(rawUpdates), hostHealth: markIgnoredServices(parseHostHealth(rawHealth), parseThresholds(rawThresholds)?.ignoreServices), thresholds: parseThresholds(rawThresholds) }, diagnostics: describeDiagnostics(parseDiagnostics(rawDiagnostics), { osType: server.osType, lastSeenAt: server.lastSeenAt, agentVersion: server.agentVersion, latest: latestAgentVersions() }), thresholdDefaults: (await getSettings()).healthChecks, ipAddresses, hardware, dnsMatches, links, relations, agentLatest: latestAgentVersions() }); + const settings = await getSettings(); + res.json({ os: osSummary(server, new Date(), settings.healthChecks.osSupportWarnDays), server: { ...serverOut, tags: parseTags(rawTags), pendingUpdates: parsePendingUpdates(rawUpdates), hostHealth: markIgnoredServices(parseHostHealth(rawHealth), parseThresholds(rawThresholds)?.ignoreServices), thresholds: parseThresholds(rawThresholds) }, diagnostics: describeDiagnostics(parseDiagnostics(rawDiagnostics), { osType: server.osType, lastSeenAt: server.lastSeenAt, agentVersion: server.agentVersion, latest: latestAgentVersions() }), thresholdDefaults: (await getSettings()).healthChecks, ipAddresses, hardware, dnsMatches, links, relations, agentLatest: latestAgentVersions() }); })); const tagsSchema = z.object({ tags: z.array(z.string().max(100)).max(50) }); diff --git a/server/src/routes/settings.ts b/server/src/routes/settings.ts index ee5af65..77a81c5 100644 --- a/server/src/routes/settings.ts +++ b/server/src/routes/settings.ts @@ -144,7 +144,7 @@ const updateSchema = z.object({ .partial() .optional(), healthChecks: z - .object({ serverOfflineMinutes: z.number().int().min(15).max(10080), diskUsagePercent: z.number().int().min(50).max(99), domainWarnDays: z.number().int().min(1).max(365), diskForecastDays: z.number().int().min(0).max(90), backupStaleHours: z.number().int().min(0).max(2160), restoreTestDays: z.number().int().min(0).max(730), newPortAlerts: z.boolean(), flapRaises: z.number().int().min(0).max(20), deviceOfflineMinutes: z.number().int().min(5).max(1440) }) + .object({ serverOfflineMinutes: z.number().int().min(15).max(10080), diskUsagePercent: z.number().int().min(50).max(99), domainWarnDays: z.number().int().min(1).max(365), diskForecastDays: z.number().int().min(0).max(90), backupStaleHours: z.number().int().min(0).max(2160), restoreTestDays: z.number().int().min(0).max(730), newPortAlerts: z.boolean(), flapRaises: z.number().int().min(0).max(20), deviceOfflineMinutes: z.number().int().min(5).max(1440), osSupportWarnDays: z.number().int().min(0).max(365) }) .partial() .optional(), quietHours: z diff --git a/server/src/routes/todos.ts b/server/src/routes/todos.ts new file mode 100644 index 0000000..3d087c8 --- /dev/null +++ b/server/src/routes/todos.ts @@ -0,0 +1,92 @@ +import { Router } from "express"; +import { z } from "zod"; +import { requireAuth, requireRole } from "../auth/middleware.js"; +import { recordAudit } from "../services/audit.js"; +import { assignableUsers } from "../services/alertAcks.js"; +import { createTodo, getNote, listTodos, removeTodo, setNote, TARGET_TYPES, TodoError, updateTodo } from "../services/todos.js"; +import { asyncHandler } from "../utils/asyncHandler.js"; + +/** The to-do list: everyone signed in reads it; operators write. */ +export const todosRouter = Router(); +todosRouter.use(requireAuth); + +const idOf = (v: string) => (/^\d+$/.test(v) ? Number(v) : NaN); +const label = (u: { name: string | null; email: string | null; oidcSub: string }) => u.name ?? u.email ?? u.oidcSub; + +const fields = { + title: z.string(), + detail: z.string().nullable().optional(), + dueDate: z.string().nullable().optional(), + assigneeId: z.number().int().positive().nullable().optional(), + targetType: z.enum(TARGET_TYPES).nullable().optional(), + targetId: z.number().int().positive().nullable().optional(), +}; + +todosRouter.get("/", asyncHandler(async (_req, res) => { + res.json({ todos: await listTodos(), people: await assignableUsers() }); +})); + +todosRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => { + const parsed = z.object(fields).safeParse(req.body); + if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Say what is to be done." }); + try { + const actor = req.currentUser!; + const item = await createTodo(parsed.data, label(actor)); + await recordAudit({ actor, category: "todo", action: "create", targetType: "todo", targetId: item.id, detail: { title: item.title, dueDate: item.dueDate, assignee: item.assignee?.name ?? null, about: item.target?.name ?? null } }); + res.status(201).json({ todo: item }); + } catch (err) { + if (err instanceof TodoError) return res.status(err.status).json({ error: err.code, message: err.message }); + throw err; + } +})); + +todosRouter.patch("/:id", requireRole("operator"), asyncHandler(async (req, res) => { + const id = idOf(req.params.id); + const parsed = z.object({ ...fields, title: z.string().optional(), done: z.boolean().optional() }).safeParse(req.body); + if (!Number.isInteger(id) || !parsed.success) return res.status(400).json({ error: "invalid_body" }); + try { + const actor = req.currentUser!; + const result = await updateTodo(id, parsed.data, label(actor)); + if (!result) return res.status(404).json({ error: "not_found" }); + const action = parsed.data.done === true && !result.before.doneAt ? "done" : parsed.data.done === false && result.before.doneAt ? "reopen" : "update"; + await recordAudit({ actor, category: "todo", action, targetType: "todo", targetId: id, detail: { title: result.after.title } }); + res.json({ todo: result.after }); + } catch (err) { + if (err instanceof TodoError) return res.status(err.status).json({ error: err.code, message: err.message }); + throw err; + } +})); + +todosRouter.delete("/:id", requireRole("operator"), asyncHandler(async (req, res) => { + const id = idOf(req.params.id); + if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" }); + const removed = await removeTodo(id); + if (!removed) return res.status(404).json({ error: "not_found" }); + await recordAudit({ actor: req.currentUser!, category: "todo", action: "delete", targetType: "todo", targetId: id, detail: { title: removed.title } }); + res.status(204).end(); +})); + +/** The notes on servers and devices: everyone reads; operators write. */ +export const notesRouter = Router(); +notesRouter.use(requireAuth); + +notesRouter.get("/", asyncHandler(async (req, res) => { + const type = z.enum(TARGET_TYPES).safeParse(req.query.targetType); + const id = idOf(String(req.query.targetId ?? "")); + if (!type.success || !Number.isInteger(id)) return res.status(400).json({ error: "invalid_target" }); + res.json({ note: await getNote(type.data, id) }); +})); + +notesRouter.put("/", requireRole("operator"), asyncHandler(async (req, res) => { + const parsed = z.object({ targetType: z.enum(TARGET_TYPES), targetId: z.number().int().positive(), body: z.string() }).safeParse(req.body); + if (!parsed.success) return res.status(400).json({ error: "invalid_body" }); + try { + const actor = req.currentUser!; + const note = await setNote(parsed.data.targetType, parsed.data.targetId, parsed.data.body, label(actor)); + await recordAudit({ actor, category: "note", action: note ? "save" : "delete", targetType: parsed.data.targetType, targetId: parsed.data.targetId }); + res.json({ note }); + } catch (err) { + if (err instanceof TodoError) return res.status(err.status).json({ error: err.code, message: err.message }); + throw err; + } +})); diff --git a/server/src/services/agenda.ts b/server/src/services/agenda.ts index 3daed9c..91009ec 100644 --- a/server/src/services/agenda.ts +++ b/server/src/services/agenda.ts @@ -9,7 +9,8 @@ import { createHash } from "node:crypto"; import { and, eq } from "drizzle-orm"; import { db } from "../db/client.js"; -import { assets, domains, endpointChecks, integrations, maintenanceSchedules, patchPlans, secrets, servers } from "../db/schema.js"; +import { assets, domains, endpointChecks, integrations, maintenanceSchedules, patchPlans, secrets, servers, todos } from "../db/schema.js"; +import { isNull } from "drizzle-orm"; import { collectTailscaleKeyExpiries } from "./tailscaleKeyExpiryScheduler.js"; import { describeTarget, listUpcomingWindows } from "./maintenance.js"; import { occurrencesBetween, targetsOf } from "./maintenanceSchedules.js"; @@ -19,7 +20,7 @@ import { latestTests } from "./restoreTests.js"; import { getSettings } from "./settingsStore.js"; import { env } from "../env.js"; -export const AGENDA_KINDS = ["secret", "certificate", "domain", "tailscale", "warranty", "support", "maintenance", "restore", "updates"] as const; +export const AGENDA_KINDS = ["secret", "certificate", "domain", "tailscale", "warranty", "support", "maintenance", "restore", "updates", "todo"] as const; export type AgendaKind = (typeof AGENDA_KINDS)[number]; export const KIND_LABELS: Record = { @@ -32,6 +33,7 @@ export const KIND_LABELS: Record = { maintenance: "Maintenance", restore: "Restore tests", updates: "Updates waiting", + todo: "To do", }; export interface AgendaItem { @@ -96,6 +98,8 @@ export interface AgendaData { restoreLimitDays: number; /** Servers with updates waiting. */ updates: { name: string; count: number; security: number | null; since: string | null }[]; + /** Open jobs that have a day they are due. */ + todos: { id: number; title: string; dueDate: string | null; assigneeName: string | null; serverId: number | null }[]; notes: string[]; } @@ -127,6 +131,8 @@ export async function loadAgendaData(now: Date = new Date()): Promise t.dueDate !== null); + const windows: AgendaData["windows"] = []; for (const w of await listUpcomingWindows(now)) { const target = await describeTarget(w.targetType, w.targetId); @@ -174,6 +180,7 @@ export async function loadAgendaData(now: Date = new Date()): Promise ({ subjectKey: t.subjectKey, label: t.label, testedAt: t.testedAt, result: t.result })), restoreLimitDays: settings.healthChecks.restoreTestDays, updates, + todos: todoRows.map((t) => ({ id: t.id, title: t.title, dueDate: t.dueDate, assigneeName: t.assigneeName, serverId: t.targetType === "server" ? t.targetId : null })), notes, }; } @@ -213,6 +220,11 @@ export function agendaFromData(data: AgendaData, now: Date, tz: string, days: nu day(`support:${a.id}`, "support", a.endOfSupport, (past) => ({ title: `Support for ${a.name} ${past ? "ended" : "ends"}`, detail: "time to plan its replacement", link: `/inventory?asset=${a.id}`, serverId: a.serverId })); } + // Jobs on the to-do list that have a day: an open one that is past due stays until it is done (or for as long as anything past is kept). + for (const t of data.todos ?? []) { + day(`todo:${t.id}`, "todo", t.dueDate, (past) => ({ title: `${past ? "Overdue" : "To do"}: ${t.title}`, detail: t.assigneeName ? `for ${t.assigneeName}` : null, link: "/todo", serverId: t.serverId })); + } + // A restore test is due a set time after the last good one — only if a time limit is set (Settings → Notifications). if (data.restoreLimitDays > 0) { for (const t of data.restoreTests) { @@ -317,6 +329,7 @@ const GENERIC: Record = { maintenance: "Planned maintenance", restore: "A restore test is due", updates: "Updates are waiting", + todo: "A job is due", }; /** diff --git a/server/src/services/agentVersions.ts b/server/src/services/agentVersions.ts index f783578..7884fd4 100644 --- a/server/src/services/agentVersions.ts +++ b/server/src/services/agentVersions.ts @@ -12,6 +12,7 @@ * Windows: also reports failed services, disk health and Storage Spaces pools, and what the machine is (maker, model, serial) * 5 — Linux: also says what the machine is (maker, model, serial), for the inventory * 6 — Linux (and Windows 5): also says what it could not collect and why, so the server can say what to fix + * 7 — Linux (and Windows 6): also says which operating system and release it runs, so the server can say when that release stops being supported */ import { createHash } from "node:crypto"; import { readFileSync } from "node:fs"; diff --git a/server/src/services/alerts.ts b/server/src/services/alerts.ts index 3d9fdc0..04188f3 100644 --- a/server/src/services/alerts.ts +++ b/server/src/services/alerts.ts @@ -11,8 +11,11 @@ */ import { eq } from "drizzle-orm"; import { db } from "../db/client.js"; -import { endpointChecks, heartbeats, integrations, networkDevices, secrets, servers } from "../db/schema.js"; +import { endpointChecks, haEntities, haWatched, heartbeats, integrations, networkDevices, secrets, servers } from "../db/schema.js"; import { disksFillingSoon, getForecastSeries } from "./serverMetrics.js"; +import { daysOfSupportLeft, lifecycleOf } from "./osLifecycle.js"; +import { npmIntegrationIds, npmProblems, readNpm } from "./npmReader.js"; +import { haProblems, haSyncStatuses, isHaFresh } from "./homeAssistantSync.js"; import { diskLimit, effectiveThresholds, parseThresholds } from "./serverThresholds.js"; import { getBackupCoverage, staleBackups } from "./backupCoverage.js"; import { recordFromReport } from "./incidents.js"; @@ -65,6 +68,8 @@ const SOURCES: Record = { uptimekuma: { label: "Uptime Kuma", link: "/uptime-kuma" }, osticket: { label: "osTicket", link: "/osticket" }, unifi: { label: "UniFi", link: "/network/devices" }, + npm: { label: "Nginx Proxy Manager", link: "/proxy-hosts" }, + homeassistant: { label: "Home Assistant", link: "/home-assistant" }, secrets: { label: "Secrets", link: "/secrets" }, domains: { label: "Domains", link: "/dns?view=domains" }, endpoint: { label: "Endpoint", link: "/endpoints" }, @@ -515,6 +520,67 @@ export async function collectAlerts(): Promise { } }), + // Certificates in use by Nginx Proxy Manager that are running out, and hosts it could not set up. + check("Nginx Proxy Manager", async () => { + for (const i of await npmIntegrationIds()) { + const read = await readNpm(i.id); + if (!read.snapshot) { + cannotCheck(`Nginx Proxy Manager “${i.name}”`, read.error ?? "couldn't be read", "Nginx Proxy Manager"); + continue; + } + for (const p of npmProblems(i.id, i.name, read.snapshot, new Date())) { + push({ category: p.kind === "certificate" ? "expiry" : "monitoring", severity: p.severity, type: "npm", message: p.message, key: p.key, link: "/proxy-hosts", silenced: silencedIntegration(i.id), target: integrationTarget(i.id) }); + } + } + }), + + // What was chosen to watch in Home Assistant: an entity that has said nothing for a while, or a number past its limit. + check("Home Assistant", async () => { + const statuses = await haSyncStatuses(); + const nowMs = Date.now(); + const watched = await db.select().from(haWatched); + if (watched.length === 0) return; + const entities = await db.select().from(haEntities); + for (const i of intRows.filter((r) => r.type === "homeassistant" && r.enabled)) { + const mine = watched.filter((w) => w.integrationId === i.id); + if (mine.length === 0) continue; + if (!isHaFresh(statuses[i.id], nowMs)) { + cannotCheck(`Home Assistant “${i.name}”`, statuses[i.id]?.error ?? "hasn't been read yet", "Home Assistant"); + continue; + } + const rows = new Map(entities.filter((e) => e.integrationId === i.id).map((e) => [e.entityId, e])); + for (const p of haProblems(i.id, i.name, mine, rows, new Date(nowMs))) { + push({ category: "monitoring", severity: p.severity, type: "homeassistant", message: p.message, key: p.key, link: "/home-assistant", silenced: silencedIntegration(i.id), target: integrationTarget(i.id) }); + } + } + }), + + // Not a notification either: an operating system whose support has ended (or is about to) is seen here, with the date, from what the agent says it runs. + check("Operating system support", async () => { + const { healthChecks } = await getSettings(); + if (!(healthChecks.osSupportWarnDays > 0)) return; + const now = new Date(); + for (const s of await db.select({ id: servers.id, name: servers.name, osId: servers.osId, osName: servers.osName, osVersion: servers.osVersion }).from(servers)) { + if (!s.osId) continue; + const life = lifecycleOf({ id: s.osId, name: s.osName, version: s.osVersion }); + const left = life ? daysOfSupportLeft(life.endsOn, now) : null; + if (!life || life.endsOn === null || left === null || left > healthChecks.osSupportWarnDays) continue; + const ended = left < 0; + push({ + category: "updates", + severity: ended ? "warning" : "info", + type: "server", + message: ended + ? `${s.name} runs ${life.product}, whose support ended on ${life.endsOn} — it no longer gets security fixes` + : `${s.name} runs ${life.product}, whose support ends on ${life.endsOn} (in ${plural(left, "day")})`, + key: `os-support:${s.id}`, + link: `/servers/${s.id}`, + silenced: subjects.has(`server:${s.id}`), + target: targetOf("server", s.id), + }); + } + }), + check("Integration failures", async () => { const { notifications } = await getSettings(); const failing = getFailingSources(); diff --git a/server/src/services/changeLog.ts b/server/src/services/changeLog.ts index 64fd698..f40c574 100644 --- a/server/src/services/changeLog.ts +++ b/server/src/services/changeLog.ts @@ -40,6 +40,8 @@ const KIND_OF_CATEGORY: Record = { share_link: "settings", metrics_token: "settings", api_token: "settings", + todo: "other", + note: "servers", webhook: "settings", integration: "integrations", dns: "integrations", diff --git a/server/src/services/dependencySuggestions.ts b/server/src/services/dependencySuggestions.ts new file mode 100644 index 0000000..aa95980 --- /dev/null +++ b/server/src/services/dependencySuggestions.ts @@ -0,0 +1,133 @@ +/** + * Suggested dependencies: things the app already knows enough about to offer "this needs that" for, so the map fills in with a click instead of typing. + * + * - **An integration that runs on a server.** An integration is reached at an address; when that address is one of a server's own (its IP, its hostname, or its + * name), the service almost certainly runs on that server — Gitea at git.lab on the server that answers to it — so when that server is down, so is the service. + * (A server it runs on that is not in the app, or a service in the cloud, matches nothing and is not offered.) + * + * Network links (which switch a device or a server is plugged into) and which Proxmox node a guest runs on are not offered: they are already part of the map + * by themselves. It only reads what is stored, asks nobody, leaves out what is already so (or implied, or would make a loop), and remembers what somebody said + * no to — like the suggested checks. + */ +import { db } from "../db/client.js"; +import { integrations, servers } from "../db/schema.js"; +import { matchServerForTarget, type MatchableServer } from "./uptimeKumaMatch.js"; +import { loadGraph, nodeKey, wouldLoop, type Edges } from "./dependencies.js"; +import { getInternalFlag, setInternalFlag } from "./settingsStore.js"; + +export interface DependencySuggestion { + /** Stable, so a dismissed suggestion stays dismissed: "integration:3>server:7". */ + key: string; + from: { type: "integration"; id: number; name: string }; + to: { type: "server"; id: number; name: string }; + /** Why it is offered, in a sentence. */ + reason: string; +} + +export interface IntegrationFacts { + id: number; + name: string; + type: string; + enabled: boolean; + /** The address it is reached at: a URL's host, or a database host. */ + host: string | null; +} + +const TYPE_WORDS: Record = { + gitea: "Gitea", + semaphore: "Semaphore", + dockhand: "Docker (Dockhand)", + proxmox: "Proxmox", + synology: "Synology", + uptimekuma: "Uptime Kuma", + phpipam: "phpIPAM", + pbs: "Proxmox Backup Server", + osticket: "osTicket", + unifi: "the UniFi controller", + homeassistant: "Home Assistant", + npm: "Nginx Proxy Manager", +}; + +/** The host an integration is reached at, from the address it was set up with (or its database host, for osTicket). */ +export function hostOfIntegration(baseUrl: string | null, config: string | null): string | null { + try { + const c = config ? (JSON.parse(config) as Record) : {}; + if (typeof c.host === "string" && c.host.trim()) return c.host.trim(); + } catch { + // a config that is not JSON says nothing + } + if (!baseUrl) return null; + try { + return new URL(baseUrl).hostname || null; + } catch { + return null; + } +} + +/** Pure: the dependencies worth offering, from what is known. */ +export function suggestDependencies(input: { integrations: IntegrationFacts[]; servers: MatchableServer[]; edges: Edges; dismissed: Set }): { suggestions: DependencySuggestion[]; dismissed: DependencySuggestion[] } { + const all: DependencySuggestion[] = []; + for (const i of input.integrations) { + if (!i.enabled || !i.host) continue; + const server = matchServerForTarget(i.host, input.servers); + if (!server) continue; + const from = nodeKey("integration", i.id); + const to = nodeKey("server", server.id); + if (input.edges.get(from)?.includes(to)) continue; + if (wouldLoop(input.edges, from, to)) continue; + all.push({ + key: `${from}>${to}`, + from: { type: "integration", id: i.id, name: i.name }, + to: { type: "server", id: server.id, name: server.name }, + reason: `${TYPE_WORDS[i.type] ?? i.name} is reached at ${i.host}, which is ${server.name}'s own address — so it most likely runs there, and is down when ${server.name} is.`, + }); + } + all.sort((a, b) => a.from.name.localeCompare(b.from.name) || a.to.name.localeCompare(b.to.name)); + return { suggestions: all.filter((s) => !input.dismissed.has(s.key)), dismissed: all.filter((s) => input.dismissed.has(s.key)) }; +} + +// ─── What was said no to ─────────────────────────────────────────────────── + +const DISMISSED_FLAG = "dependencySuggestionsDismissed"; +const MAX_DISMISSED = 500; + +export async function loadDismissedDependencies(): Promise> { + const raw = await getInternalFlag(DISMISSED_FLAG); + if (!raw) return new Set(); + try { + const v = JSON.parse(raw); + return new Set(Array.isArray(v) ? v.filter((k): k is string => typeof k === "string") : []); + } catch { + return new Set(); + } +} + +export async function saveDismissedDependencies(keys: Set): Promise { + await setInternalFlag(DISMISSED_FLAG, JSON.stringify([...keys].slice(-MAX_DISMISSED))); +} + +// ─── Reading what is stored ──────────────────────────────────────────────── + +export async function loadDependencySuggestions() { + const [intRows, serverRows, graph, dismissed] = await Promise.all([ + db.select({ id: integrations.id, name: integrations.name, type: integrations.type, enabled: integrations.enabled, baseUrl: integrations.baseUrl, config: integrations.config }).from(integrations), + db.select({ id: servers.id, name: servers.name, hostname: servers.hostname, ipAddresses: servers.ipAddresses }).from(servers), + loadGraph(), + loadDismissedDependencies(), + ]); + return suggestDependencies({ + integrations: intRows.map((i) => ({ id: i.id, name: i.name, type: i.type, enabled: i.enabled, host: hostOfIntegration(i.baseUrl, i.config) })), + servers: serverRows.map((s) => { + let ips: string[] = []; + try { + const v = s.ipAddresses ? JSON.parse(s.ipAddresses) : []; + ips = Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []; + } catch { + // none + } + return { id: s.id, name: s.name, hostname: s.hostname, ips }; + }), + edges: graph.edges, + dismissed, + }); +} diff --git a/server/src/services/endpointSuggestions.ts b/server/src/services/endpointSuggestions.ts index b899ce3..8c1ea5e 100644 --- a/server/src/services/endpointSuggestions.ts +++ b/server/src/services/endpointSuggestions.ts @@ -3,6 +3,8 @@ * * - A web port a server's agent sees open (80, 443, 8080, 8443), with a name that points at it in DNS if there is one — "git.example.lan answers on * 443 on nas" — as a web check, linked to that server so its maintenance silences the alerts. + * - A host Nginx Proxy Manager serves ("wiki.example.com" forwarding to a server the app knows), as a web check on the name people really use, linked to the + * server it forwards to. * - A secret that already has a host to read the certificate from, as a certificate check: the secret only warns about the expiry, this also hears * when the service stops answering. * @@ -12,6 +14,8 @@ import { db } from "../db/client.js"; import { dnsRecordsCache, endpointChecks, secrets, servers } from "../db/schema.js"; import { isLoopback } from "./agentPorts.js"; +import { npmIntegrationIds, readNpm } from "./npmReader.js"; +import { matchServerForTarget } from "./uptimeKumaMatch.js"; import { getInternalFlag, setInternalFlag } from "./settingsStore.js"; export interface Suggestion { @@ -33,6 +37,8 @@ export interface SuggestionInput { secrets: { name: string; checkHost: string | null; checkPort: number | null }[]; existing: { kind: string; target: string; port: number | null }[]; dismissed: Set; + /** Hosts an Nginx Proxy Manager serves, with the server they forward to when the app knows it. */ + proxied?: { domain: string; secure: boolean; serverId: number | null; serverName: string | null; integrationName: string }[]; } /** The web ports worth offering, and what they speak. */ @@ -112,6 +118,25 @@ export function suggestChecks(input: SuggestionInput): { suggestions: Suggestion } } + for (const p of input.proxied ?? []) { + const host = cleanHost(p.domain); + if (!host.includes(".") || host.startsWith("*") || /s/.test(host) || isIPv4(host)) continue; + const port = p.secure ? 443 : 80; + if (covered.has(`web:${host}:${port}`)) continue; + const key = `http|${p.secure ? "https" : "http"}://${host}/`; + if (all.has(key)) continue; + all.set(key, { + key, + kind: "http", + name: host, + target: `${p.secure ? "https" : "http"}://${host}/`, + port: null, + serverId: p.serverId, + serverName: p.serverName, + reason: `${p.integrationName} serves ${host}${p.serverName ? `, forwarding to ${p.serverName}` : ""}.`, + }); + } + for (const sec of input.secrets) { if (!sec.checkHost || sec.checkPort === null) continue; const host = cleanHost(sec.checkHost); @@ -176,7 +201,19 @@ export async function loadSuggestions(): Promise<{ suggestions: Suggestion[]; di db.select({ kind: endpointChecks.kind, target: endpointChecks.target, port: endpointChecks.port }).from(endpointChecks), loadDismissed(), ]); + // What Nginx Proxy Manager serves (a read is kept for a minute, and an NPM that can't be reached just adds nothing). + const matchable = serverRows.map((s) => ({ id: s.id, name: s.name, hostname: s.hostname, ips: jsonArray(s.ipAddresses).filter((i) => typeof i === "string") })); + const proxied: NonNullable = []; + for (const i of await npmIntegrationIds()) { + const read = await readNpm(i.id); + for (const h of read.snapshot?.hosts ?? []) { + if (!h.enabled) continue; + const server = matchServerForTarget(h.forwardHost, matchable); + for (const domain of h.domains) proxied.push({ domain, secure: h.sslForced || h.certificate !== null, serverId: server?.id ?? null, serverName: server?.name ?? null, integrationName: i.name }); + } + } return suggestChecks({ + proxied, servers: serverRows.map((s) => ({ id: s.id, name: s.name, hostname: s.hostname, ips: jsonArray(s.ipAddresses).filter((i) => typeof i === "string"), ports: jsonArray<{ protocol?: string; port: number; address?: string }>(s.listeningPorts).filter((p) => p && Number.isInteger(p.port)) })), dns: dnsRows, secrets: secretRows, diff --git a/server/src/services/homeAssistantSync.ts b/server/src/services/homeAssistantSync.ts new file mode 100644 index 0000000..b462287 --- /dev/null +++ b/server/src/services/homeAssistantSync.ts @@ -0,0 +1,182 @@ +/** + * Keeps what was chosen to watch in each Home Assistant up to date: every few minutes the entities are read (one call lists them all), the watched ones are + * stored with their state, and a numeric one adds a point to its history. The page, the chart and the alerts are built from what is stored — so none of them talks to + * Home Assistant — and a Home Assistant that is down costs only how fresh they are. + * + * What makes an alert: a watched entity that has been "unavailable" or "unknown" for a while, or a number past a limit somebody set (a UPS battery under 30, a + * freezer over -10). + */ +import { and, desc, eq, lt } from "drizzle-orm"; +import { db } from "../db/client.js"; +import { haEntities, haReadings, haWatched, integrations } from "../db/schema.js"; +import { loadIntegrationConfig } from "../integrations/loadIntegration.js"; +import { createHomeAssistantAdapter, type HaEntity } from "../integrations/homeassistant/adapter.js"; +import { getInternalFlag, setInternalFlag } from "./settingsStore.js"; + +export const SYNC_INTERVAL_MS = 5 * 60_000; +/** The stored states are only as good as the last good pass: after this long, alerts for them are held rather than judged. */ +export const STALE_AFTER_MS = 20 * 60_000; +/** An entity must have said nothing for this long before it is an alert. */ +export const UNAVAILABLE_MINUTES = 15; +export const READING_KEEP_DAYS = 35; +/** Two passes closer than this add one point to a history, not two. */ +const MIN_READING_GAP_MS = 2 * 60_000; +const STATUS_FLAG = "homeAssistantSync"; + +export interface HaSyncStatus { + at: string; + ok: boolean; + error: string | null; + entities: number; +} + +async function readStatuses(): Promise> { + try { + const raw = await getInternalFlag(STATUS_FLAG); + return raw ? (JSON.parse(raw) as Record) : {}; + } catch { + return {}; + } +} + +export async function haSyncStatuses(): Promise> { + return Object.fromEntries(Object.entries(await readStatuses()).map(([k, v]) => [Number(k), v])); +} + +export function isHaFresh(status: HaSyncStatus | undefined, nowMs: number): boolean { + return !!status && status.ok && nowMs - Date.parse(status.at) <= STALE_AFTER_MS; +} + +/** Pure: when an entity first stopped saying anything, kept until it does. */ +export function trackUnavailable(previous: string | null | undefined, unavailable: boolean, nowIso: string): string | null { + return unavailable ? (previous ?? nowIso) : null; +} + +/** Stores one read of one Home Assistant: the watched entities' states and, for the numeric ones, a reading. */ +export async function storeEntities(integrationId: number, entities: HaEntity[], now: Date = new Date()): Promise { + const nowIso = now.toISOString(); + const watched = await db.select().from(haWatched).where(eq(haWatched.integrationId, integrationId)); + if (watched.length === 0) return 0; + const byId = new Map(entities.map((e) => [e.entityId, e])); + const before = new Map((await db.select().from(haEntities).where(eq(haEntities.integrationId, integrationId))).map((r) => [r.entityId, r])); + for (const w of watched) { + const e = byId.get(w.entityId); + // An entity that is no longer in Home Assistant at all is as good as unavailable. + const state = e?.state ?? "missing"; + const unavailable = e ? e.unavailable : true; + const values = { + friendlyName: e?.name ?? null, + state, + value: e?.value ?? null, + unit: e?.unit ?? null, + deviceClass: e?.deviceClass ?? null, + lastChanged: e?.lastChanged ?? null, + unavailableSince: trackUnavailable(before.get(w.entityId)?.unavailableSince, unavailable, nowIso), + updatedAt: nowIso, + }; + await db.insert(haEntities).values({ integrationId, entityId: w.entityId, ...values }).onConflictDoUpdate({ target: [haEntities.integrationId, haEntities.entityId], set: values }); + if (e?.value !== null && e?.value !== undefined && !unavailable) { + const [newest] = await db.select({ at: haReadings.at }).from(haReadings).where(and(eq(haReadings.integrationId, integrationId), eq(haReadings.entityId, w.entityId))).orderBy(desc(haReadings.at)).limit(1); + if (!newest || now.getTime() - Date.parse(newest.at) >= MIN_READING_GAP_MS) await db.insert(haReadings).values({ integrationId, entityId: w.entityId, at: nowIso, value: e.value }); + } + } + // What is no longer watched is no longer kept. + const watchedIds = watched.map((w) => w.entityId); + for (const id of before.keys()) if (!watchedIds.includes(id)) await db.delete(haEntities).where(and(eq(haEntities.integrationId, integrationId), eq(haEntities.entityId, id))); + await db.delete(haReadings).where(and(eq(haReadings.integrationId, integrationId), lt(haReadings.at, new Date(now.getTime() - READING_KEEP_DAYS * 86_400_000).toISOString()))); + return watched.length; +} + +/** Reads one Home Assistant and stores what is watched. Never throws: how it went is the answer, and what was stored is left alone when it failed. */ +export async function syncHomeAssistant(integrationId: number, now: Date = new Date()): Promise { + let status: HaSyncStatus; + try { + const loaded = await loadIntegrationConfig(integrationId); + if (!loaded || loaded.integration.type !== "homeassistant") throw new Error("not a Home Assistant integration"); + const entities = await createHomeAssistantAdapter(loaded.config as never).listEntities(); + const count = await storeEntities(integrationId, entities, now); + status = { at: now.toISOString(), ok: true, error: null, entities: count }; + } catch (err) { + const previous = (await readStatuses())[String(integrationId)]; + status = { at: previous?.at ?? now.toISOString(), ok: false, error: err instanceof Error ? err.message : String(err), entities: previous?.entities ?? 0 }; + console.error(`[home-assistant] couldn't read integration ${integrationId}:`, status.error); + } + try { + const all = await readStatuses(); + all[String(integrationId)] = status; + await setInternalFlag(STATUS_FLAG, JSON.stringify(all)); + } catch (err) { + console.error("[home-assistant] couldn't record the result:", err); + } + return status; +} + +export async function syncAllHomeAssistants(now: Date = new Date()): Promise> { + const rows = await db.select({ id: integrations.id }).from(integrations).where(and(eq(integrations.type, "homeassistant"), eq(integrations.enabled, true))); + const out: Record = {}; + for (const r of rows) out[r.id] = await syncHomeAssistant(r.id, now); + return out; +} + +/** Forgets everything of one integration when it is removed (and its status). */ +export async function removeHomeAssistantData(integrationId: number): Promise { + await db.delete(haReadings).where(eq(haReadings.integrationId, integrationId)); + await db.delete(haEntities).where(eq(haEntities.integrationId, integrationId)); + await db.delete(haWatched).where(eq(haWatched.integrationId, integrationId)); + const all = await readStatuses(); + if (String(integrationId) in all) { + delete all[String(integrationId)]; + await setInternalFlag(STATUS_FLAG, JSON.stringify(all)); + } +} + +export interface HaProblem { + key: string; + kind: "unavailable" | "limit"; + severity: "critical" | "warning"; + message: string; +} + +const durationWords = (ms: number) => { + const m = Math.floor(ms / 60_000); + return m < 60 ? `${m} min` : m < 48 * 60 ? `${Math.floor(m / 60)} h` : `${Math.floor(m / 1440)} days`; +}; + +/** Pure: what is wrong with the watched entities, from what is stored. */ +export function haProblems( + integrationId: number, + integrationName: string, + watched: { entityId: string; name: string | null; above: number | null; below: number | null }[], + entities: Map, + now: Date, +): HaProblem[] { + const out: HaProblem[] = []; + for (const w of watched) { + const e = entities.get(w.entityId); + if (!e) continue; + const name = w.name ?? e.friendlyName ?? w.entityId; + if (e.unavailableSince !== null) { + const ms = now.getTime() - Date.parse(e.unavailableSince); + if (ms >= UNAVAILABLE_MINUTES * 60_000) { + out.push({ key: `ha-unavailable:${integrationId}:${w.entityId}`, kind: "unavailable", severity: "warning", message: `${name} has been ${e.state === "missing" ? "missing from" : e.state} in Home Assistant for ${durationWords(ms)} [${integrationName}]` }); + } + continue; + } + if (e.value === null) continue; + const unit = e.unit ? ` ${e.unit}` : ""; + if (w.above !== null && e.value > w.above) out.push({ key: `ha-limit:${integrationId}:${w.entityId}`, kind: "limit", severity: "warning", message: `${name} is ${e.value}${unit}, above its limit of ${w.above}${unit} [${integrationName}]` }); + else if (w.below !== null && e.value < w.below) out.push({ key: `ha-limit:${integrationId}:${w.entityId}`, kind: "limit", severity: "warning", message: `${name} is ${e.value}${unit}, below its limit of ${w.below}${unit} [${integrationName}]` }); + } + return out; +} + +let timer: ReturnType | null = null; + +export function initHomeAssistantSync(): void { + if (timer) return; + const pass = () => void syncAllHomeAssistants().catch((err) => console.error("[home-assistant] pass failed:", err)); + timer = setInterval(pass, SYNC_INTERVAL_MS); + setTimeout(pass, 7_000); + console.log(`[home-assistant] reading watched entities every ${SYNC_INTERVAL_MS / 60000} minutes`); +} + diff --git a/server/src/services/myWork.ts b/server/src/services/myWork.ts index 7601daf..27c5d5a 100644 --- a/server/src/services/myWork.ts +++ b/server/src/services/myWork.ts @@ -11,11 +11,14 @@ import { servers, updateRuns } from "../db/schema.js"; import { getAlerts } from "./alerts.js"; import { loadAcks } from "./alertAcks.js"; import { describeTarget, listActiveWindows } from "./maintenance.js"; +import { openTodosFor } from "./todos.js"; /** An acknowledgement that runs out within this long is flagged. */ export const ACK_ENDS_SOON_MS = 24 * 3600_000; /** A maintenance window that ends within this long is flagged. */ export const WINDOW_ENDS_SOON_MS = 2 * 3600_000; +/** A job handed to somebody is flagged from this many days before it is due (and once it is past). */ +export const TODO_DUE_SOON_DAYS = 2; /** A finished update run stays on the list this long, so the result is seen. */ export const RUN_KEPT_MS = 24 * 3600_000; @@ -44,6 +47,8 @@ export interface MyWork { }[]; windows: { id: number; targetType: string; targetId: number; targetName: string; targetKind: string; reason: string | null; startedAt: string; endsAt: string; endsSoon: boolean }[]; updateRuns: { id: number; serverId: number; serverName: string; templateName: string; status: string; message: string | null; startedAt: string; finishedAt: string | null; running: boolean; updatesBefore: number | null; updatesAfter: number | null; rebootRequired: boolean }[]; + /** Open jobs from the to-do list handed to this person, the soonest due first. */ + todos: { id: number; title: string; detail: string | null; dueDate: string | null; overdue: boolean; dueSoon: boolean; target: { type: string; id: number; name: string } | null }[]; /** How many of the above want a look: acknowledgements and windows that end soon, alerts handed to them, update runs still going. */ needsAttention: number; } @@ -111,6 +116,18 @@ export async function buildMyWork(user: MyWorkUser, now: Date = new Date()): Pro } runs.sort((a, b) => Number(b.running) - Number(a.running) || b.startedAt.localeCompare(a.startedAt)); - const needsAttention = alerts.filter((a) => a.role === "handed" || a.endsSoon).length + windows.filter((w) => w.endsSoon).length + runs.filter((r) => r.running).length; - return { alerts, windows, updateRuns: runs, needsAttention }; + const today = now.toISOString().slice(0, 10); + const soon = new Date(nowMs + TODO_DUE_SOON_DAYS * 86_400_000).toISOString().slice(0, 10); + const jobs: MyWork["todos"] = (await openTodosFor(user.id)).map((t) => ({ + id: t.id, + title: t.title, + detail: t.detail, + dueDate: t.dueDate, + overdue: t.dueDate !== null && t.dueDate < today, + dueSoon: t.dueDate !== null && t.dueDate >= today && t.dueDate <= soon, + target: t.target, + })); + + const needsAttention = alerts.filter((a) => a.role === "handed" || a.endsSoon).length + windows.filter((w) => w.endsSoon).length + runs.filter((r) => r.running).length + jobs.filter((j) => j.overdue || j.dueSoon).length; + return { alerts, windows, updateRuns: runs, todos: jobs, needsAttention }; } diff --git a/server/src/services/notify.ts b/server/src/services/notify.ts index 13f9d7b..c03412a 100644 --- a/server/src/services/notify.ts +++ b/server/src/services/notify.ts @@ -607,6 +607,8 @@ const SOURCE_LABELS: Record = { pbs: "Proxmox Backup Server", osticket: "osTicket", unifi: "UniFi", + npm: "Nginx Proxy Manager", + homeassistant: "Home Assistant", }; export function sourceLabel(source: string): string { diff --git a/server/src/services/npmReader.ts b/server/src/services/npmReader.ts new file mode 100644 index 0000000..085df5b --- /dev/null +++ b/server/src/services/npmReader.ts @@ -0,0 +1,82 @@ +/** + * Reads Nginx Proxy Manager for the page, the alerts and the suggested checks, and works out what is wrong: a certificate in use that is about to run out (or has), + * and a host NPM itself says it could not set up. A read is kept for a minute, so the page, the alerts and the suggestions together cost one call, and a failed read is + * kept too (briefly), so an unreachable NPM is not asked again by every one of them. + */ +import { and, eq } from "drizzle-orm"; +import { db } from "../db/client.js"; +import { integrations } from "../db/schema.js"; +import { loadIntegrationConfig } from "../integrations/loadIntegration.js"; +import { createNpmAdapter, type NpmProxyHost, type NpmSnapshot } from "../integrations/npm/adapter.js"; + +const CACHE_MS = 60_000; +/** A certificate is raised from this many days before it ends; critical in the last three. */ +export const CERT_WARN_DAYS = 14; +export const CERT_CRITICAL_DAYS = 3; + +interface Entry { + at: number; + snapshot: NpmSnapshot | null; + error: string | null; +} +const cache = new Map(); +export const clearNpmCacheForTests = () => cache.clear(); + +/** What NPM says now (a minute old at most), or why it could not be read. */ +export async function readNpm(integrationId: number, force = false): Promise<{ snapshot: NpmSnapshot | null; error: string | null; at: string }> { + const hit = cache.get(integrationId); + if (hit && !force && Date.now() - hit.at < CACHE_MS) return { snapshot: hit.snapshot, error: hit.error, at: new Date(hit.at).toISOString() }; + let entry: Entry; + try { + const loaded = await loadIntegrationConfig(integrationId); + if (!loaded || loaded.integration.type !== "npm") throw new Error("not an Nginx Proxy Manager integration"); + entry = { at: Date.now(), snapshot: await createNpmAdapter(loaded.config as never).fetchSnapshot(), error: null }; + } catch (err) { + entry = { at: Date.now(), snapshot: null, error: err instanceof Error ? err.message : String(err) }; + } + cache.set(integrationId, entry); + return { snapshot: entry.snapshot, error: entry.error, at: new Date(entry.at).toISOString() }; +} + +export async function npmIntegrationIds(): Promise<{ id: number; name: string }[]> { + return db.select({ id: integrations.id, name: integrations.name }).from(integrations).where(and(eq(integrations.type, "npm"), eq(integrations.enabled, true))); +} + +export interface NpmProblem { + key: string; + kind: "certificate" | "host"; + severity: "critical" | "warning"; + message: string; +} + +const DAY_MS = 86_400_000; + +/** Pure: what is wrong, from one read. Only certificates that an enabled host uses count; a host that is switched off is not a problem. */ +export function npmProblems(integrationId: number, integrationName: string, snapshot: NpmSnapshot, now: Date): NpmProblem[] { + const out: NpmProblem[] = []; + const inUse = new Map(); + for (const h of snapshot.hosts) { + if (!h.enabled || !h.certificate) continue; + inUse.set(h.certificate.id, [...(inUse.get(h.certificate.id) ?? []), h]); + } + for (const cert of snapshot.certificates) { + const users = inUse.get(cert.id); + if (!users || !cert.expiresAt) continue; + const days = Math.floor((Date.parse(cert.expiresAt) - now.getTime()) / DAY_MS); + if (days > CERT_WARN_DAYS) continue; + const names = users.flatMap((h) => h.domains).slice(0, 3).join(", "); + // The certificate's own name is only worth saying when it isn't one of the names it is used for. + const called = users.some((h) => h.domains.includes(cert.name)) ? "" : ` (${cert.name})`; + out.push({ + key: `npm-cert:${integrationId}:${cert.id}`, + kind: "certificate", + severity: days <= CERT_CRITICAL_DAYS ? "critical" : "warning", + message: days < 0 ? `The certificate for ${names}${called} expired ${-days} ${days === -1 ? "day" : "days"} ago [${integrationName}]` : `The certificate for ${names}${called} expires in ${days} ${days === 1 ? "day" : "days"} [${integrationName}]`, + }); + } + for (const h of snapshot.hosts) { + if (!h.enabled || h.online) continue; + out.push({ key: `npm-host:${integrationId}:${h.id}`, kind: "host", severity: "warning", message: `${h.domains[0] ?? `Proxy host ${h.id}`} is not working in Nginx Proxy Manager${h.error ? `: ${h.error.slice(0, 160)}` : ""} [${integrationName}]` }); + } + return out; +} diff --git a/server/src/services/osLifecycle.ts b/server/src/services/osLifecycle.ts new file mode 100644 index 0000000..29ed08e --- /dev/null +++ b/server/src/services/osLifecycle.ts @@ -0,0 +1,212 @@ +/** + * When the operating system a server runs stops being supported. An agent says which one it runs (the distribution's id and release; for Windows, the product and + * build); this knows the vendors' published end-of-support dates for the common ones, and says how long a release has left — so "Ubuntu 20.04 ended in May" is + * on the Alerts page before a security fix is missed, the way a disk forecast is. + * + * The dates are the end of the vendor's standard security support (for Debian, including its long-term support; Proxmox VE's are the project's own announced + * ones). The table is only as new as this version of the app: a release it does not know has no date, and is never called unsupported — it is simply not + * judged. Rolling distributions (Arch, Gentoo, NixOS unstable) have no end and are not in it. + */ + +export interface OsFacts { + id?: string | null; + name?: string | null; + version?: string | null; +} + +export interface Lifecycle { + /** What to call it: "Ubuntu 22.04 LTS". */ + product: string; + /** YYYY-MM-DD the support ends, or null when this release is not in the table. */ + endsOn: string | null; +} + +interface Row { + product: string; + ends: string; +} + +// Keyed by family, then by the release as it is looked up (see releaseKey). +const TABLE: Record> = { + ubuntu: { + "16.04": { product: "Ubuntu 16.04 LTS", ends: "2021-04-30" }, + "18.04": { product: "Ubuntu 18.04 LTS", ends: "2023-05-31" }, + "20.04": { product: "Ubuntu 20.04 LTS", ends: "2025-05-31" }, + "22.04": { product: "Ubuntu 22.04 LTS", ends: "2027-04-30" }, + "24.04": { product: "Ubuntu 24.04 LTS", ends: "2029-04-30" }, + "26.04": { product: "Ubuntu 26.04 LTS", ends: "2031-04-30" }, + "22.10": { product: "Ubuntu 22.10", ends: "2023-07-20" }, + "23.04": { product: "Ubuntu 23.04", ends: "2024-01-25" }, + "23.10": { product: "Ubuntu 23.10", ends: "2024-07-11" }, + "24.10": { product: "Ubuntu 24.10", ends: "2025-07-10" }, + "25.04": { product: "Ubuntu 25.04", ends: "2026-01-15" }, + "25.10": { product: "Ubuntu 25.10", ends: "2026-07-09" }, + }, + debian: { + "9": { product: "Debian 9 (stretch)", ends: "2022-06-30" }, + "10": { product: "Debian 10 (buster)", ends: "2024-06-30" }, + "11": { product: "Debian 11 (bullseye)", ends: "2026-08-31" }, + "12": { product: "Debian 12 (bookworm)", ends: "2028-06-30" }, + "13": { product: "Debian 13 (trixie)", ends: "2030-06-30" }, + }, + "centos-classic": { + "7": { product: "CentOS 7", ends: "2024-06-30" }, + "8": { product: "CentOS 8", ends: "2021-12-31" }, + }, + "centos-stream": { + "8": { product: "CentOS Stream 8", ends: "2024-05-31" }, + "9": { product: "CentOS Stream 9", ends: "2027-05-31" }, + "10": { product: "CentOS Stream 10", ends: "2030-01-01" }, + }, + rhel: { + "7": { product: "Red Hat Enterprise Linux 7", ends: "2024-06-30" }, + "8": { product: "Red Hat Enterprise Linux 8", ends: "2029-05-31" }, + "9": { product: "Red Hat Enterprise Linux 9", ends: "2032-05-31" }, + "10": { product: "Red Hat Enterprise Linux 10", ends: "2035-05-31" }, + }, + rocky: { + "8": { product: "Rocky Linux 8", ends: "2029-05-31" }, + "9": { product: "Rocky Linux 9", ends: "2032-05-31" }, + "10": { product: "Rocky Linux 10", ends: "2035-05-31" }, + }, + almalinux: { + "8": { product: "AlmaLinux 8", ends: "2029-05-31" }, + "9": { product: "AlmaLinux 9", ends: "2032-05-31" }, + "10": { product: "AlmaLinux 10", ends: "2035-05-31" }, + }, + fedora: { + "38": { product: "Fedora 38", ends: "2024-05-21" }, + "39": { product: "Fedora 39", ends: "2024-11-26" }, + "40": { product: "Fedora 40", ends: "2025-05-13" }, + "41": { product: "Fedora 41", ends: "2025-12-15" }, + "42": { product: "Fedora 42", ends: "2026-05-13" }, + "43": { product: "Fedora 43", ends: "2026-12-02" }, + }, + alpine: { + "3.17": { product: "Alpine 3.17", ends: "2024-11-22" }, + "3.18": { product: "Alpine 3.18", ends: "2025-05-09" }, + "3.19": { product: "Alpine 3.19", ends: "2025-11-01" }, + "3.20": { product: "Alpine 3.20", ends: "2026-04-01" }, + "3.21": { product: "Alpine 3.21", ends: "2026-11-01" }, + "3.22": { product: "Alpine 3.22", ends: "2027-05-01" }, + }, + "opensuse-leap": { + "15.3": { product: "openSUSE Leap 15.3", ends: "2022-12-31" }, + "15.4": { product: "openSUSE Leap 15.4", ends: "2023-12-07" }, + "15.5": { product: "openSUSE Leap 15.5", ends: "2024-12-31" }, + "15.6": { product: "openSUSE Leap 15.6", ends: "2025-12-31" }, + }, + "proxmox-ve": { + "6": { product: "Proxmox VE 6", ends: "2022-07-31" }, + "7": { product: "Proxmox VE 7", ends: "2024-07-31" }, + "8": { product: "Proxmox VE 8", ends: "2026-08-31" }, + }, + // Windows is told apart by its build number, and a client from a server by the product's name (Windows 11 24H2 and Windows Server 2025 share a build). + "windows-client": { + "19045": { product: "Windows 10 22H2", ends: "2025-10-14" }, + "22000": { product: "Windows 11 21H2", ends: "2023-10-10" }, + "22621": { product: "Windows 11 22H2", ends: "2024-10-08" }, + "22631": { product: "Windows 11 23H2", ends: "2025-11-11" }, + "26100": { product: "Windows 11 24H2", ends: "2026-10-13" }, + "26200": { product: "Windows 11 25H2", ends: "2027-10-12" }, + }, + "windows-server": { + "9600": { product: "Windows Server 2012 R2", ends: "2023-10-10" }, + "14393": { product: "Windows Server 2016", ends: "2027-01-12" }, + "17763": { product: "Windows Server 2019", ends: "2029-01-09" }, + "20348": { product: "Windows Server 2022", ends: "2031-10-14" }, + "26100": { product: "Windows Server 2025", ends: "2034-11-14" }, + }, +}; + +/** Which family of the table an agent's answer belongs to, and which release within it; null when it is none this knows. */ +export function releaseKey(os: OsFacts): { family: string; key: string } | null { + const id = (os.id ?? "").trim().toLowerCase(); + const version = (os.version ?? "").trim(); + if (!id || !version) return null; + const name = (os.name ?? "").toLowerCase(); + switch (id) { + case "ubuntu": + return { family: "ubuntu", key: version.match(/^\d+\.\d+/)?.[0] ?? version }; + case "debian": + case "raspbian": + return { family: "debian", key: version.match(/^\d+/)?.[0] ?? version }; + case "centos": + return { family: name.includes("stream") ? "centos-stream" : "centos-classic", key: version.match(/^\d+/)?.[0] ?? version }; + case "rhel": + case "rocky": + case "almalinux": + return { family: id, key: version.match(/^\d+/)?.[0] ?? version }; + case "fedora": + return { family: "fedora", key: version.match(/^\d+/)?.[0] ?? version }; + case "alpine": + return { family: "alpine", key: version.match(/^\d+\.\d+/)?.[0] ?? version }; + case "opensuse-leap": + return { family: "opensuse-leap", key: version.match(/^\d+\.\d+/)?.[0] ?? version }; + case "proxmox-ve": + return { family: "proxmox-ve", key: version.match(/^\d+/)?.[0] ?? version }; + case "windows": + return { family: name.includes("server") ? "windows-server" : "windows-client", key: version.match(/^\d+/)?.[0] ?? version }; + default: + return null; + } +} + +/** What the table says about this operating system: its name and when its support ends. Null when the agent's answer is nothing this recognises at all. */ +export function lifecycleOf(os: OsFacts): Lifecycle | null { + const found = releaseKey(os); + if (!found) return null; + const row = TABLE[found.family]?.[found.key]; + if (row) return { product: row.product, endsOn: row.ends }; + // A release not in the table: named as the machine named itself, with no date, so nothing is claimed about it. + const name = (os.name ?? "").trim(); + return name ? { product: name, endsOn: null } : null; +} + +export interface OsSummary { + id: string; + name: string | null; + version: string | null; + /** What to call it. */ + product: string; + endsOn: string | null; + state: SupportState; + /** Days of support left (negative once it has ended); null with no date. */ + daysLeft: number | null; +} + +/** What a server's page and the read API say about the operating system it runs; null while its agent has not said. */ +export function osSummary(row: { osId: string | null; osName: string | null; osVersion: string | null }, now: Date, warnDays: number): OsSummary | null { + if (!row.osId) return null; + const life = lifecycleOf({ id: row.osId, name: row.osName, version: row.osVersion }); + const endsOn = life?.endsOn ?? null; + return { + id: row.osId, + name: row.osName, + version: row.osVersion, + product: life?.product ?? row.osName ?? row.osId, + endsOn, + // With the warning switched off the date is still known: "soon" then means the usual three months. + state: supportState(endsOn, now, warnDays > 0 ? warnDays : 90), + daysLeft: daysOfSupportLeft(endsOn, now), + }; +} + +export type SupportState = "ended" | "soon" | "ok" | "unknown"; + +const DAY_MS = 86_400_000; + +/** Whole days from `now` to the end of the day support ends (negative once it has passed); null with no date. */ +export function daysOfSupportLeft(endsOn: string | null, now: Date): number | null { + if (!endsOn) return null; + const end = Date.parse(`${endsOn}T23:59:59Z`); + return Number.isFinite(end) ? Math.floor((end - now.getTime()) / DAY_MS) : null; +} + +/** Ended once the day is over; "soon" within `warnDays` of the end; unknown with no date. */ +export function supportState(endsOn: string | null, now: Date, warnDays: number): SupportState { + const left = daysOfSupportLeft(endsOn, now); + if (left === null) return "unknown"; + if (left < 0) return "ended"; + return left <= warnDays ? "soon" : "ok"; +} diff --git a/server/src/services/publicApi.ts b/server/src/services/publicApi.ts index 87541b3..50401d1 100644 --- a/server/src/services/publicApi.ts +++ b/server/src/services/publicApi.ts @@ -15,6 +15,7 @@ import { parsePendingUpdates } from "./pendingUpdates.js"; import { parseTags } from "./serverTags.js"; import { parseThresholds } from "./serverThresholds.js"; import { getSettings } from "./settingsStore.js"; +import { osSummary } from "./osLifecycle.js"; import { serverStatus } from "./topology.js"; /** An address inside the app as a full address, for a script that has no idea where the app lives. */ @@ -33,7 +34,7 @@ const json = (text: string | null, fallback: T): T => { type ServerRow = typeof servers.$inferSelect; -export function serverV1(row: ServerRow, offlineMinutes: number, now: Date) { +export function serverV1(row: ServerRow, offlineMinutes: number, now: Date, osWarnDays = 90) { const status = serverStatus(row, offlineMinutes, now); const disks = json<{ mount: string; sizeBytes: number; usedBytes: number }[]>(row.disks, []); const updates = parsePendingUpdates(row.pendingUpdates); @@ -53,6 +54,8 @@ export function serverV1(row: ServerRow, offlineMinutes: number, now: Date) { agentVersion: row.agentVersion ?? null, runsOnServerId: row.parentServerId ?? null, hardware: { manufacturer: row.hwManufacturer ?? null, model: row.hwModel ?? null, serial: row.hwSerial ?? null }, + // What it runs and when that release stops being supported ("ended", "soon", "ok", "unknown"), once its agent has said. + operatingSystem: osSummary(row, now, osWarnDays), cpu: { model: row.cpuModel, cores: row.cpuCores, loadPercent: row.cpuLoadPercent }, memory: { totalBytes: row.memTotalBytes, usedBytes: row.memUsedBytes }, disks: disks.map((d) => ({ mount: d.mount, sizeBytes: d.sizeBytes, usedBytes: d.usedBytes, usedPercent: d.sizeBytes > 0 ? Math.round((d.usedBytes / d.sizeBytes) * 1000) / 10 : null })), @@ -65,13 +68,14 @@ export function serverV1(row: ServerRow, offlineMinutes: number, now: Date) { export async function serversV1(now: Date = new Date()) { const [rows, settings] = await Promise.all([db.select().from(servers).orderBy(servers.name), getSettings()]); - return rows.map((r) => serverV1(r, settings.healthChecks.serverOfflineMinutes, now)); + return rows.map((r) => serverV1(r, settings.healthChecks.serverOfflineMinutes, now, settings.healthChecks.osSupportWarnDays)); } export async function oneServerV1(id: number, now: Date = new Date()) { const [row] = await db.select().from(servers).where(eq(servers.id, id)).limit(1); if (!row) return null; - return serverV1(row, (await getSettings()).healthChecks.serverOfflineMinutes, now); + const { healthChecks } = await getSettings(); + return serverV1(row, healthChecks.serverOfflineMinutes, now, healthChecks.osSupportWarnDays); } export async function alertsV1() { diff --git a/server/src/services/racks.ts b/server/src/services/racks.ts new file mode 100644 index 0000000..105311f --- /dev/null +++ b/server/src/services/racks.ts @@ -0,0 +1,95 @@ +/** + * The racks, drawn from the inventory: each piece of hardware that says which unit it sits in (U12, or U12-13 for a tall one) and where (the rack's name in its + * location) is placed in its rack, units numbered from the bottom as racks are. Two pieces claiming the same unit are said to clash rather than hidden; hardware + * that names a rack but no unit is listed beside it as not placed. + */ + +export interface RackAsset { + id: number; + name: string; + kind: string; + manufacturer: string | null; + model: string | null; + location: string | null; + rackUnit: string | null; + powerWatts: number | null; + serverId: number | null; +} + +export interface RackSlot { + assetId: number; + name: string; + kind: string; + model: string | null; + /** The lowest and highest unit it takes, from 1 (the bottom). */ + from: number; + to: number; + powerWatts: number | null; + serverId: number | null; + /** Another piece takes one of the same units. */ + clash: boolean; +} + +export interface Rack { + /** What its pieces call it in their location; "(no rack named)" for pieces that gave a unit but no place. */ + name: string; + /** How many units tall to draw it. */ + units: number; + slots: RackSlot[]; + /** Pieces that name this rack and no unit. */ + unplaced: { assetId: number; name: string; kind: string }[]; + /** Units taken, and the watts of what stands in it. */ + usedUnits: number; + watts: number; +} + +/** The units of a text like "U12", "12", "U12-13", "12–14" or "U12 - U14": lowest and highest. Null when it is not a unit. */ +export function parseRackUnit(text: string | null | undefined): { from: number; to: number } | null { + if (!text) return null; + const m = /^\s*U?\s*(\d{1,2})\s*(?:[-–—]\s*U?\s*(\d{1,2}))?\s*$/i.exec(text); + if (!m) return null; + const a = Number(m[1]); + const b = m[2] !== undefined ? Number(m[2]) : a; + if (a < 1 || b < 1) return null; + return { from: Math.min(a, b), to: Math.max(a, b) }; +} + +/** Rack sizes that exist, so a rack is drawn as a real one. */ +const SIZES = [12, 18, 22, 24, 27, 42, 45, 47, 48]; +const NO_RACK = "(no rack named)"; + +export function buildRacks(assets: RackAsset[]): Rack[] { + const byRack = new Map(); + for (const a of assets) { + const place = (a.location ?? "").trim(); + const unit = parseRackUnit(a.rackUnit); + if (!place && !unit) continue; + const key = place || NO_RACK; + byRack.set(key, [...(byRack.get(key) ?? []), a]); + } + + const racks: Rack[] = []; + for (const [name, members] of byRack) { + const placed = members.filter((a) => parseRackUnit(a.rackUnit)); + // A "rack" that is only a room with things in it (no piece says a unit) is not a rack to draw. + if (placed.length === 0) continue; + const taken = new Map(); + const slots: RackSlot[] = placed.map((a) => { + const u = parseRackUnit(a.rackUnit)!; + for (let n = u.from; n <= u.to; n++) taken.set(n, (taken.get(n) ?? 0) + 1); + return { assetId: a.id, name: a.name, kind: a.kind, model: a.model, from: u.from, to: u.to, powerWatts: a.powerWatts, serverId: a.serverId, clash: false }; + }); + for (const s of slots) for (let n = s.from; n <= s.to; n++) if ((taken.get(n) ?? 0) > 1) s.clash = true; + slots.sort((x, y) => x.from - y.from || x.name.localeCompare(y.name)); + const top = Math.max(...slots.map((s) => s.to)); + racks.push({ + name, + units: SIZES.find((s) => s >= top) ?? top, + slots, + unplaced: members.filter((a) => !parseRackUnit(a.rackUnit)).map((a) => ({ assetId: a.id, name: a.name, kind: a.kind })).sort((x, y) => x.name.localeCompare(y.name)), + usedUnits: taken.size, + watts: slots.reduce((n, s) => n + (s.powerWatts ?? 0), 0), + }); + } + return racks.sort((a, b) => (a.name === NO_RACK ? 1 : 0) - (b.name === NO_RACK ? 1 : 0) || a.name.localeCompare(b.name, undefined, { numeric: true })); +} diff --git a/server/src/services/settingsStore.ts b/server/src/services/settingsStore.ts index b217cb5..8fe4a0f 100644 --- a/server/src/services/settingsStore.ts +++ b/server/src/services/settingsStore.ts @@ -119,6 +119,8 @@ export interface HealthCheckSettings { flapRaises: number; /** A network device (switch, access point, gateway) that a UniFi controller has not seen online for this many minutes is raised as offline. */ deviceOfflineMinutes: number; + /** Days before the end of an operating system's support that a server is first flagged on the Alerts page. 0 turns it off. */ + osSupportWarnDays: number; } /** The monthly report: last month's availability, incidents, updates and renewals, in one message on a day of the month. Off until switched on. */ @@ -289,7 +291,7 @@ const DEFAULTS: AppSettings = { selfBackup: { enabled: true, time: "03:30", keep: 14 }, profilePictures: { gravatar: false, identityProvider: false }, signIn: { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" }, - healthChecks: { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0, newPortAlerts: true, flapRaises: 3, deviceOfflineMinutes: 10 }, + healthChecks: { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0, newPortAlerts: true, flapRaises: 3, deviceOfflineMinutes: 10, osSupportWarnDays: 90 }, // Docker's default bridge (172.17.0.0/16) and the pool it hands custom networks from (172.18–31) live here, and every // Docker host repeats them. Shown on the Consistency page, where it can be removed if 172.16/12 is used as a real LAN. consistency: { excludedRanges: ["172.16.0.0/12"] }, diff --git a/server/src/services/taskSync.ts b/server/src/services/taskSync.ts index 31726d8..f88b7bd 100644 --- a/server/src/services/taskSync.ts +++ b/server/src/services/taskSync.ts @@ -32,6 +32,8 @@ export interface IncomingSystemInfo { health?: IncomingHostHealth; /** What the machine is, from its firmware: each part present only if it says anything. */ hardware?: { manufacturer?: string; model?: string; serial?: string }; + /** What the machine runs: the distribution's id and release (for Windows, the product and build). Absent from an agent that predates it. */ + os?: { id?: string; name?: string; version?: string } | null; /** What the agent could not collect; an empty list says nothing was missed. */ diagnostics?: AgentDiagnostic[]; } @@ -123,6 +125,8 @@ export async function syncServerTasks(serverId: number, report: AgentReport) { ...(system?.updates && before ? nextUpdateState(before, system.updates, now) : {}), ...(system?.health && before ? { hostHealth: nextHostHealth(before.hostHealth, system.health, now) } : {}), ...(system?.diagnostics ? { agentDiagnostics: nextDiagnostics(system.diagnostics, now) } : {}), + // Only stored when it was said, so an older agent doesn't wipe what a newer one told us; the text is bounded, whatever sent it. + ...(typeof system?.os?.id === "string" && system.os.id ? { osId: system.os.id.slice(0, 40).toLowerCase(), osName: typeof system.os.name === "string" ? system.os.name.slice(0, 80) : null, osVersion: typeof system.os.version === "string" ? system.os.version.slice(0, 40) : null } : {}), ...(system?.hardware?.manufacturer ? { hwManufacturer: system.hardware.manufacturer } : {}), ...(system?.hardware?.model ? { hwModel: system.hardware.model } : {}), ...(system?.hardware?.serial ? { hwSerial: system.hardware.serial } : {}), diff --git a/server/src/services/todos.ts b/server/src/services/todos.ts new file mode 100644 index 0000000..3d3f761 --- /dev/null +++ b/server/src/services/todos.ts @@ -0,0 +1,190 @@ +/** + * The to-do list and notes. A to-do is a small job with a title, maybe a day it is due, a person it is handed to and a server or network device it is about; ticking it + * off keeps it (so what was done is still there to read) and un-ticking brings it back. A note is one free-form text about a server or a device. + */ +import { and, desc, eq, isNull, isNotNull } from "drizzle-orm"; +import { db } from "../db/client.js"; +import { networkDevices, notes, servers, todos, users } from "../db/schema.js"; + +export const TARGET_TYPES = ["server", "device"] as const; +export type TargetType = (typeof TARGET_TYPES)[number]; + +export const MAX_TITLE = 160; +export const MAX_DETAIL = 2000; +export const MAX_NOTE_BODY = 8000; + +export class TodoError extends Error { + constructor( + readonly status: number, + readonly code: string, + message: string, + ) { + super(message); + } +} + +/** A real calendar day, written YYYY-MM-DD. */ +export const isRealDay = (v: unknown): v is string => typeof v === "string" && /^\d{4}-\d{2}-\d{2}$/.test(v) && new Date(`${v}T00:00:00Z`).toISOString().startsWith(v); + +export async function targetName(type: TargetType, id: number): Promise { + if (type === "server") return (await db.select({ name: servers.name }).from(servers).where(eq(servers.id, id)).limit(1))[0]?.name ?? null; + return (await db.select({ name: networkDevices.name }).from(networkDevices).where(eq(networkDevices.id, id)).limit(1))[0]?.name ?? null; +} + +export interface TodoItem { + id: number; + title: string; + detail: string | null; + dueDate: string | null; + assignee: { id: number | null; name: string } | null; + target: { type: TargetType; id: number; name: string } | null; + createdBy: string | null; + createdAt: string; + doneAt: string | null; + doneBy: string | null; +} + +type Row = typeof todos.$inferSelect; + +async function shape(rows: Row[]): Promise { + const serverNames = new Map((await db.select({ id: servers.id, name: servers.name }).from(servers)).map((s) => [s.id, s.name])); + const deviceNames = new Map((await db.select({ id: networkDevices.id, name: networkDevices.name }).from(networkDevices)).map((d) => [d.id, d.name])); + return rows.map((r) => { + const name = r.targetType && r.targetId !== null ? (r.targetType === "server" ? serverNames.get(r.targetId) : deviceNames.get(r.targetId)) : undefined; + return { + id: r.id, + title: r.title, + detail: r.detail, + dueDate: r.dueDate, + assignee: r.assigneeName ? { id: r.assigneeUserId, name: r.assigneeName } : null, + // What it was about, if that is still there. + target: r.targetType && r.targetId !== null && name ? { type: r.targetType, id: r.targetId, name } : null, + createdBy: r.createdBy, + createdAt: r.createdAt, + doneAt: r.doneAt, + doneBy: r.doneBy, + }; + }); +} + +/** Open ones first, the soonest due first (those with no day last); done ones after, the latest done first. */ +export async function listTodos(): Promise { + const open = await shape(await db.select().from(todos).where(isNull(todos.doneAt))); + open.sort((a, b) => (a.dueDate ?? "9999-99-99").localeCompare(b.dueDate ?? "9999-99-99") || a.createdAt.localeCompare(b.createdAt) || a.id - b.id); + const done = await shape(await db.select().from(todos).where(isNotNull(todos.doneAt)).orderBy(desc(todos.doneAt)).limit(200)); + return [...open, ...done]; +} + +export interface TodoInput { + title: string; + detail?: string | null; + dueDate?: string | null; + assigneeId?: number | null; + targetType?: TargetType | null; + targetId?: number | null; +} + +async function resolveAssignee(id: number | null | undefined): Promise<{ id: number | null; name: string | null }> { + if (id === null || id === undefined) return { id: null, name: null }; + const [u] = await db.select().from(users).where(eq(users.id, id)).limit(1); + if (!u || (u.role !== "admin" && u.role !== "operator")) throw new TodoError(400, "invalid_assignee", "A job can be handed to an administrator or an operator."); + return { id: u.id, name: u.name ?? u.email ?? u.oidcSub }; +} + +async function resolveTarget(type: TargetType | null | undefined, id: number | null | undefined): Promise<{ type: TargetType | null; id: number | null }> { + if (!type || id === null || id === undefined) return { type: null, id: null }; + if (!(await targetName(type, id))) throw new TodoError(400, "unknown_target", "That server or network device is not there."); + return { type, id }; +} + +function checked(input: TodoInput) { + const title = input.title.trim(); + if (!title) throw new TodoError(400, "invalid_body", "Say what is to be done."); + if (title.length > MAX_TITLE) throw new TodoError(400, "too_long", `Keep the title under ${MAX_TITLE} characters.`); + const detail = (input.detail ?? "").trim(); + if (detail.length > MAX_DETAIL) throw new TodoError(400, "too_long", `Keep the details under ${MAX_DETAIL} characters.`); + if (input.dueDate !== null && input.dueDate !== undefined && input.dueDate !== "" && !isRealDay(input.dueDate)) throw new TodoError(400, "invalid_date", "That is not a date."); + return { title, detail: detail || null, dueDate: input.dueDate ? input.dueDate : null }; +} + +export async function createTodo(input: TodoInput, actor: string, now: Date = new Date()): Promise { + const base = checked(input); + const who = await resolveAssignee(input.assigneeId); + const target = await resolveTarget(input.targetType, input.targetId); + const [row] = await db + .insert(todos) + .values({ ...base, assigneeUserId: who.id, assigneeName: who.name, targetType: target.type, targetId: target.id, createdBy: actor, createdAt: now.toISOString() }) + .returning(); + return (await shape([row]))[0]; +} + +/** Changes what is given; "done" ticks it off or brings it back. Null if there is no such job. */ +export async function updateTodo(id: number, input: Partial & { done?: boolean }, actor: string, now: Date = new Date()): Promise<{ before: TodoItem; after: TodoItem } | null> { + const [existing] = await db.select().from(todos).where(eq(todos.id, id)).limit(1); + if (!existing) return null; + const before = (await shape([existing]))[0]; + const set: Partial = {}; + if (input.title !== undefined || input.detail !== undefined || input.dueDate !== undefined) { + const c = checked({ title: input.title ?? existing.title, detail: input.detail === undefined ? existing.detail : input.detail, dueDate: input.dueDate === undefined ? existing.dueDate : input.dueDate }); + Object.assign(set, c); + } + if (input.assigneeId !== undefined) { + const who = await resolveAssignee(input.assigneeId); + set.assigneeUserId = who.id; + set.assigneeName = who.name; + } + if (input.targetType !== undefined || input.targetId !== undefined) { + const t = await resolveTarget(input.targetType === undefined ? existing.targetType : input.targetType, input.targetId === undefined ? existing.targetId : input.targetId); + set.targetType = t.type; + set.targetId = t.id; + } + if (input.done === true && !existing.doneAt) Object.assign(set, { doneAt: now.toISOString(), doneBy: actor }); + if (input.done === false) Object.assign(set, { doneAt: null, doneBy: null }); + if (Object.keys(set).length > 0) await db.update(todos).set(set).where(eq(todos.id, id)); + const [after] = await db.select().from(todos).where(eq(todos.id, id)).limit(1); + return { before, after: (await shape([after]))[0] }; +} + +export async function removeTodo(id: number): Promise { + const [row] = await db.select().from(todos).where(eq(todos.id, id)).limit(1); + if (!row) return null; + const item = (await shape([row]))[0]; + await db.delete(todos).where(eq(todos.id, id)); + return item; +} + +/** Open jobs handed to a person, for My work. */ +export async function openTodosFor(userId: number): Promise { + const rows = await db.select().from(todos).where(and(isNull(todos.doneAt), eq(todos.assigneeUserId, userId))); + const items = await shape(rows); + return items.sort((a, b) => (a.dueDate ?? "9999-99-99").localeCompare(b.dueDate ?? "9999-99-99") || a.id - b.id); +} + +// ─── Notes ───────────────────────────────────────────────────────────────── + +export interface NoteItem { + targetType: TargetType; + targetId: number; + body: string; + updatedBy: string | null; + updatedAt: string; +} + +export async function getNote(type: TargetType, id: number): Promise { + const [row] = await db.select().from(notes).where(and(eq(notes.targetType, type), eq(notes.targetId, id))).limit(1); + return row ? { targetType: row.targetType, targetId: row.targetId, body: row.body, updatedBy: row.updatedBy, updatedAt: row.updatedAt } : null; +} + +/** Writes the note of something; an empty text takes it away. Returns what is there now (null when there is none). */ +export async function setNote(type: TargetType, id: number, body: string, actor: string, now: Date = new Date()): Promise { + const text = body.replace(/\r\n/g, "\n").trimEnd(); + if (text.length > MAX_NOTE_BODY) throw new TodoError(400, "too_long", `Keep the note under ${MAX_NOTE_BODY} characters.`); + if (!(await targetName(type, id))) throw new TodoError(404, "unknown_target", "That server or network device is not there."); + if (text.trim() === "") { + await db.delete(notes).where(and(eq(notes.targetType, type), eq(notes.targetId, id))); + return null; + } + const values = { body: text, updatedBy: actor, updatedAt: now.toISOString() }; + await db.insert(notes).values({ targetType: type, targetId: id, ...values }).onConflictDoUpdate({ target: [notes.targetType, notes.targetId], set: values }); + return getNote(type, id); +} diff --git a/server/test/agentDiagnostics.test.ts b/server/test/agentDiagnostics.test.ts index f42e8f3..bea92c9 100644 --- a/server/test/agentDiagnostics.test.ts +++ b/server/test/agentDiagnostics.test.ts @@ -129,7 +129,7 @@ describe("through a report, the page, the alerts and the figures", () => { before(async () => { await db.insert(users).values([{ oidcSub: "admin", name: "Ada", role: "admin" }]); - const [s] = await db.insert(servers).values({ name: "elsa", apiTokenHash: hashToken("tok"), apiTokenPrefix: "t", lastSeenAt: new Date().toISOString(), agentVersion: 6 }).returning(); + const [s] = await db.insert(servers).values({ name: "elsa", apiTokenHash: hashToken("tok"), apiTokenPrefix: "t", lastSeenAt: new Date().toISOString(), agentVersion: 7 }).returning(); id = s.id; const a = express(); a.use("/api/agent/report", agentReportRouter); @@ -155,7 +155,7 @@ describe("through a report, the page, the alerts and the figures", () => { }); const report = (system: unknown) => - fetch(`${base}/agent/report`, { method: "POST", headers: { "content-type": "application/json", authorization: "Bearer tok" }, body: JSON.stringify({ hostname: "h", os_type: "linux", agent_version: 6, tasks: [], system }) }); + fetch(`${base}/agent/report`, { method: "POST", headers: { "content-type": "application/json", authorization: "Bearer tok" }, body: JSON.stringify({ hostname: "h", os_type: "linux", agent_version: 7, tasks: [], system }) }); const detail = async () => await (await fetch(`${base}/servers/${id}/detail`)).json(); const patch = (body: unknown) => fetch(`${base}/servers/${id}`, { method: "PATCH", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }); diff --git a/server/test/dependencySuggestions.test.ts b/server/test/dependencySuggestions.test.ts new file mode 100644 index 0000000..484a7ea --- /dev/null +++ b/server/test/dependencySuggestions.test.ts @@ -0,0 +1,137 @@ +/** + * Suggested dependencies: an integration reached at a server's own address is offered as needing that server; what is already so, would make a loop, or was + * said no to is left out; and adding one writes an ordinary dependency. + * + * Run with: npm test --workspace server + */ +import { test, describe, before, after } from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import type { AddressInfo } from "node:net"; +import type { Server } from "node:http"; + +const dir = mkdtempSync(join(tmpdir(), "hm-depsug-")); +process.env.DATABASE_PATH = join(dir, "test.sqlite"); +process.env.SESSION_DIR = join(dir, "sessions"); +process.env.CREDENTIALS_ENCRYPTION_KEY = "ab".repeat(32); + +const express = (await import("express")).default; +const { db } = await import("../src/db/client.js"); +const { users, servers, integrations, dependencies, auditLog } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const { suggestDependencies, hostOfIntegration } = await import("../src/services/dependencySuggestions.js"); +const { dependenciesRouter } = await import("../src/routes/dependencies.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); + +describe("what is offered", () => { + const servers = [ + { id: 1, name: "nas", hostname: "nas.lan", ips: ["10.0.0.5"] }, + { id: 2, name: "elsa", hostname: null, ips: ["10.0.0.9"] }, + ]; + const integ = (id: number, name: string, type: string, host: string | null, enabled = true) => ({ id, name, type, enabled, host }); + const none = new Map(); + + test("an integration at a server's own address (its IP, hostname or short name) needs that server", () => { + const { suggestions } = suggestDependencies({ + integrations: [integ(1, "Gitea", "gitea", "10.0.0.5"), integ(2, "Kuma", "uptimekuma", "nas.lan"), integ(3, "IPAM", "phpipam", "elsa"), integ(4, "Cloud", "tailscale", "api.tailscale.com")], + servers, + edges: none, + dismissed: new Set(), + }); + assert.deepEqual(suggestions.map((x) => x.key), ["integration:1>server:1", "integration:3>server:2", "integration:2>server:1"], "by name (Gitea, IPAM, Kuma); the one in the cloud matches nothing"); + assert.ok(suggestions.every((x) => x.reason.includes("most likely runs there"))); + }); + + test("a disabled integration, one with no address, and one with an unknown host are not offered", () => { + const { suggestions } = suggestDependencies({ integrations: [integ(1, "Off", "gitea", "10.0.0.5", false), integ(2, "None", "gitea", null), integ(3, "Elsewhere", "gitea", "10.9.9.9")], servers, edges: none, dismissed: new Set() }); + assert.equal(suggestions.length, 0); + }); + + test("what is already so, and what would make a loop, is left out", () => { + const already = new Map([["integration:1", ["server:1"]]]); + assert.equal(suggestDependencies({ integrations: [integ(1, "Gitea", "gitea", "10.0.0.5")], servers, edges: already, dismissed: new Set() }).suggestions.length, 0); + // the server needs the integration already: the other way round would make them wait for each other + const loop = new Map([["server:1", ["integration:1"]]]); + assert.equal(suggestDependencies({ integrations: [integ(1, "Gitea", "gitea", "10.0.0.5")], servers, edges: loop, dismissed: new Set() }).suggestions.length, 0); + }); + + test("what somebody said no to is kept apart, and can come back", () => { + const r = suggestDependencies({ integrations: [integ(1, "Gitea", "gitea", "10.0.0.5")], servers, edges: none, dismissed: new Set(["integration:1>server:1"]) }); + assert.deepEqual([r.suggestions.length, r.dismissed.length], [0, 1]); + }); + + test("where an integration is reached: a URL's host, or osTicket's database host", () => { + assert.equal(hostOfIntegration("https://git.example.lan:3000/", "{}"), "git.example.lan"); + assert.equal(hostOfIntegration("", JSON.stringify({ host: "osticket-db.lan" })), "osticket-db.lan"); + assert.equal(hostOfIntegration("not a url", null), null); + assert.equal(hostOfIntegration(null, "not json"), null); + }); +}); + +describe("over the routes", () => { + let app: Server; + let base = ""; + let who = "viewer"; + before(async () => { + await db.insert(users).values([ + { oidcSub: "viewer", name: "Vic", role: "viewer" }, + { oidcSub: "operator", name: "Olga", role: "operator" }, + ]); + await db.insert(servers).values({ name: "nas", hostname: "nas.lan", apiTokenHash: "n", apiTokenPrefix: "n", ipAddresses: JSON.stringify(["10.0.0.5"]) }); + await db.insert(integrations).values({ type: "gitea", name: "Gitea", baseUrl: "http://10.0.0.5:3000", config: JSON.stringify({ url: "http://10.0.0.5:3000" }) }); + 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/dependencies", dependenciesRouter); + 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/dependencies`; + }); + after(() => { + app.close(); + try { + rmSync(dir, { recursive: true, force: true }); + } catch { + // Windows may still hold the database file + } + }); + const post = (path: string, body: unknown = {}) => fetch(`${base}${path}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }); + + test("anyone signed in sees them; only an operator adds or dismisses", async () => { + who = "viewer"; + const body = (await (await fetch(`${base}/suggestions`)).json()) as any; + assert.deepEqual(body.suggestions.map((s: any) => s.key), ["integration:1>server:1"]); + assert.equal((await post("/suggestions/add", { keys: ["integration:1>server:1"] })).status, 403); + assert.equal((await post("/suggestions/dismiss", { keys: ["integration:1>server:1"] })).status, 403); + }); + + test("dismissing hides it, restoring brings it back, and a bad body is refused", async () => { + who = "operator"; + const hidden = (await (await post("/suggestions/dismiss", { keys: ["integration:1>server:1"] })).json()) as any; + assert.deepEqual([hidden.suggestions.length, hidden.dismissed.length], [0, 1]); + const back = (await (await post("/suggestions/restore")).json()) as any; + assert.equal(back.suggestions.length, 1); + assert.equal((await post("/suggestions/add", { keys: [] })).status, 400); + }); + + test("adding writes an ordinary dependency, written down, and it is no longer offered", async () => { + who = "operator"; + const res = (await (await post("/suggestions/add", { keys: ["integration:1>server:1", "integration:9>server:9"] })).json()) as any; + assert.deepEqual(res.added.map((a: any) => [a.from, a.to]), [["Gitea", "nas"]], "a key that is not offered adds nothing"); + assert.equal(res.suggestions.length, 0); + const rows = await db.select().from(dependencies); + assert.deepEqual(rows.map((r) => [r.fromType, r.fromId, r.toType, r.toId]), [["integration", 1, "server", 1]]); + const written = (await db.select().from(auditLog).where(eq(auditLog.category, "dependency")))[0]; + assert.equal(written.action, "create"); + const list = (await (await fetch(base)).json()) as any; + assert.equal(list.dependencies.length, 1, "and the page lists it with the rest"); + }); +}); diff --git a/server/test/npmAndHomeAssistant.test.ts b/server/test/npmAndHomeAssistant.test.ts new file mode 100644 index 0000000..c512982 --- /dev/null +++ b/server/test/npmAndHomeAssistant.test.ts @@ -0,0 +1,415 @@ +/** + * Nginx Proxy Manager and Home Assistant: reading each (against pretend ones), what is kept, what makes an alert, and the suggestions NPM feeds. + * + * Run with: npm test --workspace server + */ +import { test, describe, before, after } from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http"; +import type { AddressInfo } from "node:net"; + +const dir = mkdtempSync(join(tmpdir(), "hm-npmha-")); +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, integrations, integrationCredentials, haEntities, haReadings, haWatched } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const { encryptSecret } = await import("../src/crypto.js"); +const { createNpmAdapter, isoOf, hostFrom } = await import("../src/integrations/npm/adapter.js"); +const { createHomeAssistantAdapter, entityFrom } = await import("../src/integrations/homeassistant/adapter.js"); +const { npmProblems, readNpm, clearNpmCacheForTests } = await import("../src/services/npmReader.js"); +const { haProblems, trackUnavailable, syncHomeAssistant, removeHomeAssistantData, isHaFresh, haSyncStatuses } = await import("../src/services/homeAssistantSync.js"); +const { suggestChecks, loadSuggestions } = await import("../src/services/endpointSuggestions.js"); +const { getAlerts, invalidateAlertsCache } = await import("../src/services/alerts.js"); +const { npmRouter } = await import("../src/routes/npm.js"); +const { homeAssistantRouter } = await import("../src/routes/homeAssistant.js"); +const { validateIntegrationConfig } = await import("../src/integrations/fieldSchemas.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); + +const DAY = 86_400_000; +const inDays = (n: number) => new Date(Date.now() + n * DAY).toISOString(); +const npmTime = (n: number) => inDays(n).replace("T", " ").slice(0, 19); + +// ─── A pretend Nginx Proxy Manager ────────────────────────────────────────── + +let npmPassword = "pw"; +const npmCertificates = [ + { id: 1, nice_name: "wiki.example.com", provider: "letsencrypt", domain_names: ["wiki.example.com"], expires_on: npmTime(40) }, + { id: 2, nice_name: "git.example.com", provider: "letsencrypt", domain_names: ["git.example.com"], expires_on: npmTime(2) }, + { id: 3, nice_name: "old.example.com", provider: "letsencrypt", domain_names: ["old.example.com"], expires_on: npmTime(-5) }, +]; +const npmHosts = [ + { id: 10, domain_names: ["wiki.example.com"], forward_scheme: "http", forward_host: "10.0.0.5", forward_port: 8080, enabled: 1, ssl_forced: 1, certificate: npmCertificates[0], meta: { nginx_online: true } }, + { id: 11, domain_names: ["git.example.com"], forward_scheme: "http", forward_host: "10.0.0.6", forward_port: 3000, enabled: 1, ssl_forced: 1, certificate: npmCertificates[1], meta: { nginx_online: true } }, + // A certificate that ran out, but on a host that is switched off: nobody is served it, so it is not a problem. + { id: 12, domain_names: ["old.example.com"], forward_scheme: "http", forward_host: "10.0.0.7", forward_port: 80, enabled: 0, ssl_forced: 0, certificate: npmCertificates[2], meta: {} }, + { id: 13, domain_names: ["broken.example.com"], forward_scheme: "http", forward_host: "10.0.0.8", forward_port: 80, enabled: 1, ssl_forced: 0, certificate: null, meta: { nginx_online: false, nginx_err: "host not found in upstream" } }, +]; +let npmRequests: string[] = []; + +function reply(res: ServerResponse, status: number, body: unknown) { + res.writeHead(status, { "content-type": "application/json" }); + res.end(JSON.stringify(body)); +} + +function npmRoute(req: IncomingMessage, res: ServerResponse) { + const url = req.url ?? ""; + npmRequests.push(`${req.method} ${url.split("?")[0]}`); + if (url === "/api/tokens" && req.method === "POST") { + let raw = ""; + req.on("data", (c) => (raw += c)); + req.on("end", () => { + const b = JSON.parse(raw || "{}"); + if (b.identity === "viewer@example.com" && b.secret === npmPassword) return reply(res, 200, { token: "npm-token", expires: inDays(1) }); + return reply(res, 400, { error: { message: "Invalid email or password" } }); + }); + return; + } + if (req.headers.authorization !== "Bearer npm-token") return reply(res, 401, {}); + if (url.startsWith("/api/nginx/proxy-hosts")) return reply(res, 200, npmHosts); + if (url.startsWith("/api/nginx/certificates")) return reply(res, 200, npmCertificates); + if (url === "/api/") return reply(res, 200, { status: "OK", version: { major: 2, minor: 11, revision: 3 } }); + return reply(res, 404, {}); +} + +// ─── A pretend Home Assistant ─────────────────────────────────────────────── + +let haToken = "good-token"; +let haStates: Record[] = []; +const state = (entity_id: string, s: string, attributes: Record = {}) => ({ entity_id, state: s, attributes, last_changed: "2026-10-20T08:00:00+00:00" }); +function haRoute(req: IncomingMessage, res: ServerResponse) { + if (req.headers.authorization !== `Bearer ${haToken}`) return reply(res, 401, { message: "401: Unauthorized" }); + if (req.url === "/api/") return reply(res, 200, { message: "API running." }); + if (req.url === "/api/states") return reply(res, 200, haStates); + return reply(res, 404, {}); +} + +let npmServer: Server; +let haServer: Server; +let npmUrl = ""; +let haUrl = ""; +let npmId = 0; +let haId = 0; + +before(async () => { + npmServer = await new Promise((resolve) => { + const s = createServer(npmRoute).listen(0, "127.0.0.1", () => resolve(s)); + }); + haServer = await new Promise((resolve) => { + const s = createServer(haRoute).listen(0, "127.0.0.1", () => resolve(s)); + }); + npmUrl = `http://127.0.0.1:${(npmServer.address() as AddressInfo).port}`; + haUrl = `http://127.0.0.1:${(haServer.address() as AddressInfo).port}`; +}); +after(() => { + npmServer.close(); + haServer.close(); + try { + rmSync(dir, { recursive: true, force: true }); + } catch { + // Windows may still hold the database file + } +}); + +describe("normalising what they say", () => { + test("NPM writes its times without a zone, and they are UTC", () => { + assert.equal(isoOf("2026-12-31 23:59:59"), "2026-12-31T23:59:59.000Z"); + assert.equal(isoOf("2026-12-31T23:59:59+01:00"), "2026-12-31T22:59:59.000Z"); + assert.equal(isoOf("nonsense"), null); + assert.equal(isoOf(null), null); + }); + + test("a proxy host: where it goes, whether it is on, and that NPM's own error makes it not working; a host with no id is nothing", () => { + const h = hostFrom(npmHosts[3])!; + assert.deepEqual([h.domains, h.forwardHost, h.forwardPort, h.enabled, h.online, h.error], [["broken.example.com"], "10.0.0.8", 80, true, false, "host not found in upstream"]); + const ok = hostFrom(npmHosts[0])!; + assert.deepEqual([ok.sslForced, ok.online, ok.certificate?.id], [true, true, 1]); + assert.equal(hostFrom({ domain_names: ["x"] }), null); + assert.equal(hostFrom(npmHosts[2])!.enabled, false); + }); + + test("a Home Assistant entity: a number when its state is one, unavailable when it says nothing, its friendly name or else its id", () => { + const e = entityFrom(state("sensor.ups_battery", "87.5", { friendly_name: "UPS battery", unit_of_measurement: "%", device_class: "battery" }))!; + assert.deepEqual([e.name, e.value, e.unit, e.deviceClass, e.unavailable], ["UPS battery", 87.5, "%", "battery", false]); + const off = entityFrom(state("switch.pump", "unavailable"))!; + assert.deepEqual([off.name, off.value, off.unavailable], ["switch.pump", null, true]); + assert.equal(entityFrom(state("light.x", "on"))!.value, null, "on/off is not a number"); + assert.equal(entityFrom(state("sensor.blank", ""))!.value, null); + assert.equal(entityFrom({ state: "1" }), null); + }); +}); + +describe("Nginx Proxy Manager", () => { + const cfg = (extra: Record = {}) => ({ url: npmUrl, email: "viewer@example.com", password: npmPassword, ...extra }) as never; + + test("signs in, then only reads: hosts with their certificate, the certificates, the version", async () => { + npmRequests = []; + const snap = await createNpmAdapter(cfg()).fetchSnapshot(); + assert.equal(snap.version, "2.11.3"); + assert.equal(snap.hosts.length, 4); + assert.equal(snap.certificates.length, 3); + assert.ok(npmRequests.every((r) => r.startsWith("GET") || r === "POST /api/tokens"), "nothing but the sign-in and reads"); + }); + + test("a wrong password is said plainly, and the login check works as a ping", async () => { + await assert.rejects(createNpmAdapter(cfg({ password: "wrong" })).fetchSnapshot(), /did not accept the email and password/); + assert.equal((await createNpmAdapter(cfg()).ping()).ok, true); + assert.equal((await createNpmAdapter(cfg({ password: "wrong" })).ping()).ok, false); + }); + + test("certificates in use that run out soon are a problem — critical in the last days, and an expired one too — but not on a host that is off", async () => { + const snap = await createNpmAdapter(cfg()).fetchSnapshot(); + const problems = npmProblems(1, "Edge NPM", snap, new Date()); + const by = Object.fromEntries(problems.map((p) => [p.key, p])); + assert.deepEqual(Object.keys(by).sort(), ["npm-cert:1:2", "npm-host:1:13"], "wiki is fine (40 days), old is on a host that is off"); + assert.equal(by["npm-cert:1:2"].severity, "critical"); + assert.match(by["npm-cert:1:2"].message, /git\.example\.com.*expires in [12] days?/); + assert.match(by["npm-host:1:13"].message, /broken\.example\.com is not working.*host not found in upstream/); + const later = npmProblems(1, "Edge NPM", snap, new Date(Date.now() + 30 * DAY)); + assert.ok(later.some((p) => p.key === "npm-cert:1:1"), "and the wiki one in time"); + assert.match(later.find((p) => p.key === "npm-cert:1:2")!.message, /expired 2[89] days ago/); + }); +}); + +describe("Home Assistant", () => { + const cfg = (extra: Record = {}) => ({ url: haUrl, token: haToken, ...extra }) as never; + + test("lists every entity with the token; a refused token and a wrong address are said plainly", async () => { + haStates = [state("sensor.ups_battery", "87", { friendly_name: "UPS battery", unit_of_measurement: "%" }), state("light.hall", "on")]; + assert.equal((await createHomeAssistantAdapter(cfg()).listEntities()).length, 2); + await assert.rejects(createHomeAssistantAdapter(cfg({ token: "nope" })).listEntities(), /did not accept the token/); + const ping = await createHomeAssistantAdapter(cfg()).ping(); + assert.equal(ping.ok, true); + }); + + test("an entity that says nothing is only a problem after a while, and a number only past a limit that was set", () => { + const now = new Date("2026-10-20T12:00:00Z"); + const watched = [ + { entityId: "sensor.ups", name: "UPS", above: null, below: 30 }, + { entityId: "sensor.freezer", name: null, above: -10, below: null }, + { entityId: "switch.pump", name: "Pump", above: null, below: null }, + { entityId: "sensor.fine", name: null, above: 50, below: 10 }, + ]; + const rows = new Map([ + ["sensor.ups", { friendlyName: "UPS battery", state: "22", value: 22, unit: "%", unavailableSince: null }], + ["sensor.freezer", { friendlyName: "Freezer", state: "-18", value: -18, unit: "°C", unavailableSince: null }], + ["switch.pump", { friendlyName: null, state: "unavailable", value: null, unit: null, unavailableSince: "2026-10-20T11:30:00Z" }], + ["sensor.fine", { friendlyName: null, state: "20", value: 20, unit: null, unavailableSince: null }], + ]); + const problems = haProblems(3, "Home", watched, rows, now); + assert.deepEqual(problems.map((p) => p.key), ["ha-limit:3:sensor.ups", "ha-unavailable:3:switch.pump"]); + assert.match(problems[0].message, /UPS is 22 %, below its limit of 30 %/); + assert.match(problems[1].message, /Pump has been unavailable in Home Assistant for 30 min/); + rows.get("switch.pump")!.unavailableSince = "2026-10-20T11:55:00Z"; + assert.equal(haProblems(3, "Home", watched, rows, now).length, 1, "five minutes of silence is nothing"); + }); + + test("when an entity first went quiet is kept until it speaks again", () => { + assert.equal(trackUnavailable(null, true, "T1"), "T1"); + assert.equal(trackUnavailable("T0", true, "T1"), "T0"); + assert.equal(trackUnavailable("T0", false, "T1"), null); + }); +}); + +describe("kept in the app", () => { + before(async () => { + await db.insert(users).values([ + { oidcSub: "viewer", name: "Vic", role: "viewer" }, + { oidcSub: "operator", name: "Olga", role: "operator" }, + ]); + const [npmCred] = await db.insert(integrationCredentials).values({ name: "npm:Edge", encryptedSecret: encryptSecret(JSON.stringify({ password: "pw" })) }).returning(); + const [npmRow] = await db.insert(integrations).values({ type: "npm", name: "Edge NPM", baseUrl: npmUrl, credentialId: npmCred.id, config: JSON.stringify({ url: npmUrl, email: "viewer@example.com" }) }).returning(); + npmId = npmRow.id; + const [haCred] = await db.insert(integrationCredentials).values({ name: "ha:Home", encryptedSecret: encryptSecret(JSON.stringify({ token: "good-token" })) }).returning(); + const [haRow] = await db.insert(integrations).values({ type: "homeassistant", name: "Home", baseUrl: haUrl, credentialId: haCred.id, config: JSON.stringify({ url: haUrl }) }).returning(); + haId = haRow.id; + await db.insert(servers).values({ name: "wiki-host", hostname: "wiki-host.example.lan", ipAddresses: JSON.stringify(["10.0.0.5"]), osType: "linux", apiTokenHash: "x", apiTokenPrefix: "x" } as never); + }); + + test("the field forms need what each one needs", () => { + assert.deepEqual(validateIntegrationConfig("npm", { url: "https://npm", email: "a@b" }), ["password"]); + assert.deepEqual(validateIntegrationConfig("homeassistant", { url: "https://ha" }), ["token"]); + assert.deepEqual(validateIntegrationConfig("homeassistant", { url: "https://ha", token: "t" }), []); + }); + + test("NPM is read once a minute at most, and a failed read is kept just as briefly", async () => { + clearNpmCacheForTests(); + npmRequests = []; + const a = await readNpm(npmId); + const b = await readNpm(npmId); + assert.ok(a.snapshot && b.snapshot); + assert.equal(npmRequests.filter((r) => r === "POST /api/tokens").length, 1); + await readNpm(npmId, true); + assert.equal(npmRequests.filter((r) => r === "POST /api/tokens").length, 2, "asking again is possible"); + }); + + test("on the Alerts page: the certificate in its last days and the host NPM can't set up, from the right place", async () => { + clearNpmCacheForTests(); + invalidateAlertsCache(); + const report = await getAlerts(true); + const cert = report.alerts.find((a) => a.id === `expiry:npm-cert:${npmId}:2`)!; + assert.ok(cert, "the certificate that runs out"); + assert.deepEqual([cert.severity, cert.source, cert.link, cert.target?.type], ["critical", "Nginx Proxy Manager", "/proxy-hosts", "integration"]); + const host = report.alerts.find((a) => a.id === `monitoring:npm-host:${npmId}:13`)!; + assert.ok(host); + assert.equal(report.alerts.some((a) => a.id === `expiry:npm-cert:${npmId}:3`), false, "the one on the host that is off is left alone"); + }); + + test("an NPM that can't be read says so rather than being quiet", async () => { + npmPassword = "changed"; + clearNpmCacheForTests(); + invalidateAlertsCache(); + const report = await getAlerts(true); + assert.ok(report.couldntCheck.some((c) => /Nginx Proxy Manager/.test(c.name))); + assert.equal(report.alerts.some((a) => a.id.startsWith("expiry:npm-cert")), false, "and raises nothing from what it could not read"); + npmPassword = "pw"; + clearNpmCacheForTests(); + }); + + test("hosts NPM serves are offered as checks on the name people use, linked to the server it forwards to — and not when a check already covers it", async () => { + invalidateAlertsCache(); + const { suggestions } = await loadSuggestions(); + const wiki = suggestions.find((s) => s.target === "https://wiki.example.com/")!; + assert.ok(wiki); + assert.deepEqual([wiki.kind, wiki.serverName], ["http", "wiki-host"]); + assert.match(wiki.reason, /Edge NPM serves wiki\.example\.com, forwarding to wiki-host/); + assert.ok(suggestions.some((s) => s.target === "http://broken.example.com/"), "a host with no certificate is a plain web check"); + assert.ok(!suggestions.some((s) => /old\.example\.com/.test(s.target)), "a host that is off is not offered"); + const none = suggestChecks({ servers: [], dns: [], secrets: [], dismissed: new Set(), existing: [{ kind: "http", target: "https://wiki.example.com/", port: null }], proxied: [{ domain: "wiki.example.com", secure: true, serverId: null, serverName: null, integrationName: "x" }, { domain: "*.example.com", secure: true, serverId: null, serverName: null, integrationName: "x" }, { domain: "10.0.0.1", secure: false, serverId: null, serverName: null, integrationName: "x" }] }); + assert.deepEqual(none.suggestions, []); + }); + + test("the NPM page: each host with the server it forwards to, its certificate, and the problems; anyone signed in may see it", async () => { + const a = express(); + a.use(express.json()); + a.use((req, _res, next) => { + (req as unknown as { session: unknown }).session = { user: { sub: "viewer" } }; + next(); + }); + a.use("/api/npm", npmRouter); + const s = await new Promise((resolve) => { + const x = a.listen(0, "127.0.0.1", () => resolve(x)); + }); + const res = await fetch(`http://127.0.0.1:${(s.address() as AddressInfo).port}/api/npm?refresh=1`); + assert.equal(res.status, 200); + const body = (await res.json()) as any; + const npm = body.integrations[0]; + assert.equal(npm.version, "2.11.3"); + const wiki = npm.hosts.find((h: any) => h.id === 10); + assert.deepEqual([wiki.server?.name, wiki.certificate.name], ["wiki-host", "wiki.example.com"]); + assert.equal(npm.hosts.find((h: any) => h.id === 11).server, null, "an address no server has is left unmatched"); + assert.equal(npm.problems.length, 2); + s.close(); + }); + + describe("Home Assistant stored", () => { + let app: Server; + let base = ""; + let who = "viewer"; + before(async () => { + 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/home-assistant", homeAssistantRouter); + 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/home-assistant`; + }); + after(() => app.close()); + + const put = (body: unknown) => fetch(`${base}/${haId}/watched`, { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }); + + test("choosing what to watch needs an operator; only entities that exist and sensible limits are accepted", async () => { + haStates = [state("sensor.ups_battery", "87", { friendly_name: "UPS battery", unit_of_measurement: "%" }), state("switch.pump", "on", { friendly_name: "Pump" }), state("light.hall", "on")]; + who = "viewer"; + assert.equal((await put({ entityId: "sensor.ups_battery" })).status, 403); + assert.equal((await fetch(`${base}/${haId}/entities`)).status, 403); + who = "operator"; + assert.equal((await put({ entityId: "not an entity" })).status, 400); + assert.equal((await put({ entityId: "sensor.ups_battery", above: 10, below: 20 })).status, 400, "the lower limit has to be lower"); + assert.equal((await fetch(`${base}/999/entities`)).status, 404); + const list = (await (await fetch(`${base}/${haId}/entities?q=ups`)).json()) as any; + assert.deepEqual(list.entities.map((e: any) => e.entityId), ["sensor.ups_battery"]); + const ok = await put({ entityId: "sensor.ups_battery", name: "UPS", below: 30 }); + assert.equal(ok.status, 200); + assert.equal(((await ok.json()) as any).status.ok, true); + assert.equal((await put({ entityId: "switch.pump" })).status, 200); + const [row] = await db.select().from(haEntities).where(eq(haEntities.entityId, "sensor.ups_battery")); + assert.deepEqual([row.state, row.value, row.unit], ["87", 87, "%"]); + }); + + test("the page lists what is watched with its state; a number keeps a point of history, but two passes close together keep one", async () => { + who = "viewer"; + const body = (await (await fetch(base)).json()) as any; + const ha = body.integrations[0]; + assert.deepEqual(ha.watched.map((w) => [w.entityId, w.entity?.state]), [["switch.pump", "on"], ["sensor.ups_battery", "87"]], "by the name it is shown under: Pump, then UPS"); + assert.equal(ha.fresh, true); + await syncHomeAssistant(haId); + const readings = await db.select().from(haReadings).where(eq(haReadings.entityId, "sensor.ups_battery")); + assert.equal(readings.length, 1, "the pump is not a number, the second pass is too soon"); + const hist = (await (await fetch(`${base}/${haId}/history?entity=sensor.ups_battery&days=7`)).json()) as any; + assert.equal(hist.days, 7); + assert.ok(hist.points.length >= 1); + }); + + test("a number past its limit is an alert, an entity that goes quiet becomes one after a while, and a Home Assistant that is down holds them rather than clearing", async () => { + haStates = [state("sensor.ups_battery", "22", { friendly_name: "UPS battery", unit_of_measurement: "%" }), state("switch.pump", "unavailable", { friendly_name: "Pump" })]; + await syncHomeAssistant(haId, new Date()); + invalidateAlertsCache(); + let report = await getAlerts(true); + const limit = report.alerts.find((a) => a.id === `monitoring:ha-limit:${haId}:sensor.ups_battery`)!; + assert.ok(limit); + assert.deepEqual([limit.source, limit.link], ["Home Assistant", "/home-assistant"]); + assert.equal(report.alerts.some((a) => a.id.includes("ha-unavailable")), false, "the pump just went quiet"); + + await db.update(haEntities).set({ unavailableSince: new Date(Date.now() - 40 * 60_000).toISOString() }).where(eq(haEntities.entityId, "switch.pump")); + invalidateAlertsCache(); + report = await getAlerts(true); + assert.ok(report.alerts.some((a) => a.id === `monitoring:ha-unavailable:${haId}:switch.pump`)); + + haToken = "revoked"; + const down = await syncHomeAssistant(haId); + assert.equal(down.ok, false); + assert.match(down.error ?? "", /did not accept the token/); + invalidateAlertsCache(); + report = await getAlerts(true); + assert.ok(report.couldntCheck.some((c) => /Home Assistant/.test(c.name))); + assert.equal(report.alerts.some((a) => a.id.includes("ha-limit")), false, "neither raised nor cleared while it can't be read"); + assert.equal(isHaFresh((await haSyncStatuses())[haId], Date.now()), false); + haToken = "good-token"; + assert.equal((await syncHomeAssistant(haId)).ok, true); + }); + + test("an entity that disappears from Home Assistant counts as quiet; stopping watching forgets it and its history", async () => { + haStates = [state("sensor.ups_battery", "50", { unit_of_measurement: "%" })]; + await syncHomeAssistant(haId); + const [pump] = await db.select().from(haEntities).where(eq(haEntities.entityId, "switch.pump")); + assert.equal(pump.state, "missing"); + who = "operator"; + assert.equal((await fetch(`${base}/${haId}/watched/sensor.ups_battery`, { method: "DELETE" })).status, 204); + assert.equal((await db.select().from(haReadings).where(eq(haReadings.entityId, "sensor.ups_battery"))).length, 0); + assert.equal((await fetch(`${base}/${haId}/watched/sensor.ups_battery`, { method: "DELETE" })).status, 404); + }); + + test("removing the integration removes everything read from it", async () => { + await removeHomeAssistantData(haId); + assert.equal((await db.select().from(haWatched)).length, 0); + assert.equal((await db.select().from(haEntities)).length, 0); + assert.equal((await haSyncStatuses())[haId], undefined); + assert.equal((await db.select({ id: integrationCredentials.id }).from(integrationCredentials)).length >= 1, true); + }); + }); +}); diff --git a/server/test/osLifecycle.test.ts b/server/test/osLifecycle.test.ts new file mode 100644 index 0000000..3cc93fe --- /dev/null +++ b/server/test/osLifecycle.test.ts @@ -0,0 +1,140 @@ +/** + * When the operating system a server runs stops being supported: what the table knows, how an agent's answer is read, the alert, and that the agent's own + * script says it (the shell part is checked by reading it; the answer it would give is a plain JSON object). + * + * Run with: npm test --workspace server + */ +import { test, describe, before, after } from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const dir = mkdtempSync(join(tmpdir(), "hm-oslife-")); +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 { db } = await import("../src/db/client.js"); +const { servers, maintenanceWindows } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const { lifecycleOf, releaseKey, supportState, daysOfSupportLeft } = await import("../src/services/osLifecycle.js"); +const { syncServerTasks } = await import("../src/services/taskSync.js"); +const { getAlerts, invalidateAlertsCache } = await import("../src/services/alerts.js"); +const { updateSettings } = await import("../src/services/settingsStore.js"); +const { latestAgentVersions } = await import("../src/services/agentVersions.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); + +const repo = fileURLToPath(new URL("../../", import.meta.url)); +after(() => { + try { + rmSync(dir, { recursive: true, force: true }); + } catch { + // Windows may still hold the database file + } +}); + +describe("reading what an agent says it runs", () => { + test("a release is found by its distribution and version, however the version is written", () => { + assert.deepEqual(releaseKey({ id: "ubuntu", version: "22.04" }), { family: "ubuntu", key: "22.04" }); + assert.deepEqual(releaseKey({ id: "debian", version: "12" }), { family: "debian", key: "12" }); + assert.deepEqual(releaseKey({ id: "raspbian", version: "11" }), { family: "debian", key: "11" }, "Raspberry Pi OS is Debian"); + assert.deepEqual(releaseKey({ id: "rocky", version: "9.4" }), { family: "rocky", key: "9" }); + assert.deepEqual(releaseKey({ id: "alpine", version: "3.19.1" }), { family: "alpine", key: "3.19" }); + assert.deepEqual(releaseKey({ id: "proxmox-ve", version: "8.2" }), { family: "proxmox-ve", key: "8" }); + assert.deepEqual(releaseKey({ id: "centos", name: "CentOS Stream 9", version: "9" }), { family: "centos-stream", key: "9" }); + assert.deepEqual(releaseKey({ id: "centos", name: "CentOS Linux 7 (Core)", version: "7" }), { family: "centos-classic", key: "7" }); + assert.deepEqual(releaseKey({ id: "windows", name: "Windows Server 2019 Standard", version: "17763" }), { family: "windows-server", key: "17763" }); + assert.deepEqual(releaseKey({ id: "windows", name: "Windows 11 Pro", version: "22631" }), { family: "windows-client", key: "22631" }); + assert.equal(releaseKey({ id: "arch", version: "rolling" }), null, "a rolling distribution has no end"); + assert.equal(releaseKey({ id: "", version: "1" }), null); + assert.equal(releaseKey({ id: "ubuntu" }), null); + }); + + test("the same build number is a different product on a server and a client", () => { + assert.equal(lifecycleOf({ id: "windows", name: "Windows Server 2025 Datacenter", version: "26100" })?.product, "Windows Server 2025"); + assert.equal(lifecycleOf({ id: "windows", name: "Windows 11 Pro", version: "26100" })?.product, "Windows 11 24H2"); + }); + + test("what the table knows: a name and a date; a release it does not know is named as the machine named itself, with no date", () => { + assert.deepEqual(lifecycleOf({ id: "ubuntu", name: "Ubuntu 20.04.6 LTS", version: "20.04" }), { product: "Ubuntu 20.04 LTS", endsOn: "2025-05-31" }); + assert.deepEqual(lifecycleOf({ id: "debian", version: "12" }), { product: "Debian 12 (bookworm)", endsOn: "2028-06-30" }); + assert.deepEqual(lifecycleOf({ id: "ubuntu", name: "Ubuntu 31.04", version: "31.04" }), { product: "Ubuntu 31.04", endsOn: null }); + assert.equal(lifecycleOf({ id: "ubuntu", version: "31.04" }), null, "nothing to call it, nothing to say"); + assert.equal(lifecycleOf({ id: "templeos", version: "5" }), null); + }); + + test("ended once the day is over, soon within the warning, ok beyond it, unknown with no date", () => { + const now = new Date("2026-10-20T12:00:00Z"); + assert.equal(supportState("2026-10-19", now, 90), "ended"); + assert.equal(supportState("2026-10-20", now, 90), "soon", "the last day is still a day of support"); + assert.equal(supportState("2027-01-10", now, 90), "soon"); + assert.equal(supportState("2027-06-01", now, 90), "ok"); + assert.equal(supportState(null, now, 90), "unknown"); + assert.equal(daysOfSupportLeft("2026-10-30", now), 10); + assert.equal(daysOfSupportLeft("2026-10-10", now), -10); + }); +}); + +describe("what the agent says, and what the Alerts page makes of it", () => { + let id = 0; + before(async () => { + id = (await db.insert(servers).values({ name: "old-box", apiTokenHash: "o", apiTokenPrefix: "o", lastSeenAt: new Date().toISOString() }).returning({ id: servers.id }))[0].id; + }); + const row = () => db.select().from(servers).where(eq(servers.id, id)).then((r) => r[0]); + const report = (os: unknown) => syncServerTasks(id, { osType: "linux", tasks: [], system: { os } as never }); + + test("it is stored, bounded; an agent that says nothing leaves what was said", async () => { + await report({ id: "Ubuntu", name: "Ubuntu 20.04.6 LTS", version: "20.04" }); + let r = await row(); + assert.deepEqual([r.osId, r.osName, r.osVersion], ["ubuntu", "Ubuntu 20.04.6 LTS", "20.04"]); + await syncServerTasks(id, { osType: "linux", tasks: [], system: {} }); + r = await row(); + assert.equal(r.osId, "ubuntu", "an older agent does not wipe it"); + await report({ id: "x".repeat(200), name: "n".repeat(500), version: "v".repeat(200) }); + r = await row(); + assert.deepEqual([r.osId!.length, r.osName!.length, r.osVersion!.length], [40, 80, 40]); + await report({ id: "ubuntu", name: "Ubuntu 20.04.6 LTS", version: "20.04" }); + }); + + test("a release past its end is a warning with the date, on the Alerts page, under the server", async () => { + invalidateAlertsCache(); + const alert = (await getAlerts(true)).alerts.find((a) => a.id === `updates:os-support:${id}`)!; + assert.ok(alert, "it is raised"); + assert.deepEqual([alert.severity, alert.category, alert.link, alert.target?.name, alert.silenced], ["warning", "updates", `/servers/${id}`, "old-box", false]); + assert.match(alert.message, /old-box runs Ubuntu 20\.04 LTS, whose support ended on 2025-05-31/); + }); + + test("one with a supported release is not raised, and the warning is a setting (0 turns it off)", async () => { + await report({ id: "debian", name: "Debian GNU/Linux 12 (bookworm)", version: "12" }); + invalidateAlertsCache(); + assert.equal((await getAlerts(true)).alerts.some((a) => a.id === `updates:os-support:${id}`), false); + await report({ id: "ubuntu", name: "Ubuntu 20.04.6 LTS", version: "20.04" }); + await updateSettings({ healthChecks: { osSupportWarnDays: 0 } }); + invalidateAlertsCache(); + assert.equal((await getAlerts(true)).alerts.some((a) => a.id === `updates:os-support:${id}`), false, "off"); + await updateSettings({ healthChecks: { osSupportWarnDays: 90 } }); + }); + + test("a maintenance window on the server holds it back", async () => { + await db.insert(maintenanceWindows).values({ targetType: "server", targetId: id, startedAt: new Date(Date.now() - 1000).toISOString(), endsAt: new Date(Date.now() + 3600_000).toISOString() }); + invalidateAlertsCache(); + assert.equal((await getAlerts(true)).alerts.find((a) => a.id === `updates:os-support:${id}`)?.silenced, true); + await db.delete(maintenanceWindows).where(eq(maintenanceWindows.targetId, id)); + }); +}); + +describe("the agent scripts say it", () => { + test("Linux reads /etc/os-release (and asks Proxmox by its own command) and reports it; Windows reports the product and the build; both are a new version", () => { + const linux = readFileSync(join(repo, "agent", "linux", "report-tasks.sh"), "utf8"); + assert.ok(linux.includes("collect_os()") && linux.includes("OS_RELEASE_FILE") && linux.includes("pveversion") && linux.includes("os: $os")); + const windows = readFileSync(join(repo, "agent", "windows", "report-tasks.ps1"), "utf8"); + assert.ok(windows.includes("Win32_OperatingSystem") && windows.includes("os = $osInfo") && windows.includes("BuildNumber")); + const latest = latestAgentVersions(); + assert.ok((latest.linux ?? 0) >= 7 && (latest.windows ?? 0) >= 6, "an agent that does not say it is behind"); + }); +}); diff --git a/server/test/racks.test.ts b/server/test/racks.test.ts new file mode 100644 index 0000000..69b37f5 --- /dev/null +++ b/server/test/racks.test.ts @@ -0,0 +1,59 @@ +/** + * The rack view: which unit a piece of hardware says it sits in, how the racks are made from that, clashes and what is not placed. + * + * Run with: npm test --workspace server + */ +import { test, describe } from "node:test"; +import assert from "node:assert/strict"; +import { buildRacks, parseRackUnit, type RackAsset } from "../src/services/racks.js"; + +const asset = (id: number, name: string, location: string | null, rackUnit: string | null, extra: Partial = {}): RackAsset => ({ id, name, kind: "server", manufacturer: null, model: null, location, rackUnit, powerWatts: null, serverId: null, ...extra }); + +describe("reading a unit", () => { + test("a unit, or a run of them, in the ways people write them", () => { + assert.deepEqual(parseRackUnit("U12"), { from: 12, to: 12 }); + assert.deepEqual(parseRackUnit("u3"), { from: 3, to: 3 }); + assert.deepEqual(parseRackUnit("12"), { from: 12, to: 12 }); + assert.deepEqual(parseRackUnit("U12-13"), { from: 12, to: 13 }); + assert.deepEqual(parseRackUnit("12 – 14"), { from: 12, to: 14 }); + assert.deepEqual(parseRackUnit("U14-U12"), { from: 12, to: 14 }, "either way round"); + assert.equal(parseRackUnit("top shelf"), null); + assert.equal(parseRackUnit("U0"), null); + assert.equal(parseRackUnit(""), null); + assert.equal(parseRackUnit(null), null); + }); +}); + +describe("making racks", () => { + test("hardware is grouped by where it says it is, placed by unit, in a rack of a real size", () => { + const racks = buildRacks([asset(1, "Switch", "Rack A", "U40", { kind: "network", powerWatts: 40 }), asset(2, "NAS", "Rack A", "U10-13", { powerWatts: 120 }), asset(3, "UPS", "Rack A", "U1-3", { kind: "power" }), asset(4, "Laptop", "Desk", null)]); + assert.equal(racks.length, 1, "a desk with no unit is not a rack"); + const a = racks[0]; + assert.deepEqual([a.name, a.units, a.usedUnits, a.watts], ["Rack A", 42, 1 + 4 + 3, 160]); + assert.deepEqual(a.slots.map((s) => [s.name, s.from, s.to]), [["UPS", 1, 3], ["NAS", 10, 13], ["Switch", 40, 40]], "from the bottom up"); + assert.ok(a.slots.every((s) => !s.clash)); + }); + + test("a small rack is drawn small, and a tall piece makes it as tall as it needs", () => { + assert.equal(buildRacks([asset(1, "A", "R", "U5")])[0].units, 12); + assert.equal(buildRacks([asset(1, "A", "R", "U13")])[0].units, 18); + assert.equal(buildRacks([asset(1, "A", "R", "U43-48")])[0].units, 48); + assert.equal(buildRacks([asset(1, "A", "R", "U60-70")])[0].units, 70, "beyond any real rack it just fits"); + }); + + test("two pieces on the same unit clash, and both are said to", () => { + const [rack] = buildRacks([asset(1, "A", "R", "U4-5"), asset(2, "B", "R", "U5"), asset(3, "C", "R", "U8")]); + assert.deepEqual(rack.slots.map((s) => [s.name, s.clash]), [["A", true], ["B", true], ["C", false]]); + assert.equal(rack.usedUnits, 3, "a unit is used once however many claim it"); + }); + + test("hardware that names a rack and no unit is listed beside it, not placed", () => { + const [rack] = buildRacks([asset(1, "NAS", "Rack A", "U10"), asset(2, "Cable box", "Rack A", null), asset(3, "Patch panel", "Rack A", "somewhere")]); + assert.deepEqual(rack.unplaced.map((u) => u.name), ["Cable box", "Patch panel"]); + }); + + test("a unit with no place goes in a rack of its own, last; racks are in order, numbers as numbers", () => { + const racks = buildRacks([asset(1, "X", null, "U2"), asset(2, "Y", "Rack 10", "U1"), asset(3, "Z", "Rack 2", "U1")]); + assert.deepEqual(racks.map((r) => r.name), ["Rack 2", "Rack 10", "(no rack named)"]); + }); +}); diff --git a/server/test/todosAndNotes.test.ts b/server/test/todosAndNotes.test.ts new file mode 100644 index 0000000..76d991c --- /dev/null +++ b/server/test/todosAndNotes.test.ts @@ -0,0 +1,181 @@ +/** + * The to-do list and notes: who may write, what is checked, ticking off and bringing back, what shows in Coming up and My work. + * + * Run with: npm test --workspace server + */ +import { test, describe, before, after } from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import type { AddressInfo } from "node:net"; +import type { Server } from "node:http"; + +const dir = mkdtempSync(join(tmpdir(), "hm-todos-")); +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, notes, todos, auditLog } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const { todosRouter, notesRouter } = await import("../src/routes/todos.js"); +const { loadAgendaData, agendaFromData } = await import("../src/services/agenda.js"); +const { buildMyWork } = await import("../src/services/myWork.js"); +const { isRealDay } = await import("../src/services/todos.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); + +let app: Server; +let base = ""; +let who = "operator"; +const ids: Record = {}; +const send = async (method: string, path: string, body?: unknown) => { + const res = await fetch(`${base}${path}`, { method, headers: { "content-type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) }); + return { status: res.status, body: res.status === 204 ? null : ((await res.json().catch(() => null)) as any) }; +}; +const day = (offset: number) => new Date(Date.now() + offset * 86_400_000).toISOString().slice(0, 10); + +before(async () => { + const rows = await db + .insert(users) + .values([ + { oidcSub: "admin", name: "Ada", role: "admin" }, + { oidcSub: "operator", name: "Olga", role: "operator" }, + { oidcSub: "viewer", name: "Vic", role: "viewer" }, + ]) + .returning({ id: users.id, oidcSub: users.oidcSub }); + for (const r of rows) ids[r.oidcSub] = r.id; + ids.web = (await db.insert(servers).values({ name: "web", apiTokenHash: "w", apiTokenPrefix: "w" }).returning({ id: servers.id }))[0].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/todos", todosRouter); + a.use("/api/notes", notesRouter); + 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`; +}); +after(() => { + app.close(); + try { + rmSync(dir, { recursive: true, force: true }); + } catch { + // Windows may still hold the database file + } +}); + +describe("the to-do list", () => { + let jobId = 0; + + test("a real day is a real day", () => { + assert.equal(isRealDay("2026-10-20"), true); + assert.equal(isRealDay("2026-02-30"), false); + assert.equal(isRealDay("next week"), false); + }); + + test("everyone signed in reads it; only an operator writes", async () => { + who = "viewer"; + assert.equal((await send("GET", "/todos")).status, 200); + assert.equal((await send("POST", "/todos", { title: "x" })).status, 403); + assert.equal((await send("PATCH", "/todos/1", { done: true })).status, 403); + assert.equal((await send("DELETE", "/todos/1")).status, 403); + }); + + test("a job needs a title; the day must be a day; it can be about a server and handed to an operator, and not to a viewer", async () => { + who = "operator"; + assert.equal((await send("POST", "/todos", { title: " " })).status, 400); + assert.equal((await send("POST", "/todos", { title: "x", dueDate: "tomorrow" })).body.error, "invalid_date"); + assert.equal((await send("POST", "/todos", { title: "x", assigneeId: ids.viewer })).body.error, "invalid_assignee"); + assert.equal((await send("POST", "/todos", { title: "x", targetType: "server", targetId: 9999 })).body.error, "unknown_target"); + assert.equal((await send("POST", "/todos", { title: "x".repeat(200) })).body.error, "too_long"); + const made = await send("POST", "/todos", { title: "Replace the UPS battery", detail: "APC, model in the rack", dueDate: day(1), assigneeId: ids.operator, targetType: "server", targetId: ids.web }); + assert.equal(made.status, 201); + jobId = made.body.todo.id; + assert.deepEqual([made.body.todo.title, made.body.todo.assignee.name, made.body.todo.target.name, made.body.todo.doneAt], ["Replace the UPS battery", "Olga", "web", null]); + }); + + test("open jobs come soonest-due first, with those without a day last; ticking one off keeps it, and it comes back", async () => { + await send("POST", "/todos", { title: "Someday" }); + await send("POST", "/todos", { title: "Next week", dueDate: day(7) }); + const open = (await send("GET", "/todos")).body.todos.map((t: any) => t.title); + assert.deepEqual(open, ["Replace the UPS battery", "Next week", "Someday"]); + const done = await send("PATCH", `/todos/${jobId}`, { done: true }); + assert.ok(done.body.todo.doneAt && done.body.todo.doneBy === "Olga"); + const after = (await send("GET", "/todos")).body.todos; + assert.deepEqual(after.map((t: any) => [t.title, t.doneAt !== null]), [["Next week", false], ["Someday", false], ["Replace the UPS battery", true]], "done ones after the open ones"); + const back = await send("PATCH", `/todos/${jobId}`, { done: false }); + assert.equal(back.body.todo.doneAt, null); + }); + + test("a job can be changed, and removed; one that is not there is a 404", async () => { + const changed = await send("PATCH", `/todos/${jobId}`, { title: "Replace the UPS battery (APC)", dueDate: null, assigneeId: null }); + assert.deepEqual([changed.body.todo.title, changed.body.todo.dueDate, changed.body.todo.assignee], ["Replace the UPS battery (APC)", null, null]); + assert.equal((await send("PATCH", "/todos/99999", { done: true })).status, 404); + assert.equal((await send("DELETE", `/todos/${jobId}`)).status, 204); + assert.equal((await send("DELETE", `/todos/${jobId}`)).status, 404); + const kinds = (await db.select().from(auditLog).where(eq(auditLog.category, "todo"))).map((e) => e.action); + assert.ok(["create", "done", "reopen", "update", "delete"].every((a) => kinds.includes(a)), "each is written down"); + }); + + test("a job about a server that is later removed is still there, about nothing", async () => { + const gone = (await db.insert(servers).values({ name: "temp", apiTokenHash: "t", apiTokenPrefix: "t" }).returning({ id: servers.id }))[0].id; + const made = await send("POST", "/todos", { title: "About temp", targetType: "server", targetId: gone }); + await db.delete(servers).where(eq(servers.id, gone)); + const found = (await send("GET", "/todos")).body.todos.find((t: any) => t.id === made.body.todo.id); + assert.equal(found.target, null); + await send("DELETE", `/todos/${made.body.todo.id}`); + }); + + test("an open job with a day is in Coming up (overdue ones too), a done one is not; one handed to somebody is in their My work", async () => { + const soon = (await send("POST", "/todos", { title: "Move the NAS", dueDate: day(3), assigneeId: ids.operator })).body.todo; + const late = (await send("POST", "/todos", { title: "Order a spare disk", dueDate: day(-2), assigneeId: ids.operator })).body.todo; + const finished = (await send("POST", "/todos", { title: "Already done", dueDate: day(2) })).body.todo; + await send("PATCH", `/todos/${finished.id}`, { done: true }); + const agenda = agendaFromData(await loadAgendaData(), new Date(), "UTC", 30); + const titles = agenda.items.filter((i) => i.kind === "todo").map((i) => i.title); + assert.ok(titles.includes("To do: Move the NAS") && titles.includes("Overdue: Order a spare disk")); + assert.ok(!titles.some((t) => t.includes("Already done"))); + const mine = await buildMyWork({ id: ids.operator, name: "Olga", email: null, oidcSub: "operator" }); + assert.deepEqual(mine.todos.map((t) => [t.title, t.overdue, t.dueSoon]), [["Order a spare disk", true, false], ["Move the NAS", false, false]], "overdue first; three days off is not yet soon"); + assert.ok(mine.needsAttention >= 1, "an overdue job wants a look"); + const theirs = await buildMyWork({ id: ids.admin, name: "Ada", email: null, oidcSub: "admin" }); + assert.equal(theirs.todos.length, 0); + await db.delete(todos); + assert.ok(soon && late); + }); +}); + +describe("notes", () => { + test("read by everyone; written by an operator; an empty text takes it away", async () => { + who = "viewer"; + assert.equal((await send("GET", `/notes?targetType=server&targetId=${ids.web}`)).body.note, null); + assert.equal((await send("PUT", "/notes", { targetType: "server", targetId: ids.web, body: "x" })).status, 403); + who = "operator"; + const saved = await send("PUT", "/notes", { targetType: "server", targetId: ids.web, body: "Lives in the **rack**.\n\n- PSU is on the left" }); + assert.deepEqual([saved.status, saved.body.note.updatedBy, saved.body.note.body.includes("**rack**")], [200, "Olga", true]); + const again = await send("PUT", "/notes", { targetType: "server", targetId: ids.web, body: "Replaced." }); + assert.equal((await db.select().from(notes)).length, 1, "one text per thing"); + assert.equal(again.body.note.body, "Replaced."); + who = "viewer"; + assert.equal((await send("GET", `/notes?targetType=server&targetId=${ids.web}`)).body.note.body, "Replaced."); + who = "operator"; + assert.equal((await send("PUT", "/notes", { targetType: "server", targetId: ids.web, body: " \n " })).body.note, null); + assert.equal((await db.select().from(notes)).length, 0); + }); + + test("a note for nothing, or too long, or about something unknown, is refused", async () => { + who = "operator"; + assert.equal((await send("PUT", "/notes", { targetType: "server", targetId: 99999, body: "x" })).status, 404); + assert.equal((await send("PUT", "/notes", { targetType: "server", targetId: ids.web, body: "x".repeat(9000) })).body.error, "too_long"); + assert.equal((await send("PUT", "/notes", { targetType: "rack", targetId: 1, body: "x" })).status, 400); + assert.equal((await send("GET", "/notes?targetType=server")).status, 400); + }); +}); diff --git a/server/test/windowsAgentHealth.test.ts b/server/test/windowsAgentHealth.test.ts index b82c0d1..c57ffe5 100644 --- a/server/test/windowsAgentHealth.test.ts +++ b/server/test/windowsAgentHealth.test.ts @@ -34,7 +34,7 @@ function run(snippet: string): unknown { describe("the Windows agent's health parts", { skip: !havePwsh }, () => { test("it says it is version 5, and stays plain ASCII", () => { const text = readFileSync(script, "utf8"); - assert.match(text, /^\$script:AgentVersion = 5\s*$/m); + assert.match(text, /^\$script:AgentVersion = 6\s*$/m); assert.ok(!/[^\x00-\x7f]/.test(text)); }); diff --git a/web/src/App.tsx b/web/src/App.tsx index ca210da..37a4316 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -7,8 +7,12 @@ import Users from "./pages/Users"; import Secrets from "./pages/Secrets"; import Ipam from "./pages/Ipam"; import NetworkDevices from "./pages/NetworkDevices"; +import ProxyHosts from "./pages/ProxyHosts"; +import HomeAssistant from "./pages/HomeAssistant"; import MyWorkPage from "./pages/MyWork"; import ApiTokens from "./pages/ApiTokens"; +import Todo from "./pages/Todo"; +import InventoryRacks from "./pages/InventoryRacks"; import Ports from "./pages/Ports"; import Dns from "./pages/Dns"; import Servers from "./pages/Servers"; @@ -138,6 +142,7 @@ function Shelled({ user }: { user: CurrentUser }) { } /> } /> } /> + } /> } /> } /> } /> @@ -145,6 +150,8 @@ function Shelled({ user }: { user: CurrentUser }) { } /> } /> } /> + } /> + } /> } /> } /> } /> @@ -155,6 +162,7 @@ function Shelled({ user }: { user: CurrentUser }) { } /> } /> } /> + } /> } /> } /> {/* These were pages of their own; they are sections of other pages now, and old links, bookmarks and notifications still arrive. */} diff --git a/web/src/api/client.ts b/web/src/api/client.ts index 5723025..90a2e08 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -517,6 +517,8 @@ export interface HealthCheckSettings { flapRaises: number; /** Minutes a UniFi device may be offline before it is raised. */ deviceOfflineMinutes: number; + /** Days before an operating system's support ends that a server is flagged (0 = off). */ + osSupportWarnDays: number; } /** The monthly report: last month's availability, incidents, updates and renewals, in one message on a day of the month. */ @@ -780,7 +782,19 @@ export interface ServerLink { url: string; } +/** What a server runs and when that release stops being supported (from what its agent says). */ +export interface ServerOs { + id: string; + name: string | null; + version: string | null; + product: string; + endsOn: string | null; + state: "ended" | "soon" | "ok" | "unknown"; + daysLeft: number | null; +} + export interface ServerDetail { + os: ServerOs | null; server: ServerRecord; ipAddresses: string[]; hardware: ServerHardware; @@ -1081,7 +1095,36 @@ export interface HeartbeatInput { enabled?: boolean; } -export type AgendaKind = "secret" | "certificate" | "domain" | "tailscale" | "warranty" | "support" | "maintenance" | "restore" | "updates"; +export type AgendaKind = "secret" | "certificate" | "domain" | "tailscale" | "warranty" | "support" | "maintenance" | "restore" | "updates" | "todo"; + +/** One job on the to-do list. */ +export interface TodoItem { + id: number; + title: string; + detail: string | null; + dueDate: string | null; + assignee: { id: number | null; name: string } | null; + target: { type: "server" | "device"; id: number; name: string } | null; + createdBy: string | null; + createdAt: string; + doneAt: string | null; + doneBy: string | null; +} +export interface TodoInput { + title: string; + detail?: string | null; + dueDate?: string | null; + assigneeId?: number | null; + targetType?: "server" | "device" | null; + targetId?: number | null; +} +export interface NoteItem { + targetType: "server" | "device"; + targetId: number; + body: string; + updatedBy: string | null; + updatedAt: string; +} export interface AgendaItem { id: string; kind: AgendaKind; @@ -1172,6 +1215,18 @@ export interface DependencyNode { id: number; name: string; } +/** A dependency the app offers to write, from what it already knows. */ +export interface DependencySuggestion { + key: string; + from: { type: "integration"; id: number; name: string }; + to: { type: "server"; id: number; name: string }; + reason: string; +} +export interface DependencySuggestions { + suggestions: DependencySuggestion[]; + dismissed: DependencySuggestion[]; +} + export interface DependenciesResponse { /** "A needs B", written here. */ dependencies: { id: number; from: { type: DependencyNodeType; id: number; name: string }; to: { type: DependencyNodeType; id: number; name: string }; createdAt: string }[]; @@ -1185,6 +1240,8 @@ export interface MyWork { alerts: { alertId: string; message: string; severity: string; source: string; link: string | null; note: string; role: "handed" | "acked"; ackedBy: string; ackedAt: string; until: string | null; endsSoon: boolean }[]; windows: { id: number; targetType: string; targetId: number; targetName: string; targetKind: string; reason: string | null; startedAt: string; endsAt: string; endsSoon: boolean }[]; updateRuns: { id: number; serverId: number; serverName: string; templateName: string; status: string; message: string | null; startedAt: string; finishedAt: string | null; running: boolean; updatesBefore: number | null; updatesAfter: number | null; rebootRequired: boolean }[]; + /** Open jobs from the to-do list handed to this person. */ + todos: { id: number; title: string; detail: string | null; dueDate: string | null; overdue: boolean; dueSoon: boolean; target: { type: string; id: number; name: string } | null }[]; needsAttention: number; } @@ -1257,6 +1314,68 @@ export interface NetworkOverview { ssids: NetworkSegment[]; } +export interface NpmHost { + id: number; + domains: string[]; + forwardScheme: string; + forwardHost: string; + forwardPort: number | null; + enabled: boolean; + sslForced: boolean; + certificate: { id: number; name: string; expiresAt: string | null } | null; + online: boolean; + error: string | null; + /** The server the address it forwards to belongs to, when the app knows it. */ + server: { id: number; name: string } | null; +} + +export interface NpmCertificate { + id: number; + name: string; + provider: string; + domains: string[]; + expiresAt: string | null; +} + +export interface IntegrationProblem { + key: string; + kind: string; + severity: "critical" | "warning"; + message: string; +} + +export interface NpmOverview { + integrations: { id: number; name: string; readAt: string; error: string | null; version: string | null; hosts: NpmHost[]; certificates: NpmCertificate[]; problems: IntegrationProblem[] }[]; +} + +export interface HaSyncStatus { + at: string; + ok: boolean; + error: string | null; + entities: number; +} + +export interface HaWatchedEntity { + entityId: string; + name: string | null; + above: number | null; + below: number | null; + entity: { friendlyName: string | null; state: string; value: number | null; unit: string | null; deviceClass: string | null; lastChanged: string | null; unavailableSince: string | null; updatedAt: string } | null; +} + +export interface HaOverview { + integrations: { id: number; name: string; enabled: boolean; status: HaSyncStatus | null; fresh: boolean; watched: HaWatchedEntity[]; problems: IntegrationProblem[] }[]; +} + +export interface HaEntityChoice { + entityId: string; + name: string; + state: string; + unit: string | null; + deviceClass: string | null; + watched: boolean; +} + /** A piece of hardware in the inventory. */ export interface Asset { id: number; @@ -1671,7 +1790,7 @@ export interface ManualTaskInput { enabled?: boolean; } -export type IntegrationType = "proxmox" | "synology" | "semaphore" | "tailscale" | "gitea" | "dockhand" | "uptimekuma" | "phpipam" | "pbs" | "osticket" | "unifi"; +export type IntegrationType = "proxmox" | "synology" | "semaphore" | "tailscale" | "gitea" | "dockhand" | "uptimekuma" | "phpipam" | "pbs" | "osticket" | "unifi" | "npm" | "homeassistant"; export interface IntegrationField { key: string; @@ -2268,18 +2387,56 @@ export const api = { myWork: { get: () => request("/api/my-work"), }, + todos: { + list: () => request<{ todos: TodoItem[]; people: { id: number; name: string; role: string }[] }>("/api/todos"), + create: (data: TodoInput) => request<{ todo: TodoItem }>("/api/todos", { method: "POST", body: JSON.stringify(data) }), + update: (id: number, data: Partial & { done?: boolean }) => request<{ todo: TodoItem }>(`/api/todos/${id}`, { method: "PATCH", body: JSON.stringify(data) }), + remove: (id: number) => request(`/api/todos/${id}`, { method: "DELETE" }), + }, + notes: { + get: (targetType: "server" | "device", targetId: number) => request<{ note: NoteItem | null }>(`/api/notes?targetType=${targetType}&targetId=${targetId}`), + save: (targetType: "server" | "device", targetId: number, body: string) => request<{ note: NoteItem | null }>("/api/notes", { method: "PUT", body: JSON.stringify({ targetType, targetId, body }) }), + }, network: { overview: () => request("/api/network"), sync: (integrationId?: number) => request<{ statuses: Record }>("/api/network/sync", { method: "POST", body: JSON.stringify(integrationId ? { integrationId } : {}) }), }, + npm: { + overview: (refresh = false) => request(`/api/npm${refresh ? "?refresh=1" : ""}`), + }, + homeAssistant: { + overview: () => request("/api/home-assistant"), + entities: (id: number, q: string) => request<{ total: number; entities: HaEntityChoice[] }>(`/api/home-assistant/${id}/entities?q=${encodeURIComponent(q)}`), + watch: (id: number, body: { entityId: string; name?: string | null; above?: number | null; below?: number | null }) => + request<{ ok: boolean; status: HaSyncStatus }>(`/api/home-assistant/${id}/watched`, { method: "PUT", body: JSON.stringify(body) }), + unwatch: (id: number, entityId: string) => request(`/api/home-assistant/${id}/watched/${encodeURIComponent(entityId)}`, { method: "DELETE" }), + history: (id: number, entityId: string, days: number) => + request<{ days: number; points: { t: string; v: number }[] }>(`/api/home-assistant/${id}/history?entity=${encodeURIComponent(entityId)}&days=${days}`), + sync: () => request<{ statuses: Record }>("/api/home-assistant/sync", { method: "POST", body: "{}" }), + }, dependencies: { list: () => request("/api/dependencies"), impact: (type: DependencyNodeType, id: number) => request(`/api/dependencies/impact?type=${type}&id=${id}`), graph: () => request("/api/dependencies/graph"), + suggestions: () => request("/api/dependencies/suggestions"), + addSuggestions: (keys: string[]) => request("/api/dependencies/suggestions/add", { method: "POST", body: JSON.stringify({ keys }) }), + dismissSuggestions: (keys: string[]) => request("/api/dependencies/suggestions/dismiss", { method: "POST", body: JSON.stringify({ keys }) }), + restoreSuggestions: () => request("/api/dependencies/suggestions/restore", { method: "POST" }), create: (data: { fromType: DependencyNodeType; fromId: number; toType: DependencyNodeType; toId: number }) => request<{ id: number }>("/api/dependencies", { method: "POST", body: JSON.stringify(data) }), remove: (id: number) => request(`/api/dependencies/${id}`, { method: "DELETE" }), }, inventory: { + racks: () => + request<{ + racks: { + name: string; + units: number; + slots: { assetId: number; name: string; kind: string; model: string | null; from: number; to: number; powerWatts: number | null; serverId: number | null; clash: boolean }[]; + unplaced: { assetId: number; name: string; kind: string }[]; + usedUnits: number; + watts: number; + }[]; + }>("/api/inventory/racks"), list: () => request<{ assets: Asset[]; config: InventoryConfig; servers: { id: number; name: string }[] }>("/api/inventory"), create: (data: AssetInput) => request<{ asset: Asset }>("/api/inventory", { method: "POST", body: JSON.stringify(data) }), update: (id: number, data: AssetInput) => request<{ asset: Asset }>(`/api/inventory/${id}`, { method: "PUT", body: JSON.stringify(data) }), diff --git a/web/src/components/CommandPalette.tsx b/web/src/components/CommandPalette.tsx index ab59d4a..b1b6af1 100644 --- a/web/src/components/CommandPalette.tsx +++ b/web/src/components/CommandPalette.tsx @@ -44,6 +44,8 @@ const INTEGRATION_TYPE_LABELS: Record = { pbs: "Proxmox Backup Server", osticket: "osTicket", unifi: "UniFi", + npm: "Nginx Proxy Manager", + homeassistant: "Home Assistant", }; const DNS_PROVIDER_LABELS: Record = { diff --git a/web/src/components/IntegrationEditForm.tsx b/web/src/components/IntegrationEditForm.tsx index 864d0e1..500e49c 100644 --- a/web/src/components/IntegrationEditForm.tsx +++ b/web/src/components/IntegrationEditForm.tsx @@ -15,6 +15,8 @@ const TYPE_LABELS: Record = { pbs: "Proxmox Backup Server", osticket: "osTicket", unifi: "UniFi", + npm: "Nginx Proxy Manager", + homeassistant: "Home Assistant", }; export default function IntegrationEditForm({ diff --git a/web/src/components/IntegrationForm.tsx b/web/src/components/IntegrationForm.tsx index 979f687..ed8b499 100644 --- a/web/src/components/IntegrationForm.tsx +++ b/web/src/components/IntegrationForm.tsx @@ -14,6 +14,8 @@ const TYPE_LABELS: Record = { pbs: "Proxmox Backup Server", osticket: "osTicket", unifi: "UniFi", + npm: "Nginx Proxy Manager", + homeassistant: "Home Assistant", }; export default function IntegrationForm({ onCreated, onCancel }: { onCreated: () => void; onCancel: () => void }) { diff --git a/web/src/components/NetworkDiagram.tsx b/web/src/components/NetworkDiagram.tsx new file mode 100644 index 0000000..aae08df --- /dev/null +++ b/web/src/components/NetworkDiagram.tsx @@ -0,0 +1,160 @@ +import { useMemo } from "react"; +import type { NetworkDevice } from "../api/client"; + +const KIND_WORDS: Record = { gateway: "Gateway", switch: "Switch", access_point: "Access point", other: "Device" }; +const STATE_COLOR: Record = { online: "#2fb344", offline: "#f03e3e", updating: "#f59f00", pending: "#4299e1", other: "#8896ab" }; + +const NODE_W = 168; +const SLOT_W = 188; +const HEAD_H = 46; +const LINE_H = 14; +const MAX_SERVERS = 4; +const ROW_GAP = 46; + +interface Node { + id: string; + device: NetworkDevice | null; // null: the internet, or "unknown uplink" + label: string; + children: Node[]; + width: number; // in slots + x: number; // centre, in px + y: number; // top, in px + h: number; +} + +const heightOf = (d: NetworkDevice | null) => (d ? HEAD_H + Math.min(d.servers.length, MAX_SERVERS + (d.servers.length > MAX_SERVERS ? 1 : 0)) * LINE_H + (d.servers.length > 0 ? 6 : 0) : 30); + +/** + * How the network hangs together, from what the UniFi controller says each device is connected through: the internet, the gateway, the switches below it, the access + * points below those, and the servers plugged into each. A tree drawn top-down; a device whose state is not online is red, and a device whose uplink is not known sits + * apart under "Unknown uplink". Print it for the cabinet door. + */ +export default function NetworkDiagram({ devices }: { devices: NetworkDevice[] }) { + const layout = useMemo(() => { + const childrenOf = new Map(); + const roots: NetworkDevice[] = []; + const orphans: NetworkDevice[] = []; + for (const d of devices) { + if (d.uplink) { + const parent = devices.find((p) => p.id === d.uplink!.id); + if (parent) { + childrenOf.set(parent.id, [...(childrenOf.get(parent.id) ?? []), d]); + continue; + } + } + (d.kind === "gateway" ? roots : orphans).push(d); + } + const build = (d: NetworkDevice, seen: Set): Node => { + const kids = (childrenOf.get(d.id) ?? []).filter((k) => !seen.has(k.id)).sort((a, b) => a.name.localeCompare(b.name)); + const next = new Set(seen).add(d.id); + const children = kids.map((k) => build(k, next)); + return { id: `d${d.id}`, device: d, label: d.name, children, width: Math.max(1, children.reduce((n, c) => n + c.width, 0)), x: 0, y: 0, h: heightOf(d) }; + }; + const virtual = (id: string, label: string, kids: NetworkDevice[]): Node => { + const children = kids.sort((a, b) => a.name.localeCompare(b.name)).map((k) => build(k, new Set())); + return { id, device: null, label, children, width: Math.max(1, children.reduce((n, c) => n + c.width, 0)), x: 0, y: 0, h: heightOf(null) }; + }; + const top: Node[] = []; + if (roots.length > 0) top.push(virtual("internet", "Internet", roots)); + if (orphans.length > 0) top.push(virtual("unknown", "Unknown uplink", orphans)); + // Position: each node is centred over its children; a leaf takes one slot; the top-level groups sit side by side. + let cursor = 0; + const levelBottom: number[] = []; + const place = (n: Node, depth: number, left: number) => { + let at = left; + for (const c of n.children) { + place(c, depth + 1, at); + at += c.width * SLOT_W; + } + n.x = n.children.length > 0 ? (n.children[0].x + n.children[n.children.length - 1].x) / 2 : left + (n.width * SLOT_W) / 2; + levelBottom[depth] = Math.max(levelBottom[depth] ?? 0, n.h); + (n as Node & { depth: number }).depth = depth; + }; + for (const t of top) { + place(t, 0, cursor); + cursor += t.width * SLOT_W + SLOT_W / 2; + } + // Rows: each level is as tall as its tallest node, then a gap. + const rowTop: number[] = []; + levelBottom.reduce((y, h, i) => { + rowTop[i] = y; + return y + h + ROW_GAP; + }, 8); + const all: Node[] = []; + const walk = (n: Node) => { + n.y = rowTop[(n as Node & { depth: number }).depth]; + all.push(n); + n.children.forEach(walk); + }; + top.forEach(walk); + const width = Math.max(cursor - SLOT_W / 2, SLOT_W); + const height = (rowTop[rowTop.length - 1] ?? 0) + (levelBottom[levelBottom.length - 1] ?? 0) + 8; + return { all, width, height }; + }, [devices]); + + if (devices.length === 0) return
No devices to draw yet.
; + + return ( +
+
+ + {layout.all.flatMap((n) => + n.children.map((c) => { + const x1 = n.x; + const y1 = n.y + n.h; + const x2 = c.x; + const y2 = c.y; + const mid = (y1 + y2) / 2; + return ; + }), + )} + {layout.all.map((n) => { + const d = n.device; + if (!d) { + return ( + + + + {n.label} + + + ); + } + const shown = d.servers.slice(0, MAX_SERVERS); + return ( + + {`${d.name} — ${KIND_WORDS[d.kind]}${d.model ? `, ${d.model}` : ""}${d.ip ? `, ${d.ip}` : ""} — ${d.state}${d.servers.length > 0 ? `\nPlugged in: ${d.servers.map((s) => s.serverName).join(", ")}` : ""}`} + + + + {d.name.length > 20 ? `${d.name.slice(0, 19)}…` : d.name} + + + {[KIND_WORDS[d.kind], d.ip].filter(Boolean).join(" · ")} + + {shown.map((s, i) => ( + + ▪ {s.serverName} + {s.port !== null ? ` (${s.port})` : s.wired ? "" : " (Wi-Fi)"} + + ))} + {d.servers.length > MAX_SERVERS && ( + + + {d.servers.length - MAX_SERVERS} more + + )} + + ); + })} + +
+
+ ● online + ● offline + ● updating + ▪ a server plugged in (the port, or Wi-Fi) + As the UniFi controller reports what each device is connected through. +
+
+ ); +} diff --git a/web/src/components/NotesCard.tsx b/web/src/components/NotesCard.tsx new file mode 100644 index 0000000..3f7296a --- /dev/null +++ b/web/src/components/NotesCard.tsx @@ -0,0 +1,99 @@ +import { useEffect, useState } from "react"; +import { api, type NoteItem } from "../api/client"; +import { BlockSkeleton } from "./Skeleton"; +import RunbookText from "./RunbookText"; +import TimeAgo from "./TimeAgo"; +import { readableError } from "../utils/errors"; +import { toast } from "../utils/toast"; + +/** + * Free-form notes about a server or a network device — what it is, where it sits, what was done to it last time. One text, written with the same small formatting + * as a runbook (lists, **bold**, `code`, links). Everyone signed in reads it; operators write it. Emptying it takes the note away. + */ +export default function NotesCard({ targetType, targetId, canEdit, bare = false }: { targetType: "server" | "device"; targetId: number; canEdit: boolean; /** Without the card round it (inside a drawer). */ bare?: boolean }) { + const [note, setNote] = useState(undefined); + const [draft, setDraft] = useState(null); + const [busy, setBusy] = useState(false); + const [failed, setFailed] = useState(false); + + useEffect(() => { + let alive = true; + setNote(undefined); + setDraft(null); + api.notes + .get(targetType, targetId) + .then((res) => alive && setNote(res.note)) + .catch(() => alive && setFailed(true)); + return () => { + alive = false; + }; + }, [targetType, targetId]); + + async function save() { + if (draft === null) return; + setBusy(true); + try { + const res = await api.notes.save(targetType, targetId, draft); + setNote(res.note); + setDraft(null); + toast.success(res.note ? "Saved." : "Note removed."); + } catch (err) { + toast.error(readableError(err)); + } finally { + setBusy(false); + } + } + + const body = failed ? ( +
Couldn’t load the note.
+ ) : note === undefined ? ( + + ) : draft !== null ? ( + <> +