diff --git a/AGENT_UPDATE.md b/AGENT_UPDATE.md index aec117c..c01b80a 100644 --- a/AGENT_UPDATE.md +++ b/AGENT_UPDATE.md @@ -25,6 +25,8 @@ number when it is worth installing the agent again for. | 3 (Linux) | Asks the package manager outside the agent's systemd sandbox, so `dnf` and `zypper` hosts can answer (below). Install again to get it: the unit file changes too. | | 3 (Windows) | Can replace itself with the newer script when automatic updates are switched on (below). | | 4 (Linux) | Also reports failed services, disk health (SMART) and ZFS pool state; reads `pacman`; and can replace itself when automatic updates are switched on. | +| 4 (Windows) | Also reports failed services, disk health and Storage Spaces pools (below), and what the machine is (maker, model, serial number). | +| 5 (Linux) | Also says what the machine is — maker, model and serial number, read from the firmware — so the inventory can fill itself in (below). | Reports are always read leniently — a field an older agent doesn't send is simply left alone, and a field an agent sends that the server doesn't know yet is ignored — so there is never a rush, and a mixed fleet of @@ -198,7 +200,26 @@ What it can't do: | **ZFS pools** | `zpool list` | Needs the `zpool` command. A pool in any state but ONLINE is a critical alert. | A report that leaves one of these out leaves what was last said alone (an agent that skips a part never turns an old problem into -"all well"); an empty list is an answer ("none failed") and clears the old one. Windows doesn't report these. +"all well"); an empty list is an answer ("none failed") and clears the old one. + +## What the Windows agent reports about the machine (version 4) + +The same three parts, from what Windows itself knows (the agent runs as SYSTEM, so nothing needs installing): + +| What | Where it comes from | Notes | +|---|---|---| +| **Failed services** | `Win32_Service` | A service that starts by itself, isn't running, and stopped with an error. Services that finished normally (exit code 0), that start on a trigger (1077) or that are starting up are not failures. Some services always do this (updaters, for one): list them under `ignoreServices` in `agent.json` (or `IGNORE_SERVICES` in the environment), as names or patterns like `gupdate*`. | +| **Disk health** | `Get-PhysicalDisk` and its reliability counters | Windows' own verdict: *Healthy* passes, *Warning* and *Unhealthy* fail, anything else says nothing. Temperature and wear come from the counters where the drive gives sane ones. Virtual disks are left out. | +| **Storage pools** | `Get-StoragePool` (Storage Spaces) | *Healthy*, *Warning* and *Unhealthy* are reported as ONLINE, DEGRADED and FAULTED, with how full the pool is, and show beside ZFS pools. A machine with no pools reports an empty list. | + +## What the machine is (Linux version 5, Windows version 4) + +The agents say who made the machine, its model and its serial number (Linux reads `/sys/class/dmi/id`, where the serial is only +readable by root; Windows asks the computer system, the BIOS, and the motherboard when those say nothing — a home-built PC). What +a maker writes when it has nothing to say ("To Be Filled By O.E.M.", "Default string", all zeros) is left out, and many virtual +machines and single-board computers say nothing at all. The figures are kept on the server and used by the **Inventory**: a +linked entry gets its blank maker, model and serial number filled in, and *Refresh from agent* on the Inventory page replaces +what is written there with what the agent says, when you choose to. To see exactly what a host finds, as root: `sudo /usr/local/bin/homelab-manager-agent.sh --check-updates` — it prints the update figures, the failed services, the SMART readings and the ZFS pools, says whether it would update itself, and changes nothing. diff --git a/DATABASE.md b/DATABASE.md index 19ef8a9..f2c2738 100644 --- a/DATABASE.md +++ b/DATABASE.md @@ -51,6 +51,7 @@ what the app actually creates. ```mermaid erDiagram users ||--o{ audit_log : "actor (set null)" + users ||--o{ push_subscriptions : "cascade" integration_credentials ||--o{ integrations : "credential (set null)" integration_credentials ||--o{ dns_providers : "credential (set null)" dns_providers ||--o{ dns_zones_cache : "cascade" @@ -64,9 +65,9 @@ erDiagram integrations ||--o{ alert_tickets : "osTicket used (set null)" ``` -Thirteen tables stand alone, with no foreign keys: `settings`, `secrets`, +Fourteen tables stand alone, with no foreign keys: `settings`, `secrets`, `ipam_entries`, `domains`, `diag_log`, `notification_queue`, -`consistency_ignores`, `tag_definitions`, `share_links`, `maintenance_schedules`, `metrics_tokens`, `event_webhooks`, `alert_incidents`. `maintenance_windows` and `maintenance_aliases` also have no +`consistency_ignores`, `tag_definitions`, `share_links`, `maintenance_schedules`, `metrics_tokens`, `event_webhooks`, `alert_incidents`, `dependencies`. `maintenance_windows` and `maintenance_aliases` also have no foreign key — see [soft references](#soft-references-not-foreign-keys). ## Tables @@ -103,7 +104,7 @@ Who changed what. Written by the app on every change (see | `id` | integer PK | | | `actor_user_id` | integer → `users.id`, **set null** on delete | Null for automatic actions, and for entries whose user was deleted. | | `actor_label` | text | The user's name/email as it was at the time (or `system`), so an entry still reads correctly after the account is gone. | -| `category` | text NOT NULL | Free text. In use: `server` (including the health check's own `went_offline`, `back_online`, `disk_full` and `disk_ok`, and `agent_updated` when a server's agent reports a higher version than before, written as `system` and shown on a server's Activity card), `integration` (including the health check's `went_failing` / `recovered` for a kind of service, with `target_type` `integration_type` and the service type as `target_id`, which the dashboard summary and the uptime ribbons read), `dns`, `settings` (including `agent_auto_update`), `ipam`, `secret`, `domain`, `tag`, `task`, `session`, `network`, `maintenance`, `consistency`, `user`, `privacy`, `diag_log`, `alert_ticket`, `share_link` (a link made or removed, and `update_status_page` when what a status page shows is changed — never the secret), `runbook`, `alert` (`ack`, `unack` — with the alert's id; on the thing it is about, so they show on a server's Activity card), `incident` (`note`, `note_removed`), `db_backup` (`create`, `upload`, `download`, `delete`, `restore_staged`, `restore_cancelled`, `settings`), `update_run` (`start`, `finished`, `failed`, `cancelled` — shown on the server's Activity card), `inventory`, `metrics_token` and `webhook` (made, changed or removed — never a secret or an address). `user` also records `role_from_groups` when a sign-in changed someone's role. | +| `category` | text NOT NULL | Free text. In use: `server` (including the health check's own `went_offline`, `back_online`, `disk_full` and `disk_ok`, and `agent_updated` when a server's agent reports a higher version than before, written as `system` and shown on a server's Activity card), `integration` (including the health check's `went_failing` / `recovered` for a kind of service, with `target_type` `integration_type` and the service type as `target_id`, which the dashboard summary and the uptime ribbons read), `dns`, `settings` (including `agent_auto_update`), `ipam`, `secret`, `domain`, `tag`, `task`, `session`, `network`, `maintenance`, `consistency`, `user`, `privacy`, `diag_log`, `alert_ticket`, `dependency` (`create`, `delete` — what needs what), `push` (`subscribe`, `unsubscribe` — a browser added or removed, never its address or keys), `share_link` (a link made or removed, and `update_status_page` when what a status page shows is changed — never the secret), `runbook`, `alert` (`ack`, `unack` — with the alert's id; on the thing it is about, so they show on a server's Activity card), `incident` (`note`, `note_removed`), `db_backup` (`create`, `upload`, `download`, `delete`, `restore_staged`, `restore_cancelled`, `settings`), `update_run` (`start`, `finished`, `failed`, `cancelled` — shown on the server's Activity card), `inventory`, `metrics_token` and `webhook` (made, changed or removed — never a secret or an address). `user` also records `role_from_groups` when a sign-in changed someone's role. | | `action` | text NOT NULL | `create`, `update`, `delete`, `start`, `stop`, … — free text. | | `target_type`, `target_id` | text | What it happened to. `target_id` is text so it can hold any kind of ID; there's no foreign key. | | `detail` | text | JSON, free-form context (what changed, names, counts). Secrets are never put here. | @@ -223,6 +224,7 @@ what it last reported. | `updates_pending_since` | text | ISO; when updates were first seen waiting (and none were before). Null when none are waiting. | | `thresholds` | text | This server's own alert limits as JSON: `{"serverOfflineMinutes":…,"diskUsagePercent":…,"diskForecastDays":…,"backupStaleHours":…,"mounts":{"/data":{"percent":95,"ignore":true}}}`. Anything left out follows Settings; null when it follows Settings entirely. Ranges are checked on the way in (offline 15–10080 min, disk 50–99 %, forecast 0–90 days, backup 0–2160 h; 0 means off). | | `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_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` @@ -586,6 +588,35 @@ The hardware inventory. | `server_id` | integer | The server this is, if it is one. A plain reference, **not a foreign key**: one whose server is gone shows as unlinked. | | `created_at`, `updated_at` | text NOT NULL | ISO. | +#### `dependencies` + +"A needs B" between servers and integrations: when B is down, A's alert is folded under B's. The "runs on" links of servers are part of the same graph but live on `servers`. + +| Column | Type | Notes | +|---|---|---| +| `id` | integer PK | | +| `from_type`, `from_id` | text, integer NOT NULL | The thing that needs: `server` or `integration`, and its id. | +| `to_type`, `to_id` | text, integer NOT NULL | The thing it needs. Unique together with the pair above. | +| `created_at` | text NOT NULL | ISO. | + +No foreign keys (like `maintenance_windows`): a row whose server or integration is gone is ignored, not an error. + +#### `push_subscriptions` + +A browser or phone that asked for push notifications, one row per device. + +| Column | Type | Notes | +|---|---|---| +| `id` | integer PK | | +| `user_id` | integer NOT NULL | → `users.id`, deleted with the user. | +| `endpoint` | text NOT NULL, unique | The address of the browser's push service. It is a secret: with the keys below it can write to that device. | +| `p256dh`, `auth` | text NOT NULL | The browser's public key and authentication secret, which every message is encrypted with. | +| `label` | text | What the person calls it, or the browser it is. | +| `created_at` | text NOT NULL | ISO. | +| `last_success_at` | text | When the push service last accepted a message for it. | + +A subscription is removed when the push service says it is gone (HTTP 404 or 410), when its owner or an administrator removes it, and all of them are removed if the server's own key pair has to be made again. + #### `metrics_tokens` Read-only access to `/metrics` for Prometheus. Only a hash of each secret is stored. @@ -683,6 +714,7 @@ that were never changed aren't stored; the app fills in defaults when reading. | Key | Holds | |---|---| | `gotify`, `ntfy`, `smtp`, `webhook` | The four notification channels: enabled, address, and credentials (token / password / secret). The credential fields are stored encrypted (prefix `enc:v1:`) — see [Retention and backups](#retention-and-backups). | +| `webPush` | Push to phones and browsers: `enabled` (false) and `contact` (an email or https address the push services may reach whoever runs this on; blank is fine). Who is subscribed is in `push_subscriptions`; the server's key pair is below. | | `notifications` | Which events notify (`dnsAdd`, `healthAlerts`, …), the daily-reminder time (`secretCheckTime`, default `08:00`) and `timezone` (default `UTC`), and the integration-failure threshold (default 3). | | `quietHours` | `enabled`, `start`, `end`. | | `signIn` | Roles from groups: `roleFromGroups` (false), `groupsClaim` (`groups`), `adminGroups`, `operatorGroups`, `otherwise` (`viewer` or `keep`). | @@ -707,6 +739,7 @@ settings, and aren't part of the app's settings object: | `_internal:logRetentionLastRunAt` | When the log purge last ran. | | `_internal:integration_history_since` | When the app first began writing integrations' failing / working-again moments; the uptime ribbons claim nothing earlier for integrations. | | `_internal:alertTicketsBaselineDone`, `_internal:alertTicketsLastRun` | Whether the alert-ticket starting line has been recorded since the feature was switched on, and JSON for the last check's result. | +| `_internal:webPushVapid` | JSON `{publicKey, privateKey}`: the server's own key pair for web push, made the first time it is needed. The private half is encrypted like the other credentials. Replacing it (deleting the row) makes every browser subscribe again. | | `_internal:healthActiveConditions`, `_internal:automationActiveConditions` | JSON: the problems currently active, so each is announced once and again when it clears, and survives a restart. | ## What happens on delete @@ -728,6 +761,7 @@ a stale value is possible and the app treats it as "nothing there": - `maintenance_windows.target_id` (→ a server, integration or DNS provider, by `target_type`) - `maintenance_aliases.target_id` (the same, by `target_type`) +- `dependencies.from_id` and `to_id` (→ a server or integration, by their `_type`) - `audit_log.target_id` - `dns_records_cache.zone_id` (→ `dns_zones_cache.zone_id`, same provider) - `servers.tags` (→ `tag_definitions.name`) diff --git a/NOTIFICATIONS.md b/NOTIFICATIONS.md index 434577e..f5460ee 100644 --- a/NOTIFICATIONS.md +++ b/NOTIFICATIONS.md @@ -2,14 +2,14 @@ Every notification in Homelab Manager is sent through the same pipe (`server/src/services/notify.ts`) to whichever channels are enabled under -**Settings → Notifications**: Gotify, ntfy, SMTP (email), and a generic -JSON webhook. All four fire for every notification below — there's no +**Settings → Notifications**: Gotify, ntfy, SMTP (email), a generic +JSON webhook, and push to phones and browsers. All five fire for every notification below — there's no per-event channel routing, only a per-event on/off toggle and, for the daily ones, one shared time/timezone. The settings page has three tabs, with one Save button for all of them (it shows "Unsaved changes" until you save, and the browser asks before the page -is closed with changes unsaved): **Channels** (the four channels, each a row +is closed with changes unsaved): **Channels** (the five channels, each a row you open to fill in and send a test), **What to send** (the event toggles grouped by topic, each group's thresholds beside its switches) and **When** (the time zone, the daily reminder time, quiet hours and the weekly digest). @@ -34,6 +34,25 @@ it: Where a trigger has a configurable threshold, that's noted in its row below; several are fixed and can't be changed from the UI. +## Push to a phone or browser + +The fifth channel, **Phone and browser**, sends the same messages as the others to browsers that have asked for them — a phone with +this page added to its home screen, a desktop browser — with no app, account or extra service. An administrator switches it on under +Settings → Notifications → Channels (the optional *contact* is given to the browsers' push services, as the standard asks), and then +each person opens the same row and presses **Notify this browser**; the browser asks permission and the row lists their browsers, +with a button to send a test and one to remove each. + +- **It needs https.** Browsers only allow push for pages served over https (or from `localhost`), so a copy opened over plain http + on a LAN address shows why it can't be used instead of the button. +- **How it travels.** The message is encrypted for each browser (RFC 8291) and signed with a key pair this server makes the first time + it is needed (RFC 8292, "VAPID"), then handed to the browser's own push service — Google's, Mozilla's or Apple's — which delivers + it. The push service sees that a message is being sent and its size, not what it says. The address of each browser's push + service is checked before use: https only, and never an address on a private network. +- **Quiet hours** hold push messages like every other channel, and each event's on/off toggle applies. A tap on a notification opens + the Alerts page. +- **A browser that has gone** (the site's permission was removed, the app uninstalled) is dropped automatically when its push + service says so. If the server's key pair is ever lost (the credentials key changed), everyone has to press the button again. + ## Daily reminders These six checks share one schedule: **Settings → Notifications → Daily @@ -90,7 +109,7 @@ schedule. | DNS record added | *DNS record added* | A DNS record is created against any DNS provider through this app (manually, or via any automated action that writes one). | | DNS record updated | *DNS record updated* | An existing DNS record is edited. | | DNS record deleted | *DNS record deleted* | A DNS record is deleted. | -| Integration/DNS provider down | *Integration/DNS provider failing repeatedly* | Any integration or DNS provider adapter's calls fail a configurable number of times **in a row**. Tracked per adapter *type* (e.g. "proxmox"), not per individual integration row — with two Proxmox integrations, a streak of failures on either one counts toward the same total. Only fires once per failure streak (not on every failure past the threshold), and is skipped entirely if that type is currently in a maintenance window. | Settings → Notifications → **Alert after** (default 3 consecutive failures) | +| Integration/DNS provider down | *Integration/DNS provider failing repeatedly* | Any integration or DNS provider adapter's calls fail a configurable number of times **in a row**. Tracked per adapter *type* (e.g. "proxmox"), not per individual integration row — with two Proxmox integrations, a streak of failures on either one counts toward the same total. Only fires once per failure streak (not on every failure past the threshold), and is skipped entirely if that type is currently in a maintenance window, **or if it is explained by something it needs that is down** (see *Dependencies* in the README): a service that starts failing while the server it runs on is offline is not announced, and if it is still failing once that server is back, the next failed call alerts. | Settings → Notifications → **Alert after** (default 3 consecutive failures) | | Integration/DNS provider recovered | *(same toggle)* | The next call for that source succeeds, after a "down" alert was already sent for the current streak. | ## Digest diff --git a/README.md b/README.md index 695ebef..a1ff053 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ All modules from the original plan are built: too, which writes the table as it is on screen — times as exact timestamps, action buttons left out. - **Settings** (admin-only) — notification channels (Gotify, ntfy, SMTP, - generic webhook) with per-channel test buttons, per-event toggles (DNS + generic webhook, and push to phones and browsers) with per-channel test buttons, per-event toggles (DNS record added/updated/deleted, daily secret-expiry reminder and daily Tailscale key-expiry reminder — both sharing one configurable time/timezone), badge-color customization for both DNS @@ -420,6 +420,15 @@ refused. "Nothing — it runs on its own" stops the guess for a server that isn' guest (a physical machine that happens to share a Proxmox node's name), so its alerts always stand alone. +**Dependencies beyond servers** (Infrastructure → Dependencies). Say that Gitea needs the server it is installed on, or that a server +needs Proxmox to answer. When what is needed is down, the alert of what needs it is folded under the first one exactly like a +guest under its host — shown, labelled "caused by …", left out of notifications and tickets — and the root cause says what else it +takes down. It follows chains and the "runs on" links of servers; something needing two things is explained by whichever is down; +a loop explains nothing and one that would be made is refused. An integration is judged per kind of service (as its health is), +so it is folded only when every enabled instance of that kind is explained. A service that starts failing while the server it needs +is offline isn't announced; if it is still failing once the server is back, the next failed call alerts. (DNS providers raise no +alerts of their own, so they aren't part of this.) + **Recurring maintenance** (Maintenance → Recurring) repeats a window on the days and clock time you choose — "Sundays 02:00–04:00 on these servers" — in the time zone of the browser it was made in, so 02:00 stays 02:00 across summer and winter @@ -546,6 +555,13 @@ draw, and — with a price per kWh set at the foot of the page — a rough yearl cost. Everyone signed in can look; operators keep it up to date; the weekly digest mentions a warranty ending within 60 days. +Entries that are a server also pick up what its agent says the machine is: when you link an entry to a server (or the +agent reports later), a blank maker, model or serial number is filled in from the firmware — never over what a person wrote. +When the agent says something different, the row offers **Refresh from agent**, which asks before replacing. **Print labels** +(on the Inventory page) makes a sheet of stickers — a QR code, the name, what it is, its serial number and where it sits, in +three sizes — and scanning a code opens that entry (`/inventory?asset=…`) for whoever is signed in. The codes are drawn in the +browser; nothing about them leaves the page. + **Roles from groups** (Settings → Sign-in, off until switched on): name the groups that mean administrator and operator, and at each sign-in a person's role follows the groups the identity provider (Authentik) reports; everyone else becomes a viewer, or diff --git a/ROLES.md b/ROLES.md index bf7256c..64b10bb 100644 --- a/ROLES.md +++ b/ROLES.md @@ -26,6 +26,7 @@ page's own top-level link. | Proxmox Backup | `/pbs` | ✅ | ✅ | ✅ | | Backup coverage | `/backups` | ✅ | ✅ | ✅ | | Inventory | `/inventory` | ✅ | ✅ | ✅ | +| Dependencies | `/dependencies` | ✅ | ✅ | ✅ | | Docker | `/docker` | ✅ | ✅ | ✅ | | Tailscale | `/tailscale` | ✅ | ✅ | ✅ | | **Network** | | | | | @@ -91,8 +92,11 @@ even further, to admin only: under Settings → Alert tickets, which is admin-only. - **Runbooks**: everyone reads them (on a server's page, an integration's card, next to an alert); writing, editing and removing one needs operator. -- **Inventory**: everyone can see the hardware; adding, editing and removing needs - operator; the price of power used for the running cost is admin-only. +- **Inventory**: everyone can see the hardware (and print its labels); adding, editing and removing needs + operator, and so does *Refresh from agent*; the price of power used for the running cost is admin-only. +- **Dependencies**: everyone can see what needs what; adding and removing one needs operator. +- **Push notifications**: an administrator switches the channel on (Settings → Notifications). Each person, whatever their role, adds + and removes their own browsers and can send a test to them; an administrator can remove anyone's. - **Backup coverage** is a read-only page for everyone. On **Updates**, everyone sees what is waiting and how update runs are going; starting an update run (**Update…**) or stopping one needs operator. - **Acknowledging an alert, handing it over, and taking it back** need operator (the person it is handed to must be an operator or diff --git a/agent/linux/report-tasks.sh b/agent/linux/report-tasks.sh index ebdc98f..869b8a5 100644 --- a/agent/linux/report-tasks.sh +++ b/agent/linux/report-tasks.sh @@ -15,7 +15,8 @@ set -euo pipefail # 1 = before the number was reported 2 = reports pending updates, and its own version # 3 = the package manager is asked outside the sandbox (see --prepare), so dnf and zypper can answer there too # 4 = also reports failed services, disk health (SMART) and ZFS pools, reads pacman, and can update itself when told to -AGENT_VERSION=4 +# 5 = also says what the machine is (maker, model, serial number), from the firmware, for the inventory +AGENT_VERSION=5 ENV_FILE="${ENV_FILE:-/etc/homelab-manager-agent.env}" if [[ -f "$ENV_FILE" ]]; then @@ -297,6 +298,38 @@ api_get() { printf 'header = "Authorization: Bearer %s"\n' "$(curl_quote "$API_TOKEN")" | curl -sS "${CURL_INSECURE_FLAG[@]}" -K - -m 30 -o "$2" -w "%{http_code}" "$API_URL$1" } +# One value from the firmware's table (the kernel shows it under /sys/class/dmi/id), trying the named files in turn and leaving out what a +# maker writes when it has nothing to say ("To Be Filled By O.E.M.", "Default string", all zeros ...). DMI_DIR is for the tests. +dmi_value() { + local name value + for name in "$@"; do + # (the file is checked first: a failing redirection prints its complaint before any 2>/dev/null applies) + [[ -r "${DMI_DIR:-/sys/class/dmi/id}/$name" ]] || continue + value=$(tr -d '\0' < "${DMI_DIR:-/sys/class/dmi/id}/$name" 2>/dev/null | head -c 200 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') || value="" + [[ -n "$value" ]] || continue + case "${value,,}" in + "to be filled by o.e.m."|"default string"|"system serial number"|"system product name"|"system manufacturer"|"not specified"|"not applicable"|"none"|"n/a"|"unknown"|"o.e.m."|"oem") continue ;; + esac + [[ "$value" =~ ^0+$ ]] && continue + printf '%s' "$value" + return 0 + done + return 0 +} + +# What the machine is: maker, model and serial number (a serial is only readable by root). "null" when the firmware has nothing to say, as on +# many virtual machines and single-board computers. +collect_hardware() { + HARDWARE_JSON="null" + local maker model serial + maker=$(dmi_value sys_vendor board_vendor) + model=$(dmi_value product_name board_name) + serial=$(dmi_value product_serial board_serial) + [[ -n "$maker$model$serial" ]] || return 0 + HARDWARE_JSON=$(jq -n -c --arg maker "$maker" --arg model "$model" --arg serial "$serial" \ + '{} | (if $maker != "" then . + {manufacturer: $maker} else . end) | (if $model != "" then . + {model: $model} else . end) | (if $serial != "" then . + {serial: $serial} else . end)') || HARDWARE_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" @@ -508,6 +541,8 @@ collect_system_info() { collect_smart || SMART_JSON="null" collect_zfs || ZFS_JSON="null" fi + HARDWARE_JSON="null" + collect_hardware || HARDWARE_JSON="null" 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="{}" [[ "$HEALTH_JSON" == "{}" ]] && HEALTH_JSON="null" @@ -515,6 +550,7 @@ collect_system_info() { SYSTEM_JSON=$(jq -n \ --argjson updates "$UPDATES_JSON" \ --argjson health "$HEALTH_JSON" \ + --argjson hardware "$HARDWARE_JSON" \ --argjson ip_addresses "$ip_json" \ --argjson listening_ports "$ports_json" \ --arg cpu_model "$cpu_model" \ @@ -530,7 +566,8 @@ collect_system_info() { disks: $disks, listening_ports: $listening_ports, updates: $updates, - health: $health + health: $health, + hardware: $hardware }') } diff --git a/agent/windows/report-tasks.ps1 b/agent/windows/report-tasks.ps1 index bedca7c..59c3169 100644 --- a/agent/windows/report-tasks.ps1 +++ b/agent/windows/report-tasks.ps1 @@ -34,14 +34,15 @@ $ErrorActionPreference = 'Stop' # Which version of this script this is, sent with every report so Homelab Manager can tell which agents are behind. Raise it whenever a # change here is worth installing the agent again for. 1 = before the number was reported 2 = reports pending updates, and its own version # 3 = can replace itself with the newer script when an administrator has switched that on in Homelab Manager -$script:AgentVersion = 3 +# 4 = also reports services that have failed, disk health, Storage Spaces pools and what the machine is (maker, model, serial) +$script:AgentVersion = 4 $script:DefaultConfigPath = Join-Path $env:ProgramData 'HomelabManager\agent.json' # ---- configuration ------------------------------------------------------------ function Get-AgentConfig { - $config = @{ ApiUrl = $null; ApiToken = $null; Insecure = $false; IncludeMicrosoftTasks = $false } + $config = @{ ApiUrl = $null; ApiToken = $null; Insecure = $false; IncludeMicrosoftTasks = $false; IgnoreServices = @() } $path = if ($env:HLM_CONFIG) { $env:HLM_CONFIG } else { $script:DefaultConfigPath } if (Test-Path -LiteralPath $path) { @@ -50,6 +51,7 @@ function Get-AgentConfig { if ($file.apiToken) { $config.ApiToken = [string]$file.apiToken } if ($null -ne $file.insecure) { $config.Insecure = [bool]$file.insecure } if ($null -ne $file.includeMicrosoftTasks) { $config.IncludeMicrosoftTasks = [bool]$file.includeMicrosoftTasks } + if ($file.ignoreServices) { $config.IgnoreServices = @($file.ignoreServices | ForEach-Object { [string]$_ }) } } # Environment variables win over the file, like the Linux agent. @@ -57,6 +59,7 @@ function Get-AgentConfig { if ($env:API_TOKEN) { $config.ApiToken = $env:API_TOKEN } if ($env:API_INSECURE) { $config.Insecure = $env:API_INSECURE -match '^(1|true|yes)$' } if ($env:INCLUDE_MICROSOFT_TASKS) { $config.IncludeMicrosoftTasks = $env:INCLUDE_MICROSOFT_TASKS -match '^(1|true|yes)$' } + if ($env:IGNORE_SERVICES) { $config.IgnoreServices = @($env:IGNORE_SERVICES -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ }) } if ($config.ApiUrl) { $config.ApiUrl = $config.ApiUrl.TrimEnd('/') } return $config @@ -288,7 +291,117 @@ function Get-PendingUpdates { return [ordered]@{ manager = 'windows-update'; count = [int]$cached.count; security = [int]$cached.security; reboot_required = (Test-RebootRequired) } } -function Get-SystemInfo { +# ---- failed services, disk health, storage pools and what the machine is ------------------------- + +# A service has "failed" when it is set to start by itself, isn't running, and stopped with an error: an exit code that is neither 0 (it +# finished its job, as many do) nor 1077 (it has never been started since boot, which is what a service that starts on a trigger +# looks like). Services named in IgnoreServices (names or patterns like 'gupdate*') are left out. $Services are Win32_Service objects. +function ConvertTo-FailedUnits($Services, [string[]]$Ignore = @()) { + $out = @() + foreach ($svc in @($Services)) { + if ($null -eq $svc -or [string]$svc.StartMode -ne 'Auto') { continue } + if ([string]$svc.State -eq 'Running' -or [string]$svc.State -like '*Pending*') { continue } + $code = 0 + if ($null -ne $svc.ExitCode) { $code = [int]$svc.ExitCode } + if ($code -eq 0 -or $code -eq 1077) { continue } + $name = [string]$svc.Name + $skip = $false + foreach ($pattern in @($Ignore)) { if ($pattern -and $name -like $pattern) { $skip = $true; break } } + if ($skip) { continue } + $out += [pscustomobject][ordered]@{ unit = $name; description = [string]$svc.DisplayName } + } + return @($out | Select-Object -First 100) +} + +# Windows' own verdict on each physical disk (Healthy passes; Warning and Unhealthy don't), with temperature and how much of an SSD's +# life is used where the drive says. $Disks are Get-PhysicalDisk objects; $Counters maps a disk's DeviceId to its reliability counter. +function ConvertTo-DiskHealth($Disks, $Counters = @{}) { + $out = @() + foreach ($d in @($Disks)) { + if ($null -eq $d -or [string]$d.BusType -eq 'File Backed Virtual') { continue } + $health = [string]$d.HealthStatus + $healthy = $null + if ($health -eq 'Healthy') { $healthy = $true } elseif ($health -eq 'Warning' -or $health -eq 'Unhealthy') { $healthy = $false } + $counter = $null + if ($Counters -is [hashtable] -and $Counters.ContainsKey([string]$d.DeviceId)) { $counter = $Counters[[string]$d.DeviceId] } + $temp = $null + $wear = $null + if ($null -ne $counter) { + if ($null -ne $counter.Temperature -and [int]$counter.Temperature -gt 0 -and [int]$counter.Temperature -lt 150) { $temp = [int]$counter.Temperature } + if ($null -ne $counter.Wear -and [int]$counter.Wear -ge 0 -and [int]$counter.Wear -le 255) { $wear = [int]$counter.Wear } + } + $out += [pscustomobject][ordered]@{ device = ('PhysicalDisk' + [string]$d.DeviceId); model = ([string]$d.FriendlyName).Trim(); healthy = $healthy; temperature_c = $temp; wear_percent = $wear } + } + return @($out | Select-Object -First 100) +} + +# Storage Spaces pools, in the words the server uses for ZFS pools: ONLINE, DEGRADED or FAULTED. A pool Windows can't say anything about is left out. +function ConvertTo-PoolHealth($Pools) { + $out = @() + foreach ($p in @($Pools)) { + if ($null -eq $p) { continue } + $health = switch ([string]$p.HealthStatus) { 'Healthy' { 'ONLINE' } 'Warning' { 'DEGRADED' } 'Unhealthy' { 'FAULTED' } default { $null } } + if (-not $health) { continue } + $capacity = $null + if ($p.Size -and [double]$p.Size -gt 0 -and $null -ne $p.AllocatedSize) { $capacity = [math]::Round(([double]$p.AllocatedSize / [double]$p.Size) * 100, 0) } + $out += [pscustomobject][ordered]@{ name = [string]$p.FriendlyName; health = $health; capacity_percent = $capacity } + } + return @($out | Select-Object -First 100) +} + +# The three parts are asked for separately and each only if it can be: a part that can't be read is left out of the report (the server +# then keeps what it last said), never reported as "all well". +function Get-HostHealth($Config = $null) { + $health = [ordered]@{} + $ignore = @() + if ($Config -and $Config.IgnoreServices) { $ignore = @($Config.IgnoreServices) } + try { $health['failed_units'] = @(ConvertTo-FailedUnits @(Get-CimInstance -ClassName Win32_Service -ErrorAction Stop) $ignore) } catch { Write-Warning "Reading services failed. ($($_.Exception.Message))" } + try { + $disks = @(Get-PhysicalDisk -ErrorAction Stop) + $counters = @{} + foreach ($d in $disks) { + try { $counters[[string]$d.DeviceId] = Get-StorageReliabilityCounter -PhysicalDisk $d -ErrorAction Stop } catch { } + } + $health['smart'] = @(ConvertTo-DiskHealth $disks $counters) + } catch { Write-Warning "Reading disk health failed. ($($_.Exception.Message))" } + try { + $health['zfs'] = @(ConvertTo-PoolHealth @(Get-StoragePool -ErrorAction Stop | Where-Object { -not $_.IsPrimordial })) + } catch { + # A machine with no Storage Spaces pools gets an error, not an empty list: that is an answer ("no pools"), not a failure to read. + if ($_.FullyQualifiedErrorId -like '*NotFound*') { $health['zfs'] = @() } else { Write-Warning "Reading storage pools failed. ($($_.Exception.Message))" } + } + if ($health.Count -eq 0) { return $null } + return $health +} + +# Words a maker puts in the serial number or model when it has nothing to say there. +function Test-PlaceholderText([string]$Text) { + $t = $Text.Trim() + if ($t.Length -eq 0) { return $true } + return $t -match '^(to be filled by o\.?e\.?m\.?|default string|system serial number|system product name|system manufacturer|not specified|not applicable|none|n/a|unknown|0+|o\.?e\.?m\.?)$' +} + +# What the machine is: maker, model and serial number, from the firmware. For inventory - a virtual machine says what it pretends to be. +# A home-built PC has nothing in the system's own fields, so the motherboard's are used when those say nothing. +function Get-HardwareInfo { + $cs = Get-CimInstance -ClassName Win32_ComputerSystem -ErrorAction Stop + $bios = $null + $board = $null + try { $bios = Get-CimInstance -ClassName Win32_BIOS -ErrorAction Stop } catch { } + try { $board = Get-CimInstance -ClassName Win32_BaseBoard -ErrorAction Stop } catch { } + $first = { param($values) foreach ($v in $values) { if (-not (Test-PlaceholderText ([string]$v))) { return ([string]$v).Trim() } } return $null } + $hw = [ordered]@{} + $maker = & $first @($cs.Manufacturer, $board.Manufacturer) + $model = & $first @($cs.Model, $board.Product) + $serial = & $first @($bios.SerialNumber, $board.SerialNumber) + if ($maker) { $hw['manufacturer'] = $maker } + if ($model) { $hw['model'] = $model } + if ($serial) { $hw['serial'] = $serial } + if ($hw.Count -eq 0) { return $null } + return $hw +} + +function Get-SystemInfo($Config = $null) { $ips = @(Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue | Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' -and $_.AddressState -eq 'Preferred' } | ForEach-Object { $_.IPAddress } | Select-Object -Unique) @@ -312,8 +425,16 @@ function Get-SystemInfo { $updates = $null try { $updates = Get-PendingUpdates } catch { Write-Warning "Checking for updates failed. ($($_.Exception.Message))" } + # The same for what is wrong with the machine, and what it is: neither may cost the rest of the report. + $health = $null + try { $health = Get-HostHealth $Config } catch { Write-Warning "Reading host health failed. ($($_.Exception.Message))" } + $hardware = $null + try { $hardware = Get-HardwareInfo } catch { Write-Warning "Reading the hardware identity failed. ($($_.Exception.Message))" } + return [ordered]@{ updates = $updates + health = $health + hardware = $hardware 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 }) } memory = [ordered]@{ total_bytes = $totalBytes; used_bytes = ($totalBytes - $freeBytes) } @@ -437,7 +558,7 @@ function Invoke-Agent { # Hardware and network facts are best-effort, like the Linux agent: a quirk on one host must not cost the whole report. $system = $null try { - $system = Get-SystemInfo + $system = Get-SystemInfo $config } catch { Write-Warning "Collecting hardware/network info failed - reporting tasks without it. ($($_.Exception.Message))" } diff --git a/package-lock.json b/package-lock.json index b0b8a7f..d0ee055 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3781,6 +3781,12 @@ "node": ">= 0.10" } }, + "node_modules/qrcode-generator": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-2.0.4.tgz", + "integrity": "sha512-mZSiP6RnbHl4xL2Ap5HfkjLnmxfKcPWpWe/c+5XxCuetEenqmNFf1FH/ftXPCtFG5/TDobjsjz6sSNL0Sr8Z9g==", + "license": "MIT" + }, "node_modules/qs": { "version": "6.16.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz", @@ -5174,6 +5180,7 @@ "@tabler/icons-react": "^3.46.0", "cron-parser": "^5.10.0", "cronstrue": "^2.53.0", + "qrcode-generator": "^2.0.4", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^7.1.1" diff --git a/server/drizzle/0034_lethal_mandarin.sql b/server/drizzle/0034_lethal_mandarin.sql new file mode 100644 index 0000000..c45bdc3 --- /dev/null +++ b/server/drizzle/0034_lethal_mandarin.sql @@ -0,0 +1,3 @@ +ALTER TABLE `servers` ADD `hw_manufacturer` text;--> statement-breakpoint +ALTER TABLE `servers` ADD `hw_model` text;--> statement-breakpoint +ALTER TABLE `servers` ADD `hw_serial` text; \ No newline at end of file diff --git a/server/drizzle/0035_adorable_silhouette.sql b/server/drizzle/0035_adorable_silhouette.sql new file mode 100644 index 0000000..634904c --- /dev/null +++ b/server/drizzle/0035_adorable_silhouette.sql @@ -0,0 +1,10 @@ +CREATE TABLE `dependencies` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `from_type` text NOT NULL, + `from_id` integer NOT NULL, + `to_type` text NOT NULL, + `to_id` integer NOT NULL, + `created_at` text DEFAULT (current_timestamp) NOT NULL +); +--> statement-breakpoint +CREATE UNIQUE INDEX `dependencies_edge_idx` ON `dependencies` (`from_type`,`from_id`,`to_type`,`to_id`); \ No newline at end of file diff --git a/server/drizzle/0036_cheerful_slipstream.sql b/server/drizzle/0036_cheerful_slipstream.sql new file mode 100644 index 0000000..0f01d54 --- /dev/null +++ b/server/drizzle/0036_cheerful_slipstream.sql @@ -0,0 +1,13 @@ +CREATE TABLE `push_subscriptions` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `user_id` integer NOT NULL, + `endpoint` text NOT NULL, + `p256dh` text NOT NULL, + `auth` text NOT NULL, + `label` text, + `created_at` text DEFAULT (current_timestamp) NOT NULL, + `last_success_at` text, + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `push_subscriptions_endpoint_unique` ON `push_subscriptions` (`endpoint`); \ No newline at end of file diff --git a/server/drizzle/meta/0034_snapshot.json b/server/drizzle/meta/0034_snapshot.json new file mode 100644 index 0000000..1e9c7d7 --- /dev/null +++ b/server/drizzle/meta/0034_snapshot.json @@ -0,0 +1,3188 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "020136de-b281-4f80-8b99-28faa0756afc", + "prevId": "af8acc1a-2fec-4534-9229-628ba8318548", + "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 + } + }, + "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": {} + }, + "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 + }, + "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": {} + }, + "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": {} + }, + "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": {} + }, + "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": {} + }, + "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 + }, + "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": {} + }, + "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_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 + }, + "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 + } + }, + "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/0035_snapshot.json b/server/drizzle/meta/0035_snapshot.json new file mode 100644 index 0000000..3082944 --- /dev/null +++ b/server/drizzle/meta/0035_snapshot.json @@ -0,0 +1,3252 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "86a266ae-b927-4dd6-9ec0-21610394b38a", + "prevId": "020136de-b281-4f80-8b99-28faa0756afc", + "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 + } + }, + "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": {} + }, + "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 + }, + "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": {} + }, + "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": {} + }, + "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": {} + }, + "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 + }, + "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": {} + }, + "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_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 + }, + "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 + } + }, + "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/0036_snapshot.json b/server/drizzle/meta/0036_snapshot.json new file mode 100644 index 0000000..49ecc6d --- /dev/null +++ b/server/drizzle/meta/0036_snapshot.json @@ -0,0 +1,3341 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "abcf9403-1726-47c5-9288-86240ad38535", + "prevId": "86a266ae-b927-4dd6-9ec0-21610394b38a", + "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 + } + }, + "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": {} + }, + "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 + }, + "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": {} + }, + "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": {} + }, + "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": {} + }, + "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 + }, + "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 + } + }, + "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": {} + }, + "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_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 + }, + "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 + } + }, + "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 02863f4..672379e 100644 --- a/server/drizzle/meta/_journal.json +++ b/server/drizzle/meta/_journal.json @@ -239,6 +239,27 @@ "when": 1792329463659, "tag": "0033_bright_princess_powerful", "breakpoints": true + }, + { + "idx": 34, + "version": "6", + "when": 1792340718369, + "tag": "0034_lethal_mandarin", + "breakpoints": true + }, + { + "idx": 35, + "version": "6", + "when": 1792341079438, + "tag": "0035_adorable_silhouette", + "breakpoints": true + }, + { + "idx": 36, + "version": "6", + "when": 1792341456680, + "tag": "0036_cheerful_slipstream", + "breakpoints": true } ] } \ No newline at end of file diff --git a/server/src/app.ts b/server/src/app.ts index df9b504..14202e7 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -15,6 +15,8 @@ import { updateRunsRouter } from "./routes/updateRuns.js"; import { dbBackupsRouter } from "./routes/dbBackups.js"; import { incidentsRouter } from "./routes/incidents.js"; import { inventoryRouter } from "./routes/inventory.js"; +import { dependenciesRouter } from "./routes/dependencies.js"; +import { pushRouter } from "./routes/push.js"; import { backupsRouter } from "./routes/backups.js"; import { metricsRouter, metricsTokensRouter } from "./routes/metrics.js"; import { eventWebhooksRouter } from "./routes/eventWebhooks.js"; @@ -106,6 +108,8 @@ export function createApp() { app.use("/api/db-backups", dbBackupsRouter); app.use("/api/incidents", incidentsRouter); app.use("/api/inventory", inventoryRouter); + app.use("/api/dependencies", dependenciesRouter); + app.use("/api/push", pushRouter); app.use("/api/backups", backupsRouter); app.use("/api/metrics-tokens", metricsTokensRouter); app.use("/api/event-webhooks", eventWebhooksRouter); diff --git a/server/src/db/schema.ts b/server/src/db/schema.ts index 683063e..8f1dc97 100644 --- a/server/src/db/schema.ts +++ b/server/src/db/schema.ts @@ -103,6 +103,41 @@ export const maintenanceAliases = sqliteTable( (table) => [uniqueIndex("maintenance_aliases_unique_idx").on(table.address, table.targetType, table.targetId)], ); +// A browser or phone that asked for push notifications (one row per device). The endpoint is the browser's push service address, which is +// itself a secret: whoever has it with the keys can write to that device. Removed when the push service says it is gone, or the user signs out of it. +export const pushSubscriptions = sqliteTable("push_subscriptions", { + id: integer("id").primaryKey({ autoIncrement: true }), + userId: integer("user_id") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + endpoint: text("endpoint").notNull().unique(), + p256dh: text("p256dh").notNull(), + auth: text("auth").notNull(), + /** What the person calls it, or the browser it is. */ + label: text("label"), + createdAt: text("created_at") + .notNull() + .default(sql`(current_timestamp)`), + lastSuccessAt: text("last_success_at"), +}); + +// "A needs B", for things that can be down: a server or an integration each. Polymorphic like maintenance_windows (no foreign key); an edge whose +// end was deleted is ignored. When B is down, A's alert is folded under B's — see services/dependencies.ts. +export const dependencies = sqliteTable( + "dependencies", + { + id: integer("id").primaryKey({ autoIncrement: true }), + fromType: text("from_type").notNull(), // server | integration + fromId: integer("from_id").notNull(), + toType: text("to_type").notNull(), + toId: integer("to_id").notNull(), + createdAt: text("created_at") + .notNull() + .default(sql`(current_timestamp)`), + }, + (table) => [uniqueIndex("dependencies_edge_idx").on(table.fromType, table.fromId, table.toType, table.toId)], +); + // A short history of each agent-reported server's load, memory and disk use, in percent — see services/serverMetrics.ts. // `metric` is "cpu", "mem" or "disk:". export const serverMetrics = sqliteTable( @@ -300,6 +335,11 @@ export const servers = sqliteTable("servers", { // What the agent says about the machine's own health, as JSON: {failedUnits, smart, zfs, reportedAt} — see services/hostHealth.ts. Null until it says. hostHealth: text("host_health"), + // 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"), + hwSerial: text("hw_serial"), + // This server's own alert thresholds, as JSON: {serverOfflineMinutes, diskUsagePercent, diskForecastDays, backupStaleHours, mounts: {"/data": {percent, ignore}}} — see // services/serverThresholds.ts. Whatever isn't there follows Settings. Null when it follows Settings entirely. thresholds: text("thresholds"), diff --git a/server/src/routes/agentReport.ts b/server/src/routes/agentReport.ts index 941799a..bbe1c66 100644 --- a/server/src/routes/agentReport.ts +++ b/server/src/routes/agentReport.ts @@ -52,7 +52,21 @@ const healthSchema = z.object({ .catch(undefined), }); +// What the machine is. Each part is optional and a malformed one is dropped, like the rest. +const hardwareSchema = z.object({ + manufacturer: text(100).optional().catch(undefined), + model: text(150).optional().catch(undefined), + serial: text(100).optional().catch(undefined), +}); + const systemSchema = z.object({ + hardware: z + .unknown() + .optional() + .transform((h) => { + const parsed = hardwareSchema.safeParse(h); + return parsed.success && Object.values(parsed.data).some((v) => typeof v === "string" && v.trim()) ? parsed.data : undefined; + }), health: z .unknown() .optional() diff --git a/server/src/routes/dependencies.ts b/server/src/routes/dependencies.ts new file mode 100644 index 0000000..e247397 --- /dev/null +++ b/server/src/routes/dependencies.ts @@ -0,0 +1,80 @@ +import { Router } from "express"; +import { eq } from "drizzle-orm"; +import { z } from "zod"; +import { db } from "../db/client.js"; +import { dependencies } from "../db/schema.js"; +import { requireAuth, requireRole } from "../auth/middleware.js"; +import { recordAudit } from "../services/audit.js"; +import { invalidateAlertsCache } from "../services/alerts.js"; +import { loadGraph, nodeKey, nodeTypes, wouldLoop } from "../services/dependencies.js"; +import { asyncHandler } from "../utils/asyncHandler.js"; + +export const dependenciesRouter = Router(); + +dependenciesRouter.use(requireAuth); + +const edgeSchema = z.object({ + fromType: z.enum(nodeTypes), + fromId: z.number().int().positive(), + toType: z.enum(nodeTypes), + toId: z.number().int().positive(), +}); + +// Everything signed in people may see: what needs what, with the "runs on" links of servers alongside (those are set on the server itself). +dependenciesRouter.get("/", asyncHandler(async (_req, res) => { + const graph = await loadGraph(); + const written = new Set(graph.rows.map((r) => `${nodeKey(r.fromType, r.fromId)}>${nodeKey(r.toType, r.toId)}`)); + const runsOn: { from: string; to: string }[] = []; + for (const [from, tos] of graph.edges) for (const to of tos) if (!written.has(`${from}>${to}`)) runsOn.push({ from, to }); + const nodes = [...graph.names.entries()] + .map(([key, name]) => { + const [type, id] = key.split(":"); + return { key, type, id: Number(id), name }; + }) + .sort((a, b) => a.type.localeCompare(b.type) || a.name.localeCompare(b.name)); + res.json({ + dependencies: graph.rows + .filter((r) => graph.names.has(nodeKey(r.fromType, r.fromId)) && graph.names.has(nodeKey(r.toType, r.toId))) + .map((r) => ({ id: r.id, from: { type: r.fromType, id: r.fromId, name: graph.names.get(nodeKey(r.fromType, r.fromId))! }, to: { type: r.toType, id: r.toId, name: graph.names.get(nodeKey(r.toType, r.toId))! }, createdAt: r.createdAt })), + runsOn: runsOn.map((r) => ({ from: { key: r.from, name: graph.names.get(r.from) ?? r.from }, to: { key: r.to, name: graph.names.get(r.to) ?? r.to } })), + nodes, + }); +})); + +dependenciesRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => { + const parsed = edgeSchema.safeParse(req.body); + if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Say what needs what: a server or an integration each.", details: parsed.error.flatten() }); + const d = parsed.data; + const graph = await loadGraph(); + const from = nodeKey(d.fromType, d.fromId); + const to = nodeKey(d.toType, d.toId); + if (!graph.names.has(from) || !graph.names.has(to)) return res.status(400).json({ error: "unknown_node", message: "One of those doesn't exist." }); + if (from === to) return res.status(400).json({ error: "self", message: "Something can't depend on itself." }); + if (graph.edges.get(from)?.includes(to)) return res.status(409).json({ error: "duplicate", message: "That is already so." }); + if (wouldLoop(graph.edges, from, to)) { + return res.status(409).json({ error: "loop", message: `${graph.names.get(to)} already depends on ${graph.names.get(from)}, so this would make them wait for each other.` }); + } + const [row] = await db.insert(dependencies).values(d).returning(); + await recordAudit({ actor: req.currentUser!, category: "dependency", action: "create", targetType: "dependency", targetId: row.id, detail: { from: graph.names.get(from), to: graph.names.get(to) } }); + invalidateAlertsCache(); + res.status(201).json({ id: row.id }); +})); + +dependenciesRouter.delete("/:id", requireRole("operator"), asyncHandler(async (req, res) => { + const id = /^\d+$/.test(req.params.id) ? Number(req.params.id) : NaN; + if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" }); + const [before] = await db.select().from(dependencies).where(eq(dependencies.id, id)).limit(1); + if (!before) return res.status(404).json({ error: "not_found" }); + const graph = await loadGraph(); + await db.delete(dependencies).where(eq(dependencies.id, id)); + await recordAudit({ + actor: req.currentUser!, + category: "dependency", + action: "delete", + targetType: "dependency", + targetId: id, + detail: { from: graph.names.get(nodeKey(before.fromType as "server", before.fromId)) ?? `${before.fromType} #${before.fromId}`, to: graph.names.get(nodeKey(before.toType as "server", before.toId)) ?? `${before.toType} #${before.toId}` }, + }); + invalidateAlertsCache(); + res.status(204).end(); +})); diff --git a/server/src/routes/inventory.ts b/server/src/routes/inventory.ts index de8ccf1..499472e 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 } from "../services/inventory.js"; +import { blanksToFill, differences, hardwareOf } from "../services/inventoryAutofill.js"; import { getSettings, updateSettings } from "../services/settingsStore.js"; import { asyncHandler } from "../utils/asyncHandler.js"; @@ -53,16 +54,32 @@ function values(d: z.infer) { }; } +/** A linked entry's blank maker, model and serial, from what that server's agent says. */ +async function fillFromAgent(v: ReturnType) { + if (v.serverId === null) return {}; + const [server] = await db.select({ hwManufacturer: servers.hwManufacturer, hwModel: servers.hwModel, hwSerial: servers.hwSerial }).from(servers).where(eq(servers.id, v.serverId)).limit(1); + return blanksToFill(v, hardwareOf(server)); +} + const idOf = (v: string) => (/^\d+$/.test(v) ? Number(v) : NaN); // Everything signed-in people may see: the hardware, and the price of power the running cost is worked out with. inventoryRouter.get("/", asyncHandler(async (_req, res) => { - const [rows, serverRows, settings] = await Promise.all([db.select().from(assets).orderBy(assets.name), db.select({ id: servers.id, name: servers.name }).from(servers), getSettings()]); - const serverName = new Map(serverRows.map((s) => [s.id, s.name])); + const [rows, serverRows, settings] = await Promise.all([db.select().from(assets).orderBy(assets.name), db.select().from(servers), getSettings()]); + const byId = new Map(serverRows.map((s) => [s.id, s])); res.json({ - assets: rows.map((a) => ({ ...a, server: a.serverId !== null && serverName.has(a.serverId) ? { id: a.serverId, name: serverName.get(a.serverId)! } : null })), + assets: rows.map((a) => { + const s = a.serverId !== null ? byId.get(a.serverId) : undefined; + const hw = hardwareOf(s); + return { + ...a, + server: s ? { id: s.id, name: s.name } : null, + // What the machine's agent says it is, and what that would change here (for the "refresh from agent" button). + agent: hw ? { ...hw, differs: differences(a, hw) } : null, + }; + }), config: settings.inventory, - servers: serverRows.sort((a, b) => a.name.localeCompare(b.name)), + servers: serverRows.map((s) => ({ id: s.id, name: s.name })).sort((a, b) => a.name.localeCompare(b.name)), }); })); @@ -89,8 +106,9 @@ inventoryRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) return res.status(400).json({ error: "unknown_server", message: "That server doesn't exist." }); } const now = new Date().toISOString(); - const [row] = await db.insert(assets).values({ ...v, createdAt: now, updatedAt: now }).returning(); - await recordAudit({ actor: req.currentUser!, category: "inventory", action: "create", targetType: "asset", targetId: row.id, detail: { name: row.name, kind: row.kind } }); + const filled = await fillFromAgent(v); + const [row] = await db.insert(assets).values({ ...v, ...filled, createdAt: now, updatedAt: now }).returning(); + await recordAudit({ actor: req.currentUser!, category: "inventory", action: "create", targetType: "asset", targetId: row.id, detail: { name: row.name, kind: row.kind, ...(Object.keys(filled).length ? { filledFromAgent: Object.keys(filled) } : {}) } }); res.status(201).json({ asset: row }); })); @@ -104,11 +122,27 @@ inventoryRouter.put("/:id", requireRole("operator"), asyncHandler(async (req, re if (v.serverId !== null && (await db.select({ id: servers.id }).from(servers).where(eq(servers.id, v.serverId))).length === 0) { return res.status(400).json({ error: "unknown_server", message: "That server doesn't exist." }); } - const [row] = await db.update(assets).set({ ...v, updatedAt: new Date().toISOString() }).where(eq(assets.id, id)).returning(); - await recordAudit({ actor: req.currentUser!, category: "inventory", action: "update", targetType: "asset", targetId: id, detail: { name: row.name } }); + const filled = await fillFromAgent(v); + const [row] = await db.update(assets).set({ ...v, ...filled, updatedAt: new Date().toISOString() }).where(eq(assets.id, id)).returning(); + await recordAudit({ actor: req.currentUser!, category: "inventory", action: "update", targetType: "asset", targetId: id, detail: { name: row.name, ...(Object.keys(filled).length ? { filledFromAgent: Object.keys(filled) } : {}) } }); res.json({ asset: row }); })); +// Takes what the agent says over what is written here: the one deliberate overwrite (the entry's own fields are otherwise only ever filled when blank). +inventoryRouter.post("/:id/refresh-from-agent", 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 [before] = await db.select().from(assets).where(eq(assets.id, id)).limit(1); + if (!before) return res.status(404).json({ error: "not_found" }); + if (before.serverId === null) return res.status(400).json({ error: "not_linked", message: "Link the entry to a server first." }); + const [server] = await db.select({ hwManufacturer: servers.hwManufacturer, hwModel: servers.hwModel, hwSerial: servers.hwSerial }).from(servers).where(eq(servers.id, before.serverId)).limit(1); + const changes = differences(before, hardwareOf(server)); + if (Object.keys(changes).length === 0) return res.json({ asset: before, changed: [] }); + const [row] = await db.update(assets).set({ ...changes, updatedAt: new Date().toISOString() }).where(eq(assets.id, id)).returning(); + await recordAudit({ actor: req.currentUser!, category: "inventory", action: "refresh_from_agent", targetType: "asset", targetId: id, detail: { name: row.name, from: Object.fromEntries(Object.keys(changes).map((k) => [k, (before as any)[k]])), to: changes } }); + res.json({ asset: row, changed: Object.keys(changes) }); +})); + inventoryRouter.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" }); diff --git a/server/src/routes/privacy.ts b/server/src/routes/privacy.ts index fe3b525..43fee3c 100644 --- a/server/src/routes/privacy.ts +++ b/server/src/routes/privacy.ts @@ -63,6 +63,7 @@ privacyRouter.get("/", asyncHandler(async (req, res) => { ntfy: channel(settings.ntfy.enabled, hostOf(settings.ntfy.url)), smtp: channel(settings.smtp.enabled, settings.smtp.host || null), webhook: channel(settings.webhook.enabled, hostOf(settings.webhook.url)), + webPush: channel(settings.webPush.enabled, "the push services of your browsers (Google, Mozilla, Apple …)"), }, }, }); diff --git a/server/src/routes/push.ts b/server/src/routes/push.ts new file mode 100644 index 0000000..b6ac951 --- /dev/null +++ b/server/src/routes/push.ts @@ -0,0 +1,97 @@ +import { Router } from "express"; +import { and, eq } from "drizzle-orm"; +import { z } from "zod"; +import { db } from "../db/client.js"; +import { pushSubscriptions } from "../db/schema.js"; +import { requireAuth } from "../auth/middleware.js"; +import { recordAudit } from "../services/audit.js"; +import { getSettings } from "../services/settingsStore.js"; +import { checkEndpoint, getVapidKeys, sendPush } from "../services/webPush.js"; +import { asyncHandler } from "../utils/asyncHandler.js"; + +export const pushRouter = Router(); + +pushRouter.use(requireAuth); + +/** At most this many browsers per person: a phone, a laptop, a tablet and the odd one. */ +const MAX_PER_USER = 10; + +const subscribeSchema = z.object({ + endpoint: z.string().url().max(2000), + keys: z.object({ p256dh: z.string().min(80).max(100), auth: z.string().min(20).max(30) }), + label: z.string().trim().max(80).optional(), +}); + +const hostOf = (endpoint: string) => { + try { + return new URL(endpoint).host; + } catch { + return ""; + } +}; + +const off = { error: "push_disabled", message: "Push notifications are switched off. An administrator turns them on under Settings, Notifications." }; + +// The key a browser subscribes with. Anyone signed in may ask (their own device is theirs to enrol), once push is on. +pushRouter.get("/key", asyncHandler(async (_req, res) => { + const { webPush } = await getSettings(); + if (!webPush.enabled) return res.status(409).json(off); + res.json({ publicKey: (await getVapidKeys()).publicKey }); +})); + +// This person's own browsers. +pushRouter.get("/mine", asyncHandler(async (req, res) => { + const rows = await db.select().from(pushSubscriptions).where(eq(pushSubscriptions.userId, req.currentUser!.id)).orderBy(pushSubscriptions.id); + const { webPush } = await getSettings(); + res.json({ + enabled: webPush.enabled, + subscriptions: rows.map((r) => ({ id: r.id, label: r.label, host: hostOf(r.endpoint), endpoint: r.endpoint, createdAt: r.createdAt, lastSuccessAt: r.lastSuccessAt })), + }); +})); + +pushRouter.post("/subscribe", asyncHandler(async (req, res) => { + const { webPush } = await getSettings(); + if (!webPush.enabled) return res.status(409).json(off); + const parsed = subscribeSchema.safeParse(req.body); + if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "That isn't a push subscription.", details: parsed.error.flatten() }); + const { endpoint, keys, label } = parsed.data; + try { + await checkEndpoint(endpoint); + } catch (err) { + return res.status(400).json({ error: "bad_endpoint", message: err instanceof Error ? err.message : "That push address can't be used." }); + } + const me = req.currentUser!; + const mine = await db.select({ id: pushSubscriptions.id, endpoint: pushSubscriptions.endpoint }).from(pushSubscriptions).where(eq(pushSubscriptions.userId, me.id)); + const existing = mine.find((r) => r.endpoint === endpoint); + if (!existing && mine.length >= MAX_PER_USER) return res.status(409).json({ error: "too_many", message: `You already have ${MAX_PER_USER} browsers subscribed. Remove one first.` }); + // The same browser subscribing again (or after someone else used it) is the same row, now this person's. + const [row] = await db + .insert(pushSubscriptions) + .values({ userId: me.id, endpoint, p256dh: keys.p256dh, auth: keys.auth, label: label || null }) + .onConflictDoUpdate({ target: pushSubscriptions.endpoint, set: { userId: me.id, p256dh: keys.p256dh, auth: keys.auth, label: label || null } }) + .returning({ id: pushSubscriptions.id }); + if (!existing) await recordAudit({ actor: me, category: "push", action: "subscribe", targetType: "push_subscription", targetId: row.id, detail: { host: hostOf(endpoint), label: label || null } }); + res.status(201).json({ id: row.id }); +})); + +// Stops a browser being written to. A person removes their own; an administrator may remove anyone's. +pushRouter.delete("/:id", asyncHandler(async (req, res) => { + const id = /^\d+$/.test(req.params.id) ? Number(req.params.id) : NaN; + if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" }); + const me = req.currentUser!; + const [row] = await db.select().from(pushSubscriptions).where(eq(pushSubscriptions.id, id)).limit(1); + if (!row || (row.userId !== me.id && me.role !== "admin")) return res.status(404).json({ error: "not_found" }); + await db.delete(pushSubscriptions).where(and(eq(pushSubscriptions.id, id))); + await recordAudit({ actor: me, category: "push", action: "unsubscribe", targetType: "push_subscription", targetId: id, detail: { host: hostOf(row.endpoint), label: row.label } }); + res.status(204).end(); +})); + +// A message to this person's own browsers, to see that it works. +pushRouter.post("/test", asyncHandler(async (req, res) => { + const { webPush } = await getSettings(); + if (!webPush.enabled) return res.status(409).json(off); + const mine = await db.select().from(pushSubscriptions).where(eq(pushSubscriptions.userId, req.currentUser!.id)); + if (mine.length === 0) return res.status(400).json({ error: "none", message: "This browser isn't subscribed yet." }); + const outcome = await sendPush({ title: "Homelab Manager — Test", body: "Push notifications are working.", url: "/settings/notifications", tag: "test" }, mine); + res.json(outcome); +})); diff --git a/server/src/routes/settings.ts b/server/src/routes/settings.ts index a9b9e72..c4cec67 100644 --- a/server/src/routes/settings.ts +++ b/server/src/routes/settings.ts @@ -64,6 +64,7 @@ const updateSchema = z.object({ .partial() .optional(), webhook: z.object({ enabled: z.boolean(), url: z.string(), secret: z.string() }).partial().optional(), + webPush: z.object({ enabled: z.boolean(), contact: z.string().trim().max(200) }).partial().optional(), notifications: z .object({ dnsAdd: z.boolean(), diff --git a/server/src/services/agentVersions.ts b/server/src/services/agentVersions.ts index b7cb9d0..322436e 100644 --- a/server/src/services/agentVersions.ts +++ b/server/src/services/agentVersions.ts @@ -8,7 +8,9 @@ * 2 — reports pending updates, and its own version * 3 — Linux: the package manager is asked outside the systemd sandbox, so dnf and zypper can answer too. * Windows: can replace itself when an administrator has switched automatic updates on. - * 4 — Linux: also reports failed services, disk health (SMART) and ZFS pools, reads pacman, and can replace itself too + * 4 — Linux: also reports failed services, disk health (SMART) and ZFS pools, reads pacman, and can replace itself too. + * 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 */ 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 1146119..60e532e 100644 --- a/server/src/services/alerts.ts +++ b/server/src/services/alerts.ts @@ -33,7 +33,7 @@ import { computeSecretStatus } from "./secretStatus.js"; import { getFailingSources } from "./integrationHealthMonitor.js"; import { getSettings } from "./settingsStore.js"; import { sourceLabel } from "./notify.js"; -import { coveredByParent, loadParentRows, resolveParents } from "./serverParents.js"; +import { dependencyCover, integrationTypeCause, takenByType } from "./dependencies.js"; import type { Alert, AlertCategory, AlertSeverity, SourceFailure } from "./alertTypes.js"; export interface AlertsReport { @@ -158,6 +158,10 @@ export async function collectAlerts(): Promise { } } + // The servers found to be offline, for the integration failures that one may explain: the server check fills it in (and it is empty if that check fails). + let offlineKnown!: (ids: Set) => void; + const offlineServers = new Promise>((resolve) => (offlineKnown = resolve)); + await Promise.all([ check("Server and storage health", async () => { const { healthChecks } = await getSettings(); @@ -176,17 +180,17 @@ export async function collectAlerts(): Promise { const m = /^offline:server:(\d+)$/.exec(c.key); if (m) offlineIds.add(Number(m[1])); } - const cause = coveredByParent(offlineIds, resolveParents(await loadParentRows())); - const taken = new Map(); - for (const [child, parent] of cause) taken.set(parent, [...(taken.get(parent) ?? []), serverNames.get(child) ?? `#${child}`]); + // (Or because of a service it needs that is failing, or a server it needs that needs one.) + offlineKnown(offlineIds); + const cover = await dependencyCover(offlineIds, getFailingSources().map((f) => f.source)); for (const c of conditions) { const origin = originOfConditionKey(c.key); const subject = subjectOfConditionKey(c.key); const offlineId = /^offline:server:(\d+)$/.exec(c.key)?.[1]; - const parentOf = offlineId ? cause.get(Number(offlineId)) : undefined; + const parentOf = offlineId ? cover.cause.get(`server:${offlineId}`) : undefined; push({ - causedBy: parentOf !== undefined ? { name: serverNames.get(parentOf) ?? `#${parentOf}` } : undefined, - affects: offlineId ? taken.get(Number(offlineId))?.sort((a, b) => a.localeCompare(b)) : undefined, + causedBy: parentOf !== undefined ? { name: cover.graph.names.get(parentOf) ?? parentOf } : undefined, + affects: offlineId ? cover.taken.get(`server:${offlineId}`)?.sort((a, b) => a.localeCompare(b)) : undefined, category: origin.category, severity: c.severity ?? "warning", type: origin.type, @@ -203,7 +207,7 @@ export async function collectAlerts(): Promise { const row = intById.get(Number(m[2])); cannotCheck(`${SOURCES[m[1]].label} “${row?.name ?? `#${m[2]}`}”${m[3] ? ` (node ${m[3]})` : ""}`, "couldn't be read — see the Diagnostic Log", "Server and storage health"); } - }), + }).finally(() => offlineKnown(new Set())), check("Automation runs", async () => { const { items, held } = await collectAutomation(); @@ -447,8 +451,15 @@ export async function collectAlerts(): Promise { check("Integration failures", async () => { const { notifications } = await getSettings(); - for (const f of getFailingSources()) { + const failing = getFailingSources(); + // A failure explained by something it needs that is down is folded under that, like a guest under its host. + const cover = failing.length > 0 ? await dependencyCover(await offlineServers, failing.map((f) => f.source)).catch(() => null) : null; + for (const f of failing) { + const cause = cover ? integrationTypeCause(f.source, cover) : null; + const affects = cover ? takenByType(f.source, cover) : []; push({ + causedBy: cause ? { name: cause.name } : undefined, + affects: affects.length > 0 ? affects.sort((a, b) => a.localeCompare(b)) : undefined, category: "integration", severity: f.alerted ? "critical" : "warning", type: f.source, diff --git a/server/src/services/dependencies.ts b/server/src/services/dependencies.ts new file mode 100644 index 0000000..d745093 --- /dev/null +++ b/server/src/services/dependencies.ts @@ -0,0 +1,192 @@ +/** + * What depends on what, beyond "this server runs on that server": a service that needs a server (Gitea on the box it is installed on), a + * server that needs a service (a guest that only exists while Proxmox answers). When the thing depended on is down, the things that need it + * are down too — and only the one that matters is worth an alert, so the rest are folded under it: shown, not announced. + * + * The graph is the "runs on" links of servers (set by hand or worked out from Proxmox, see serverParents.ts) plus the dependencies written + * here. Servers and integrations are the things that can be down and be needed. (DNS providers raise no alerts of their own, so there is + * nothing to fold.) An integration is judged per kind of service, as its health is: it is folded only if every enabled instance of that + * kind is explained. + */ +import { eq } from "drizzle-orm"; +import { db } from "../db/client.js"; +import { dependencies, integrations, servers } from "../db/schema.js"; +import { getInternalFlag } from "./settingsStore.js"; +import { loadParentRows, resolveParents, type ParentLink } from "./serverParents.js"; + +/** Where the health monitor keeps the problems it is announcing; read here so a service's alert can tell a server it needs is down. */ +export const HEALTH_STATE_FLAG = "healthActiveConditions"; + +export const nodeTypes = ["server", "integration"] as const; +export type NodeType = (typeof nodeTypes)[number]; + +export const nodeKey = (type: NodeType, id: number) => `${type}:${id}`; + +export interface DependencyEdge { + fromType: NodeType; + fromId: number; + toType: NodeType; + toId: number; +} + +/** node → the nodes it needs. */ +export type Edges = Map; + +/** The graph from the "runs on" links and the written dependencies; an edge to or from something that no longer exists is left out. */ +export function buildEdges(parentLinks: Map, rows: DependencyEdge[], exists: (key: string) => boolean): Edges { + const edges: Edges = new Map(); + const add = (from: string, to: string) => { + if (from === to || !exists(from) || !exists(to)) return; + const list = edges.get(from) ?? []; + if (!list.includes(to)) edges.set(from, [...list, to]); + }; + for (const [child, link] of parentLinks) add(nodeKey("server", child), nodeKey("server", link.parentId)); + for (const r of rows) add(nodeKey(r.fromType, r.fromId), nodeKey(r.toType, r.toId)); + return edges; +} + +/** Everything `node` needs, directly or not, nearest first; `looped` if it ends up needing itself. */ +function ancestorsOf(node: string, edges: Edges): { order: string[]; looped: boolean } { + const order: string[] = []; + const seen = new Set(); + const queue = [...(edges.get(node) ?? [])]; + let looped = false; + while (queue.length > 0) { + const cur = queue.shift()!; + if (cur === node) { + looped = true; + continue; + } + if (seen.has(cur)) continue; + seen.add(cur); + order.push(cur); + queue.push(...(edges.get(cur) ?? [])); + } + return { order, looped }; +} + +/** + * Of the nodes that are down, those whose cause is something they need that is down too: each maps to the root cause — a down node that + * needs nothing that is down. A loop explains nothing (each would be waiting for the other), so its members stand alone and are announced. + */ +export function coveredNodes(down: Set, edges: Edges): Map { + const covered = new Map(); + for (const node of [...down].sort()) { + const { order, looped } = ancestorsOf(node, edges); + if (looped) continue; + const downAbove = order.filter((a) => down.has(a)); + const root = downAbove.find((a) => { + const above = ancestorsOf(a, edges); + return !above.looped && !above.order.some((x) => down.has(x)); + }); + if (root !== undefined) covered.set(node, root); + } + return covered; +} + +/** Would `from` needing `to` close a loop? True if `to` is `from` or already needs it, however indirectly. */ +export function wouldLoop(edges: Edges, from: string, to: string): boolean { + return from === to || ancestorsOf(to, edges).order.includes(from) || ancestorsOf(to, edges).looped; +} + +export interface Graph { + edges: Edges; + /** node → its name, for every node that exists. */ + names: Map; + rows: (DependencyEdge & { id: number; createdAt: string })[]; + /** Enabled instances of each kind of integration. */ + instances: Map; + intRows: { id: number; type: string; enabled: boolean }[]; +} + +export async function loadGraph(): Promise { + const [serverRows, intRows, depRows, parentRows] = await Promise.all([ + db.select({ id: servers.id, name: servers.name }).from(servers), + db.select({ id: integrations.id, name: integrations.name, type: integrations.type, enabled: integrations.enabled }).from(integrations), + db.select().from(dependencies), + loadParentRows(), + ]); + const names = new Map(); + for (const s of serverRows) names.set(nodeKey("server", s.id), s.name); + for (const i of intRows) names.set(nodeKey("integration", i.id), i.name); + const rows = depRows.map((r) => ({ id: r.id, fromType: r.fromType as NodeType, fromId: r.fromId, toType: r.toType as NodeType, toId: r.toId, createdAt: r.createdAt })); + const instances = new Map(); + for (const i of intRows) if (i.enabled) instances.set(i.type, [...(instances.get(i.type) ?? []), i.id]); + return { edges: buildEdges(resolveParents(parentRows), rows, (k) => names.has(k)), names, rows, instances, intRows }; +} + +export interface Cover { + /** Each node that is down because of another → the root cause. */ + cause: Map; + /** Each root cause → the names of what it takes down with it. */ + taken: Map; + graph: Graph; +} + +/** Works out what is down because of what, given the servers that are offline and the kinds of integration that are failing. */ +export async function dependencyCover(offlineServerIds: Iterable, failingTypes: Iterable): Promise { + const graph = await loadGraph(); + const down = new Set(); + for (const id of offlineServerIds) down.add(nodeKey("server", id)); + const failing = new Set(failingTypes); + for (const [type, ids] of graph.instances) if (failing.has(type)) for (const id of ids) down.add(nodeKey("integration", id)); + const cause = coveredNodes(down, graph.edges); + const taken = new Map(); + for (const [child, parent] of cause) taken.set(parent, [...(taken.get(parent) ?? []), graph.names.get(child) ?? child]); + return { cause, taken, graph }; +} + +/** The root cause behind a failing kind of integration, when every enabled instance of it is explained; null when it stands alone. */ +export function integrationTypeCause(type: string, cover: Cover): { key: string; name: string } | null { + const ids = cover.graph.instances.get(type); + if (!ids || ids.length === 0) return null; + let first: string | null = null; + for (const id of ids) { + const root = cover.cause.get(nodeKey("integration", id)); + if (root === undefined) return null; + first ??= root; + } + return first === null ? null : { key: first, name: cover.graph.names.get(first) ?? first }; +} + +/** What a root cause takes down, for a kind of integration: the folded names across all its instances. */ +export function takenByType(type: string, cover: Cover): string[] { + const out: string[] = []; + for (const id of cover.graph.instances.get(type) ?? []) out.push(...(cover.taken.get(nodeKey("integration", id)) ?? [])); + return out; +} + +/** The servers the health monitor is announcing as offline (or holding back as explained), from what it last stored. */ +export async function offlineServerIdsFromState(): Promise { + try { + const raw = await getInternalFlag(HEALTH_STATE_FLAG); + if (!raw) return []; + const ids: number[] = []; + for (const key of Object.keys(JSON.parse(raw) as Record)) { + const m = /^offline:server:(\d+)$/.exec(key); + if (m) ids.push(Number(m[1])); + } + return ids; + } catch { + return []; + } +} + +/** + * Whether a kind of integration that has started failing is failing because of something it needs that is down — a server the health + * monitor says is offline, or another service that is failing. Never throws: a problem here must not swallow a real outage. + */ +export async function integrationCausedBy(type: string, failingTypes: string[]): Promise<{ name: string } | null> { + try { + const cover = await dependencyCover(await offlineServerIdsFromState(), failingTypes); + return integrationTypeCause(type, cover); + } catch (err) { + console.error("[dependencies] couldn't work out whether a failure is explained:", err); + return null; + } +} + +export async function nodeExists(type: NodeType, id: number): Promise { + if (type === "server") return (await db.select({ id: servers.id }).from(servers).where(eq(servers.id, id)).limit(1)).length > 0; + return (await db.select({ id: integrations.id }).from(integrations).where(eq(integrations.id, id)).limit(1)).length > 0; +} diff --git a/server/src/services/healthMonitor.ts b/server/src/services/healthMonitor.ts index 287ca89..660a091 100644 --- a/server/src/services/healthMonitor.ts +++ b/server/src/services/healthMonitor.ts @@ -8,11 +8,12 @@ import { notifyHealthIssues, notifyHealthRecovered } from "./notify.js"; import { recordAudit } from "./audit.js"; import { getInternalFlag, getSettings, setInternalFlag } from "./settingsStore.js"; import { activeSubjects, subjectOfConditionKey } from "./maintenance.js"; -import { coveredByParent, loadParentRows, resolveParents } from "./serverParents.js"; +import { dependencyCover, HEALTH_STATE_FLAG } from "./dependencies.js"; +import { getFailingSources } from "./integrationHealthMonitor.js"; import { hostHealthConditions, parseHostHealth, type HostHealth } from "./hostHealth.js"; import { diskLimit, parseThresholds, type ServerThresholds } from "./serverThresholds.js"; -const STATE_FLAG = "healthActiveConditions"; +const STATE_FLAG = HEALTH_STATE_FLAG; /** After a restart the agents haven't had a chance to report yet (they run every 15 min), so server-derived conditions are held rather than judged. */ const STARTUP_GRACE_MS = Number(process.env.HEALTH_STARTUP_GRACE_MS ?? 20 * 60 * 1000); // the environment variable is for tests const PROCESS_START = Date.now(); @@ -396,18 +397,20 @@ export async function runHealthCheck(now: number = Date.now()): Promise<{ added: const m = /^offline:server:(\d+)$/.exec(c.key); if (m) offlineIds.add(Number(m[1])); } - const cause = coveredByParent(offlineIds, resolveParents(await loadParentRows())); - const coveredKeys = new Set([...cause.keys()].map((id) => `offline:server:${id}`)); + // (Also when it needs a service that is failing, or runs on a server that needs one.) + const cover = await dependencyCover(offlineIds, getFailingSources().map((f) => f.source)); + const coveredKeys = new Set(); + for (const child of cover.cause.keys()) { + const m = /^server:(\d+)$/.exec(child); + if (m) coveredKeys.add(`offline:server:${m[1]}`); + } const { added: announced, resolved, next, newlyDown, ended } = diffConditions(await loadState(), current, held, await activeSubjects(new Date(now)), coveredKeys); await setInternalFlag(STATE_FLAG, JSON.stringify(next)); // A host's message says what else it takes with it. - const names = new Map(snapshot.servers.map((s) => [s.id, s.name])); - const taken = new Map(); - for (const [child, parent] of cause) taken.set(parent, [...(taken.get(parent) ?? []), names.get(child) ?? `#${child}`]); const added = announced.map((c) => { const m = /^offline:server:(\d+)$/.exec(c.key); - const children = m ? taken.get(Number(m[1])) : undefined; + const children = m ? cover.taken.get(`server:${m[1]}`) : undefined; return children?.length ? { ...c, message: `${c.message} — also takes down ${alsoList(children)}` } : c; }); diff --git a/server/src/services/hostHealth.ts b/server/src/services/hostHealth.ts index 30abd3d..80bd657 100644 --- a/server/src/services/hostHealth.ts +++ b/server/src/services/hostHealth.ts @@ -18,6 +18,7 @@ export interface SmartDisk { /** NVMe and some SSDs say how much of their rated life is used, 0–100 (and past it). */ wearPercent: number | null; } +/** A storage pool: ZFS on Linux, Storage Spaces on Windows (which reports Healthy, Warning and Unhealthy as ONLINE, DEGRADED and FAULTED). */ export interface ZfsPool { name: string; /** ONLINE, DEGRADED, FAULTED, UNAVAIL, SUSPENDED … as zpool says it. */ @@ -117,7 +118,7 @@ export function hostHealthConditions(serverId: number, serverName: string, healt } for (const p of health.zfs ?? []) { if (!poolIsFine(p)) { - out.push({ key: `zfs:server:${serverId}:${p.name}`, severity: "critical", message: `${serverName}: ZFS pool ${p.name} is ${p.health}` }); + out.push({ key: `zfs:server:${serverId}:${p.name}`, severity: "critical", message: `${serverName}: storage pool ${p.name} is ${p.health}` }); } } return out; diff --git a/server/src/services/integrationHealthMonitor.ts b/server/src/services/integrationHealthMonitor.ts index e1a392c..d7f20af 100644 --- a/server/src/services/integrationHealthMonitor.ts +++ b/server/src/services/integrationHealthMonitor.ts @@ -6,6 +6,7 @@ import { ensureHistoryStart } from "./uptimeHistory.js"; import { getSettings } from "./settingsStore.js"; import { isSourceInMaintenance } from "./maintenance.js"; import { notifyIntegrationDown, notifyIntegrationRecovered } from "./notify.js"; +import { integrationCausedBy } from "./dependencies.js"; interface SourceHealth { consecutiveFailures: number; @@ -96,7 +97,9 @@ export async function trackIntegrationHealth(source: string, ok: boolean): Promi if (notifications.integrationFailureAlerts && !state.alerted && state.consecutiveFailures >= notifications.integrationFailureThreshold) { // During maintenance the failures keep being counted but `alerted` stays false, so if the service is // still failing once the window ends, the very next failed call alerts — a real outage isn't swallowed. - if (!(await isSourceInMaintenance(source))) { + // Likewise when it needs something that is down (the server it runs on, another service): that one is what gets announced, and if this stays + // down once that one is back, the next failed call alerts. + if (!(await isSourceInMaintenance(source)) && !(await integrationCausedBy(source, [...getFailingSources().map((f) => f.source), source]))) { state.alerted = true; await notifyIntegrationDown(source, state.consecutiveFailures); } diff --git a/server/src/services/inventoryAutofill.ts b/server/src/services/inventoryAutofill.ts new file mode 100644 index 0000000..2f59ae3 --- /dev/null +++ b/server/src/services/inventoryAutofill.ts @@ -0,0 +1,60 @@ +/** + * Filling in the inventory from what an agent has found out about the machine it runs on: maker, model and serial number. Typing a serial + * number off a label is the part of an inventory nobody keeps up, so a linked entry gets it from the agent — but only into fields that are + * blank, because what a person wrote down is theirs; "Refresh from agent" is the way to overwrite on purpose. + */ +import { eq, isNull, or, and } from "drizzle-orm"; +import { db } from "../db/client.js"; +import { assets, servers } from "../db/schema.js"; + +export interface AgentHardware { + manufacturer: string | null; + model: string | null; + serial: string | null; +} + +type Fields = { manufacturer: string | null; model: string | null; serial: string | null }; +const KEYS = ["manufacturer", "model", "serial"] as const; + +/** What the server's agent said the machine is, or null if it has said nothing. */ +export function hardwareOf(server: { hwManufacturer: string | null; hwModel: string | null; hwSerial: string | null } | null | undefined): AgentHardware | null { + if (!server) return null; + const hw = { manufacturer: server.hwManufacturer ?? null, model: server.hwModel ?? null, serial: server.hwSerial ?? null }; + return hw.manufacturer || hw.model || hw.serial ? hw : null; +} + +/** The fields of an entry that are blank and that the agent can fill. Empty when nothing would change. */ +export function blanksToFill(current: Fields, hw: AgentHardware | null): Partial { + const out: Partial = {}; + if (!hw) return out; + for (const k of KEYS) if (!current[k]?.trim() && hw[k]) out[k] = hw[k]; + return out; +} + +/** The fields where the agent says something different from the entry: what a refresh would change. */ +export function differences(current: Fields, hw: AgentHardware | null): Partial { + const out: Partial = {}; + if (!hw) return out; + for (const k of KEYS) if (hw[k] && (current[k] ?? "").trim() !== hw[k]) out[k] = hw[k]; + return out; +} + +/** After an agent has reported, fills the blanks of the inventory entries that are this server. */ +export async function fillInventoryFromServer(serverId: number): Promise { + const [server] = await db.select({ hwManufacturer: servers.hwManufacturer, hwModel: servers.hwModel, hwSerial: servers.hwSerial }).from(servers).where(eq(servers.id, serverId)).limit(1); + const hw = hardwareOf(server); + if (!hw) return 0; + // Only entries with something blank are worth reading. + const linked = await db + .select() + .from(assets) + .where(and(eq(assets.serverId, serverId), or(isNull(assets.manufacturer), isNull(assets.model), isNull(assets.serial)))); + let changed = 0; + for (const a of linked) { + const fill = blanksToFill(a, hw); + if (Object.keys(fill).length === 0) continue; + await db.update(assets).set({ ...fill, updatedAt: new Date().toISOString() }).where(eq(assets.id, a.id)); + changed++; + } + return changed; +} diff --git a/server/src/services/metrics.ts b/server/src/services/metrics.ts index 796a447..4e67668 100644 --- a/server/src/services/metrics.ts +++ b/server/src/services/metrics.ts @@ -95,7 +95,7 @@ export async function buildMetrics(now: Date = new Date()): Promise { if (d.wearPercent !== null) out.add("homelab_server_disk_wear_percent", "gauge", "How much of an SSD's rated life is used.", d.wearPercent, { server, device: d.device }); if (d.temperatureC !== null) out.add("homelab_server_disk_temperature_celsius", "gauge", "A disk's temperature.", d.temperatureC, { server, device: d.device }); } - for (const p of health?.zfs ?? []) out.add("homelab_server_zfs_pool_online", "gauge", "1 if a ZFS pool is ONLINE, 0 in any other state.", poolIsFine(p) ? 1 : 0, { server, pool: p.name }); + for (const p of health?.zfs ?? []) out.add("homelab_server_zfs_pool_online", "gauge", "1 if a storage pool (ZFS, or Storage Spaces on Windows) is ONLINE, 0 in any other state.", poolIsFine(p) ? 1 : 0, { server, pool: p.name }); out.add("homelab_server_agent_outdated", "gauge", "1 if the server's agent is older than the one this installation would install now.", isAgentOutdated(s, latest) ? 1 : 0, { server }); } // Disks on a steady climb, from each server's own history: days until full at the present rate (left out where there is no steady trend). diff --git a/server/src/services/notify.ts b/server/src/services/notify.ts index 6e67675..9cb24d9 100644 --- a/server/src/services/notify.ts +++ b/server/src/services/notify.ts @@ -2,6 +2,7 @@ import nodemailer from "nodemailer"; import { getSettings, type NotificationEvents } from "./settingsStore.js"; import { enqueueNotification, listQueuedNotifications, clearQueuedNotifications } from "./notificationQueue.js"; import { emitEvent } from "./eventWebhooks.js"; +import { sendPush, subscriptionCount } from "./webPush.js"; // ─── Channel senders (best-effort — failures are logged, never thrown) ────── @@ -72,8 +73,18 @@ async function sendWebhook(title: string, message: string) { } } +async function sendWebPush(title: string, message: string) { + const { webPush } = await getSettings(); + if (!webPush.enabled) return; + try { + await sendPush({ title, body: message }); + } catch (err) { + console.error("[notify] Web push failed:", err instanceof Error ? err.message : err); + } +} + async function sendToChannels(title: string, message: string): Promise { - await Promise.all([sendGotify(title, message), sendNtfy(title, message), sendSmtp(title, message), sendWebhook(title, message)]); + await Promise.all([sendGotify(title, message), sendNtfy(title, message), sendSmtp(title, message), sendWebhook(title, message), sendWebPush(title, message)]); } function currentTimeInZone(timezone: string): { hh: number; mm: number } { @@ -112,8 +123,9 @@ export async function notifyNow(title: string, message: string): Promise { /** How many channels are switched on and filled in enough to send, so a "send it now" can say when there is nowhere to send to. */ export async function enabledChannelCount(): Promise { - const { gotify, ntfy, smtp, webhook } = await getSettings(); + const { gotify, ntfy, smtp, webhook, webPush } = await getSettings(); return [ + webPush.enabled && (await subscriptionCount()) > 0, gotify.enabled && gotify.url && gotify.token, ntfy.enabled && ntfy.url && ntfy.topic, smtp.enabled && smtp.host && smtp.to && smtp.from, diff --git a/server/src/services/settingsStore.ts b/server/src/services/settingsStore.ts index db0b041..0cbd332 100644 --- a/server/src/services/settingsStore.ts +++ b/server/src/services/settingsStore.ts @@ -37,6 +37,13 @@ export interface WebhookSettings { secret: string; } +/** Push notifications to phones and browsers that have subscribed (see services/webPush.ts). Who is subscribed is kept apart, per device. */ +export interface WebPushSettings { + enabled: boolean; + /** Where a push service can reach whoever runs this: an email address or an https address (VAPID asks for one). Blank is fine. */ + contact: string; +} + export interface NotificationEvents { dnsAdd: boolean; dnsUpdate: boolean; @@ -189,6 +196,7 @@ export interface AppSettings { ntfy: NtfySettings; smtp: SmtpSettings; webhook: WebhookSettings; + webPush: WebPushSettings; notifications: NotificationEvents; providerColors: ProviderColors; integrationColors: IntegrationColors; @@ -211,6 +219,7 @@ const DEFAULTS: AppSettings = { ntfy: { enabled: false, url: "https://ntfy.sh", topic: "", token: "", priority: 3 }, smtp: { enabled: false, host: "", port: 587, secure: false, username: "", password: "", from: "", to: "" }, webhook: { enabled: false, url: "", secret: "" }, + webPush: { enabled: false, contact: "" }, notifications: { dnsAdd: true, dnsUpdate: true, diff --git a/server/src/services/taskSync.ts b/server/src/services/taskSync.ts index 78b739e..b3d8d35 100644 --- a/server/src/services/taskSync.ts +++ b/server/src/services/taskSync.ts @@ -5,6 +5,7 @@ import { recordServerMetrics } from "./serverMetrics.js"; import { nextUpdateState, type IncomingUpdates } from "./pendingUpdates.js"; import { nextHostHealth, type IncomingHostHealth } from "./hostHealth.js"; import { recordAudit } from "./audit.js"; +import { fillInventoryFromServer } from "./inventoryAutofill.js"; export interface IncomingTask { scheduleType: "cron" | "systemd_timer" | "windows_task"; @@ -27,6 +28,8 @@ export interface IncomingSystemInfo { updates?: IncomingUpdates; /** Failed services, disk health, ZFS pools — each part present only if the agent could find it out. */ health?: IncomingHostHealth; + /** What the machine is, from its firmware: each part present only if it says anything. */ + hardware?: { manufacturer?: string; model?: string; serial?: string }; } export interface AgentReport { @@ -115,6 +118,9 @@ export async function syncServerTasks(serverId: number, report: AgentReport) { // Only stored when the agent reported it, so an agent that predates this (or couldn't tell this time) doesn't wipe what it said before. ...(system?.updates && before ? nextUpdateState(before, system.updates, now) : {}), ...(system?.health && before ? { hostHealth: nextHostHealth(before.hostHealth, system.health, now) } : {}), + ...(system?.hardware?.manufacturer ? { hwManufacturer: system.hardware.manufacturer } : {}), + ...(system?.hardware?.model ? { hwModel: system.hardware.model } : {}), + ...(system?.hardware?.serial ? { hwSerial: system.hardware.serial } : {}), ...(report.hostname ? { hostname: report.hostname } : {}), ...(report.agentVersion !== undefined ? { agentVersion: report.agentVersion } : {}), // An agent knows what it runs on better than whoever registered the server did. @@ -146,6 +152,15 @@ export async function syncServerTasks(serverId: number, report: AgentReport) { } } + // A machine whose agent has said what it is fills in the blanks of its inventory entry. Also best-effort. + if (system?.hardware) { + try { + await fillInventoryFromServer(serverId); + } catch (err) { + console.error("[inventory] couldn't fill in from the agent:", err); + } + } + // Keep a little history of the figures too. A failure here must not lose the report itself, which is already saved. try { await recordServerMetrics(serverId, system, new Date(now)); diff --git a/server/src/services/webPush.ts b/server/src/services/webPush.ts new file mode 100644 index 0000000..404d3c0 --- /dev/null +++ b/server/src/services/webPush.ts @@ -0,0 +1,245 @@ +/** + * Web Push: notifications to a phone or a browser that has asked for them, with no app and no account — the browser's own push service + * (Google's, Mozilla's, Apple's) carries the message. Written against the standards directly rather than through a library: + * + * - RFC 8292 (VAPID): the server proves who it is with a short-lived signed token (ES256), so a push service knows the sender is the + * one the subscription was made for. + * - RFC 8291 + 8188 (aes128gcm): the message is encrypted for the one browser it is for; the push service only ever carries it. + * + * The server's key pair is made the first time it is needed and kept (the private half encrypted, like the other credentials). + */ +import { createCipheriv, createECDH, createPrivateKey, hkdfSync, randomBytes, sign, type KeyObject } from "node:crypto"; +import { eq } from "drizzle-orm"; +import { db } from "../db/client.js"; +import { pushSubscriptions } from "../db/schema.js"; +import { env } from "../env.js"; +import { decryptSecret, encryptSecret } from "../crypto.js"; +import { resolveTarget } from "../utils/networkGuard.js"; +import { getInternalFlag, getSettings, setInternalFlag } from "./settingsStore.js"; + +const b64u = (buf: Buffer | Uint8Array) => Buffer.from(buf).toString("base64url"); +const fromB64u = (s: string) => Buffer.from(s, "base64url"); + +// ─── The server's own key pair ───────────────────────────────────────────── + +const VAPID_FLAG = "webPushVapid"; +const ENCRYPTED = "enc:v1:"; + +export interface VapidKeys { + /** The uncompressed P-256 point, base64url — what a browser is given to subscribe with. */ + publicKey: string; + /** The private scalar, base64url. */ + privateKey: string; +} + +let cachedKeys: Promise | null = null; + +/** The key pair, made on first use and kept. */ +export function getVapidKeys(): Promise { + cachedKeys ??= loadOrMakeKeys().catch((err) => { + cachedKeys = null; + throw err; + }); + return cachedKeys; +} + +async function loadOrMakeKeys(): Promise { + const stored = await getInternalFlag(VAPID_FLAG); + if (stored) { + try { + const v = JSON.parse(stored) as { publicKey: string; privateKey: string }; + const privateKey = v.privateKey.startsWith(ENCRYPTED) ? decryptSecret(v.privateKey.slice(ENCRYPTED.length)) : v.privateKey; + return { publicKey: v.publicKey, privateKey }; + } catch { + // Unreadable (the encryption key changed): made again below — every browser must then subscribe again, which the page says. + } + } + const ecdh = createECDH("prime256v1"); + ecdh.generateKeys(); + const keys: VapidKeys = { publicKey: b64u(ecdh.getPublicKey()), privateKey: b64u(ecdh.getPrivateKey().length === 32 ? ecdh.getPrivateKey() : Buffer.concat([Buffer.alloc(32 - ecdh.getPrivateKey().length), ecdh.getPrivateKey()])) }; + await setInternalFlag(VAPID_FLAG, JSON.stringify({ publicKey: keys.publicKey, privateKey: env.credentialsEncryptionEnabled ? ENCRYPTED + encryptSecret(keys.privateKey) : keys.privateKey })); + // The subscriptions made for the old key can't be used with the new one. + await db.delete(pushSubscriptions); + return keys; +} + +/** For the tests, so one test's keys don't leak into the next. */ +export function forgetVapidKeysForTests(): void { + cachedKeys = null; +} + +/** A P-256 private key as a key object, from its raw scalar and public point. */ +function privateKeyObject(keys: VapidKeys): KeyObject { + const pub = fromB64u(keys.publicKey); + return createPrivateKey({ + key: { kty: "EC", crv: "P-256", d: keys.privateKey, x: b64u(pub.subarray(1, 33)), y: b64u(pub.subarray(33, 65)) }, + format: "jwk", + }); +} + +/** The Authorization header's token: who we are, who it is for, and for how long (RFC 8292). */ +export function vapidAuthorization(audience: string, subject: string, keys: VapidKeys, now: number = Date.now()): string { + const header = b64u(Buffer.from(JSON.stringify({ typ: "JWT", alg: "ES256" }))); + const claims = b64u(Buffer.from(JSON.stringify({ aud: audience, exp: Math.floor(now / 1000) + 12 * 3600, sub: subject }))); + const signature = sign("sha256", Buffer.from(`${header}.${claims}`), { key: privateKeyObject(keys), dsaEncoding: "ieee-p1363" }); + return `vapid t=${header}.${claims}.${b64u(signature)}, k=${keys.publicKey}`; +} + +// ─── Encrypting a message for one browser (RFC 8291) ─────────────────────── + +export interface PushKeys { + /** The browser's public key, base64url. */ + p256dh: string; + /** The browser's 16-byte authentication secret, base64url. */ + auth: string; +} + +const RECORD_SIZE = 4096; + +/** + * The body to send: the message encrypted so that only the browser it is for can read it. `ephemeral` and `salt` are chosen fresh each + * time; they are parameters only so the standard's own worked example can be checked. + */ +export function encryptPayload(payload: Buffer, subscription: PushKeys, fixed?: { ephemeral: ECDHLike; salt: Buffer }): Buffer { + const uaPublic = fromB64u(subscription.p256dh); + const authSecret = fromB64u(subscription.auth); + if (uaPublic.length !== 65 || uaPublic[0] !== 4) throw new Error("The browser's public key isn't a P-256 point."); + if (authSecret.length !== 16) throw new Error("The browser's authentication secret isn't 16 bytes."); + + const fresh = fixed ? null : createECDH("prime256v1"); + fresh?.generateKeys(); + const ecdh: ECDHLike = fixed?.ephemeral ?? fresh!; + const asPublic = ecdh.getPublicKey(); + const salt = fixed?.salt ?? randomBytes(16); + const secret = ecdh.computeSecret(uaPublic); + + const keyInfo = Buffer.concat([Buffer.from("WebPush: info\0"), uaPublic, asPublic]); + const ikm = Buffer.from(hkdfSync("sha256", secret, authSecret, keyInfo, 32)); + const cek = Buffer.from(hkdfSync("sha256", ikm, salt, Buffer.from("Content-Encoding: aes128gcm\0"), 16)); + const nonce = Buffer.from(hkdfSync("sha256", ikm, salt, Buffer.from("Content-Encoding: nonce\0"), 12)); + + // One record: the message, then a 0x02 marking it as the last. + if (payload.length > RECORD_SIZE - 17 - 1) throw new Error("The message is too long for one push."); + const cipher = createCipheriv("aes-128-gcm", cek, nonce); + const encrypted = Buffer.concat([cipher.update(Buffer.concat([payload, Buffer.from([2])])), cipher.final(), cipher.getAuthTag()]); + + const header = Buffer.alloc(16 + 4 + 1); + salt.copy(header, 0); + header.writeUInt32BE(RECORD_SIZE, 16); + header.writeUInt8(asPublic.length, 20); + return Buffer.concat([header, asPublic, encrypted]); +} + +type ECDHLike = Pick, "getPublicKey" | "computeSecret">; + +// ─── Subscriptions ───────────────────────────────────────────────────────── + +let allowLocalEndpoints = false; +/** Lets the tests push to a service on this machine, which is otherwise refused. */ +export function allowLocalPushEndpointsForTests(allow: boolean): void { + allowLocalEndpoints = allow; +} + +/** A push service is a public internet service with an https address; anything else is refused before we ever connect to it. */ +export async function checkEndpoint(endpoint: string): Promise { + let url: URL; + try { + url = new URL(endpoint); + } catch { + throw new Error("The push address isn't a web address."); + } + if (url.protocol !== "https:" && !(allowLocalEndpoints && url.protocol === "http:")) throw new Error("The push address must be https."); + if (url.username || url.password) throw new Error("The push address can't carry a login."); + if (allowLocalEndpoints) return; + await resolveTarget(url.hostname, { allowPrivate: false }); +} + +export interface PushOutcome { + sent: number; + /** Subscriptions the push service said are gone, now removed. */ + removed: number; + failed: number; +} + +/** The contact the push services may reach us on (a `mailto:` or an https address), as VAPID asks. */ +export async function vapidSubject(): Promise { + const { webPush } = await getSettings(); + const contact = webPush.contact.trim(); + if (/^(mailto:|https:\/\/)/i.test(contact)) return contact; + if (contact.includes("@")) return `mailto:${contact}`; + return /^https:\/\//.test(env.appBaseUrl) ? env.appBaseUrl : "mailto:homelab@example.invalid"; +} + +export interface PushMessage { + title: string; + body: string; + /** Where in the app a tap should go. */ + url?: string; + /** A later message with the same tag replaces an earlier one that is still showing. */ + tag?: string; +} + +/** Sends one message to one subscription. Resolves to what the push service said; never throws. */ +async function deliver(sub: { endpoint: string; p256dh: string; auth: string }, body: Buffer, keys: VapidKeys, subject: string, urgent: boolean): Promise<"sent" | "gone" | "failed"> { + try { + await checkEndpoint(sub.endpoint); + const res = await fetch(sub.endpoint, { + method: "POST", + headers: { + Authorization: vapidAuthorization(new URL(sub.endpoint).origin, subject, keys), + "Content-Encoding": "aes128gcm", + "Content-Type": "application/octet-stream", + TTL: "86400", + Urgency: urgent ? "high" : "normal", + }, + body: new Uint8Array(body), + signal: AbortSignal.timeout(15_000), + }); + if (res.ok) return "sent"; + if (res.status === 404 || res.status === 410) return "gone"; + console.error(`[push] ${new URL(sub.endpoint).host} answered ${res.status}: ${(await res.text().catch(() => "")).slice(0, 200)}`); + return "failed"; + } catch (err) { + console.error("[push] couldn't deliver:", err instanceof Error ? err.message : err); + return "failed"; + } +} + +/** Sends to the given subscriptions (all of them, if none are given). Subscriptions the push service says are gone are removed. */ +export async function sendPush(message: PushMessage, only?: { id: number; endpoint: string; p256dh: string; auth: string }[]): Promise { + const subs = only ?? (await db.select().from(pushSubscriptions)); + const outcome: PushOutcome = { sent: 0, removed: 0, failed: 0 }; + if (subs.length === 0) return outcome; + const keys = await getVapidKeys(); + const subject = await vapidSubject(); + const payload = Buffer.from(JSON.stringify({ title: message.title.slice(0, 120), body: message.body.slice(0, 600), url: message.url ?? "/alerts", tag: message.tag })); + await Promise.all( + subs.map(async (s) => { + let body: Buffer; + try { + body = encryptPayload(payload, { p256dh: s.p256dh, auth: s.auth }); + } catch (err) { + console.error("[push] a subscription can't be written to:", err instanceof Error ? err.message : err); + outcome.failed++; + return; + } + const result = await deliver(s, body, keys, subject, true); + if (result === "sent") { + outcome.sent++; + await db.update(pushSubscriptions).set({ lastSuccessAt: new Date().toISOString() }).where(eq(pushSubscriptions.id, s.id)); + } else if (result === "gone") { + outcome.removed++; + await db.delete(pushSubscriptions).where(eq(pushSubscriptions.id, s.id)); + } else { + outcome.failed++; + } + }), + ); + return outcome; +} + +/** How many browsers are subscribed. */ +export async function subscriptionCount(): Promise { + return (await db.select({ id: pushSubscriptions.id }).from(pushSubscriptions)).length; +} + diff --git a/server/test/dependencies.test.ts b/server/test/dependencies.test.ts new file mode 100644 index 0000000..8c0a1e8 --- /dev/null +++ b/server/test/dependencies.test.ts @@ -0,0 +1,212 @@ +/** + * Dependencies between servers and services: what is folded under what when something is down, and the routes that say what needs what. + * + * 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-deps-")); +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, auditLog } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const { buildEdges, coveredNodes, wouldLoop, integrationCausedBy, HEALTH_STATE_FLAG } = await import("../src/services/dependencies.js"); +const { setInternalFlag } = await import("../src/services/settingsStore.js"); +const { getAlerts, invalidateAlertsCache } = await import("../src/services/alerts.js"); +const { trackIntegrationHealth } = await import("../src/services/integrationHealthMonitor.js"); +const { dependenciesRouter } = await import("../src/routes/dependencies.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); + +const everything = () => true; +const edge = (fromType: "server" | "integration", fromId: number, toType: "server" | "integration", toId: number) => ({ fromType, fromId, toType, toId }); + +describe("who is down because of whom", () => { + test("a node is explained by the root of what it needs, however far up; things that are up in between don't matter", () => { + const edges = buildEdges(new Map(), [edge("integration", 1, "server", 1), edge("integration", 2, "integration", 1), edge("server", 2, "integration", 2)], everything); + const covered = coveredNodes(new Set(["server:1", "integration:1", "integration:2", "server:2"]), edges); + assert.deepEqual([...covered.entries()].sort(), [["integration:1", "server:1"], ["integration:2", "server:1"], ["server:2", "server:1"]]); + // the middle one is up: the one above it still explains the one below + const skip = coveredNodes(new Set(["server:1", "server:2"]), edges); + assert.deepEqual([...skip.entries()], [["server:2", "server:1"]]); + }); + + test("the 'runs on' links of servers are part of the graph", () => { + const edges = buildEdges(new Map([[2, { parentId: 1, auto: false }]]), [edge("integration", 1, "server", 2)], everything); + const covered = coveredNodes(new Set(["server:1", "integration:1"]), edges); + assert.equal(covered.get("integration:1"), "server:1"); + }); + + test("something that needs two things is explained by whichever is down; with none down it stands alone", () => { + const edges = buildEdges(new Map(), [edge("server", 1, "server", 2), edge("server", 1, "integration", 1)], everything); + assert.equal(coveredNodes(new Set(["server:1", "integration:1"]), edges).get("server:1"), "integration:1"); + assert.equal(coveredNodes(new Set(["server:1"]), edges).size, 0); + }); + + test("a loop explains nothing, and edges to things that are gone are ignored", () => { + const loop = buildEdges(new Map(), [edge("server", 1, "server", 2), edge("server", 2, "server", 1)], everything); + assert.equal(coveredNodes(new Set(["server:1", "server:2"]), loop).size, 0); + const gone = buildEdges(new Map(), [edge("server", 1, "server", 99)], (k) => k !== "server:99"); + assert.equal(gone.size, 0); + }); + + test("a new dependency that would close a loop is seen, including through 'runs on'", () => { + const edges = buildEdges(new Map([[2, { parentId: 1, auto: true }]]), [edge("integration", 1, "server", 2)], everything); + assert.equal(wouldLoop(edges, "server:1", "integration:1"), true, "the integration needs server 2, which runs on server 1"); + assert.equal(wouldLoop(edges, "server:1", "server:1"), true); + assert.equal(wouldLoop(edges, "integration:1", "server:1"), false, "already needs it, indirectly: not a loop"); + }); +}); + +describe("through the routes, the alerts and the notifications", () => { + let app: Server; + let base = ""; + let who = "operator"; + let box = 0; + let other = 0; + let gitea = 0; + let semaphore = 0; + + before(async () => { + await db.insert(users).values([ + { oidcSub: "operator", name: "Olga", role: "operator" }, + { oidcSub: "viewer", name: "Vic", role: "viewer" }, + ]); + const hoursAgo = (n: number) => new Date(Date.now() - n * 3600_000).toISOString(); + const made = await db + .insert(servers) + .values([ + { name: "box", apiTokenHash: "b", apiTokenPrefix: "b", lastSeenAt: hoursAgo(3) }, + { name: "other", apiTokenHash: "o", apiTokenPrefix: "o", lastSeenAt: new Date().toISOString() }, + ]) + .returning({ id: servers.id }); + box = made[0].id; + other = made[1].id; + const ints = await db + .insert(integrations) + .values([ + { type: "gitea", name: "Gitea", baseUrl: "https://git.lab", config: "{}" }, + { type: "semaphore", name: "Semaphore", baseUrl: "https://sem.lab", config: "{}" }, + ]) + .returning({ id: integrations.id }); + gitea = ints[0].id; + semaphore = ints[1].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/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 keeps the database file locked until the process exits. + } + }); + + const send = (method: string, path: string, body?: unknown) => fetch(`${base}${path}`, { method, headers: { "content-type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) }); + let firstId = 0; + + test("an operator says what needs what; it is listed with names", async () => { + const res = await send("POST", "/", edge("integration", gitea, "server", box)); + assert.equal(res.status, 201); + firstId = (await res.json()).id; + assert.equal((await send("POST", "/", edge("integration", semaphore, "integration", gitea))).status, 201); + const list = await (await send("GET", "/")).json(); + assert.deepEqual(list.dependencies.map((d: { from: { name: string }; to: { name: string } }) => `${d.from.name} > ${d.to.name}`).sort(), ["Gitea > box", "Semaphore > Gitea"]); + assert.ok(list.nodes.some((n: { key: string; name: string }) => n.key === `server:${box}` && n.name === "box")); + }); + + test("it can't be nonsense: not itself, not twice, not a loop, not something that isn't there, not by a viewer", async () => { + assert.equal((await send("POST", "/", edge("server", box, "server", box))).status, 400); + assert.equal((await send("POST", "/", edge("integration", gitea, "server", box))).status, 409, "twice"); + const loop = await send("POST", "/", edge("server", box, "integration", semaphore)); + assert.equal(loop.status, 409, "the server would wait for the thing that waits for it"); + assert.match((await loop.json()).message, /wait for each other/); + assert.equal((await send("POST", "/", edge("server", 99999, "server", box))).status, 400); + assert.equal((await send("POST", "/", { fromType: "dns_provider", fromId: 1, toType: "server", toId: box })).status, 400); + who = "viewer"; + assert.equal((await send("POST", "/", edge("server", other, "server", box))).status, 403); + assert.equal((await send("GET", "/")).status, 200, "everyone signed in can look"); + who = "operator"; + }); + + test("when the server is down and both services are failing, only the server is announced; the services are held back under it", async () => { + await trackIntegrationHealth("gitea", false); + await trackIntegrationHealth("semaphore", false); + invalidateAlertsCache(); + const report = await getAlerts(true); + const offline = report.alerts.find((a) => a.category === "offline" && a.message.startsWith("box"))!; + assert.equal(offline.silenced, false); + assert.deepEqual(offline.affects, ["Gitea", "Semaphore"]); + const failing = report.alerts.filter((a) => a.category === "integration"); + assert.equal(failing.length, 2); + for (const f of failing) { + assert.deepEqual(f.causedBy, { name: "box" }); + assert.equal(f.silenced, true); + } + assert.equal(failing.find((f) => f.id.includes("gitea"))!.affects, undefined, "only the root says what it takes with it"); + assert.equal(report.counts.critical + report.counts.warning, 1); + assert.equal(report.counts.grouped, 2); + }); + + test("when the server is back, Gitea stands alone and Semaphore is held back under Gitea", async () => { + await db.update(servers).set({ lastSeenAt: new Date().toISOString() }).where(eq(servers.id, box)); + invalidateAlertsCache(); + const report = await getAlerts(true); + const failing = report.alerts.filter((a) => a.category === "integration"); + assert.equal(failing.find((f) => f.id.includes("gitea"))!.causedBy, undefined); + assert.deepEqual(failing.find((f) => f.id.includes("semaphore"))!.causedBy, { name: "Gitea" }); + }); + + test("a kind of service is folded only if every enabled instance of it is explained", async () => { + const [second] = await db.insert(integrations).values({ type: "gitea", name: "Gitea 2", baseUrl: "https://git2.lab", config: "{}" }).returning({ id: integrations.id }); + await db.update(servers).set({ lastSeenAt: new Date(Date.now() - 3 * 3600_000).toISOString() }).where(eq(servers.id, box)); + invalidateAlertsCache(); + const report = await getAlerts(true); + assert.equal(report.alerts.find((a) => a.category === "integration" && a.id.includes("gitea"))!.causedBy, undefined, "the second one doesn't need the box"); + await db.delete(integrations).where(eq(integrations.id, second.id)); + }); + + test("a failure that crosses its threshold while the server it needs is down isn't announced; one that doesn't need it is", async () => { + assert.equal(await integrationCausedBy("gitea", ["gitea"]), null, "nothing is known to be down yet"); + await setInternalFlag(HEALTH_STATE_FLAG, JSON.stringify({ [`offline:server:${box}`]: { message: "box is offline", source: "server" } })); + assert.deepEqual(await integrationCausedBy("gitea", ["gitea"]), { key: `server:${box}`, name: "box" }); + assert.deepEqual(await integrationCausedBy("semaphore", ["gitea", "semaphore"]), { key: `server:${box}`, name: "box" }, "through Gitea"); + assert.equal(await integrationCausedBy("tailscale", ["tailscale"]), null, "an unrelated kind"); + await setInternalFlag(HEALTH_STATE_FLAG, JSON.stringify({ [`offline:server:${other}`]: { message: "other is offline", source: "server" } })); + assert.equal(await integrationCausedBy("gitea", ["gitea"]), null, "a different server being down explains nothing"); + }); + + test("removing one works, is audited, and the services stand alone again", async () => { + assert.equal((await send("DELETE", `/${firstId}`)).status, 204); + assert.equal((await send("DELETE", `/${firstId}`)).status, 404); + const actions = (await db.select().from(auditLog)).filter((e) => e.category === "dependency").map((e) => e.action); + assert.deepEqual(actions.sort(), ["create", "create", "delete"]); + invalidateAlertsCache(); + const report = await getAlerts(true); + assert.equal(report.alerts.find((a) => a.category === "integration" && a.id.includes("gitea"))!.causedBy, undefined); + }); +}); diff --git a/server/test/inventoryAutofill.test.ts b/server/test/inventoryAutofill.test.ts new file mode 100644 index 0000000..bd15aee --- /dev/null +++ b/server/test/inventoryAutofill.test.ts @@ -0,0 +1,149 @@ +/** + * Filling in the inventory from what an agent says the machine is: only blanks are filled, a refresh overwrites on purpose, and an agent's + * report fills the entries of the machine it came from. + * + * 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-invfill-")); +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, assets, auditLog } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const { inventoryRouter } = await import("../src/routes/inventory.js"); +const { agentReportRouter } = await import("../src/routes/agentReport.js"); +const { hashToken } = await import("../src/services/tokens.js"); +const { blanksToFill, differences, hardwareOf } = await import("../src/services/inventoryAutofill.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); + +describe("what would be filled, and what would change", () => { + const hw = { manufacturer: "Dell Inc.", model: "PowerEdge R730", serial: "ABC123" }; + + test("only blank fields are filled; what a person wrote stays", () => { + assert.deepEqual(blanksToFill({ manufacturer: null, model: "R730 (mine)", serial: " " }, hw), { manufacturer: "Dell Inc.", serial: "ABC123" }); + assert.deepEqual(blanksToFill({ manufacturer: "x", model: "y", serial: "z" }, hw), {}); + assert.deepEqual(blanksToFill({ manufacturer: null, model: null, serial: null }, null), {}); + assert.deepEqual(blanksToFill({ manufacturer: null, model: null, serial: null }, { manufacturer: "Dell", model: null, serial: null }), { manufacturer: "Dell" }); + }); + + test("a refresh would change the fields where the agent says something else, and nothing that already matches", () => { + assert.deepEqual(differences({ manufacturer: "Dell Inc.", model: "R730", serial: null }, hw), { model: "PowerEdge R730", serial: "ABC123" }); + assert.deepEqual(differences(hw, hw), {}); + assert.deepEqual(differences({ manufacturer: "Dell Inc. ", model: "PowerEdge R730", serial: "ABC123" }, hw), {}, "stray spaces aren't a difference"); + assert.deepEqual(differences({ manufacturer: "x", model: "y", serial: "z" }, { manufacturer: null, model: null, serial: null }), {}, "an agent that says nothing changes nothing"); + }); + + test("a server that has said nothing has no hardware", () => { + assert.equal(hardwareOf(null), null); + assert.equal(hardwareOf({ hwManufacturer: null, hwModel: null, hwSerial: null }), null); + assert.deepEqual(hardwareOf({ hwManufacturer: "A", hwModel: null, hwSerial: null }), { manufacturer: "A", model: null, serial: null }); + }); +}); + +describe("through the routes and the agent's report", () => { + let app: Server; + let base = ""; + let id = 0; + + before(async () => { + await db.insert(users).values([{ oidcSub: "operator", name: "Olle", role: "operator" }]); + const [s] = await db.insert(servers).values({ name: "elsa", apiTokenHash: hashToken("tok"), apiTokenPrefix: "t" }).returning(); + id = s.id; + const a = express(); + a.use("/api/agent/report", agentReportRouter); + a.use(express.json()); + a.use((req, _res, next) => { + (req as unknown as { session: unknown }).session = { user: { sub: "operator" } }; + next(); + }); + a.use("/api/inventory", inventoryRouter); + app = await new Promise((resolve) => { + const x = a.listen(0, "127.0.0.1", () => resolve(x)); + }); + base = `http://127.0.0.1:${(app.address() as AddressInfo).port}/api`; + }); + + after(() => { + app.close(); + try { + rmSync(dir, { recursive: true, force: true }); + } catch { + // Windows keeps the database file locked until the process exits. + } + }); + + const report = (hardware: unknown) => + fetch(`${base}/agent/report`, { method: "POST", headers: { "content-type": "application/json", authorization: "Bearer tok" }, body: JSON.stringify({ hostname: "h", os_type: "linux", tasks: [], system: { hardware } }) }); + const send = (method: string, path: string, body?: unknown) => + fetch(`${base}/inventory${path}`, { method, headers: { "content-type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) }); + const entry = async (assetId: number) => (await db.select().from(assets).where(eq(assets.id, assetId)))[0]; + + let linked = 0; + let unlinked = 0; + + test("an entry made before the agent has said anything stays blank, then an agent's report fills it", async () => { + linked = (await (await send("POST", "/", { name: "elsa's box", kind: "server", serverId: id, model: "my own words" })).json()).asset.id; + unlinked = (await (await send("POST", "/", { name: "a switch", kind: "network" })).json()).asset.id; + assert.deepEqual([(await entry(linked)).manufacturer, (await entry(linked)).serial], [null, null]); + + assert.equal((await report({ manufacturer: "Dell Inc.", model: "PowerEdge R730", serial: "ABC123" })).status, 202); + const row = await entry(linked); + assert.deepEqual([row.manufacturer, row.model, row.serial], ["Dell Inc.", "my own words", "ABC123"], "blanks filled, the model a person wrote is kept"); + const [s] = await db.select().from(servers).where(eq(servers.id, id)); + assert.deepEqual([s.hwManufacturer, s.hwModel, s.hwSerial], ["Dell Inc.", "PowerEdge R730", "ABC123"]); + assert.equal((await entry(unlinked)).manufacturer, null, "an entry that isn't this machine is left alone"); + }); + + test("the list shows what the agent says and what a refresh would change", async () => { + const list = (await (await send("GET", "/")).json()).assets; + const a = list.find((x: { id: number }) => x.id === linked); + assert.deepEqual(a.agent, { manufacturer: "Dell Inc.", model: "PowerEdge R730", serial: "ABC123", differs: { model: "PowerEdge R730" } }); + assert.equal(list.find((x: { id: number }) => x.id === unlinked).agent, null); + }); + + test("a new entry linked to a machine that has already reported starts out filled in", async () => { + const made = (await (await send("POST", "/", { name: "elsa again", kind: "server", serverId: id })).json()).asset; + assert.deepEqual([made.manufacturer, made.model, made.serial], ["Dell Inc.", "PowerEdge R730", "ABC123"]); + const edited = (await (await send("PUT", `/${unlinked}`, { name: "a switch", kind: "network", serverId: id })).json()).asset; + assert.equal(edited.serial, "ABC123", "linking an existing entry fills its blanks too"); + }); + + test("a report with nothing in it, or garbage, changes nothing", async () => { + assert.equal((await report({ manufacturer: " " })).status, 202); + assert.equal((await report("nonsense")).status, 202); + const [s] = await db.select().from(servers).where(eq(servers.id, id)); + assert.equal(s.hwSerial, "ABC123"); + }); + + test("refreshing from the agent overwrites on purpose, says what changed, and is in the audit log", async () => { + const res = await send("POST", `/${linked}/refresh-from-agent`); + assert.equal(res.status, 200); + const body = await res.json(); + assert.deepEqual(body.changed, ["model"]); + assert.equal(body.asset.model, "PowerEdge R730"); + const again = await (await send("POST", `/${linked}/refresh-from-agent`)).json(); + assert.deepEqual(again.changed, [], "nothing left to change"); + const log = (await db.select().from(auditLog)).filter((e) => e.action === "refresh_from_agent"); + assert.equal(log.length, 1, "only a refresh that changed something is recorded"); + }); + + test("an entry without a server, or one that isn't there, can't be refreshed", async () => { + const lone = (await (await send("POST", "/", { name: "a shelf", kind: "other" })).json()).asset.id; + assert.equal((await send("POST", `/${lone}/refresh-from-agent`)).status, 400); + assert.equal((await send("POST", "/99999/refresh-from-agent")).status, 404); + }); +}); diff --git a/server/test/webPush.test.ts b/server/test/webPush.test.ts new file mode 100644 index 0000000..33b8d6b --- /dev/null +++ b/server/test/webPush.test.ts @@ -0,0 +1,292 @@ +/** + * Web Push: the encryption against the standard's own worked example, the signed token, the routes, and a message all the way to a stand-in push + * service and back out through a stand-in browser. + * + * Run with: npm test --workspace server + */ +import { test, describe, before, after } from "node:test"; +import assert from "node:assert/strict"; +import { createDecipheriv, createECDH, createPublicKey, hkdfSync, verify } from "node:crypto"; +import { createServer, type IncomingMessage, type Server } from "node:http"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import type { AddressInfo } from "node:net"; + +const dir = mkdtempSync(join(tmpdir(), "hm-push-")); +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, pushSubscriptions, auditLog } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const { encryptPayload, vapidAuthorization, getVapidKeys, checkEndpoint, allowLocalPushEndpointsForTests, sendPush } = await import("../src/services/webPush.js"); +const { updateSettings } = await import("../src/services/settingsStore.js"); +const { notifyNow, enabledChannelCount } = await import("../src/services/notify.js"); +const { pushRouter } = await import("../src/routes/push.js"); +const { eq } = await import("drizzle-orm"); + +await runMigrations(); + +const b64u = (s: string) => Buffer.from(s, "base64url"); + +/** What a browser does with a push it receives (RFC 8291 §3.4), to read what we wrote. */ +function decrypt(body: Buffer, uaPrivate: Buffer, uaPublic: Buffer, authSecret: Buffer): Buffer { + const salt = body.subarray(0, 16); + const idlen = body[20]; + const asPublic = body.subarray(21, 21 + idlen); + const ciphertext = body.subarray(21 + idlen); + const ecdh = createECDH("prime256v1"); + ecdh.setPrivateKey(uaPrivate); + const secret = ecdh.computeSecret(asPublic); + const ikm = Buffer.from(hkdfSync("sha256", secret, authSecret, Buffer.concat([Buffer.from("WebPush: info\0"), uaPublic, asPublic]), 32)); + const cek = Buffer.from(hkdfSync("sha256", ikm, salt, Buffer.from("Content-Encoding: aes128gcm\0"), 16)); + const nonce = Buffer.from(hkdfSync("sha256", ikm, salt, Buffer.from("Content-Encoding: nonce\0"), 12)); + const d = createDecipheriv("aes-128-gcm", cek, nonce); + d.setAuthTag(ciphertext.subarray(ciphertext.length - 16)); + const plain = Buffer.concat([d.update(ciphertext.subarray(0, ciphertext.length - 16)), d.final()]); + assert.equal(plain[plain.length - 1], 2, "ends with the last-record marker"); + return plain.subarray(0, plain.length - 1); +} + +/** A stand-in browser: its keys, in the shape a subscription carries them. */ +function browser() { + const ecdh = createECDH("prime256v1"); + ecdh.generateKeys(); + const auth = Buffer.from(Array.from({ length: 16 }, (_, i) => i * 7 + 3)); + return { ecdh, priv: ecdh.getPrivateKey(), pub: ecdh.getPublicKey(), auth, keys: { p256dh: ecdh.getPublicKey().toString("base64url"), auth: auth.toString("base64url") } }; +} + +describe("the encryption", () => { + test("it reproduces the worked example in RFC 8291, byte for byte", () => { + const asPrivate = b64u("yfWPiYE-n46HLnH0KqZOF1fJJU3MYrct3AELtAQ-oRw"); + const ephemeral = createECDH("prime256v1"); + ephemeral.setPrivateKey(asPrivate); + assert.equal(ephemeral.getPublicKey().toString("base64url"), "BP4z9KsN6nGRTbVYI_c7VJSPQTBtkgcy27mlmlMoZIIgDll6e3vCYLocInmYWAmS6TlzAC8wEqKK6PBru3jl7A8"); + const body = encryptPayload( + Buffer.from("When I grow up, I want to be a watermelon"), + { p256dh: "BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4", auth: "BTBZMqHH6r4Tts7J_aSIgg" }, + { ephemeral, salt: b64u("DGv6ra1nlYgDCS1FRnbzlw") }, + ); + assert.equal( + body.toString("base64url"), + "DGv6ra1nlYgDCS1FRnbzlwAAEABBBP4z9KsN6nGRTbVYI_c7VJSPQTBtkgcy27mlmlMoZIIgDll6e3vCYLocInmYWAmS6TlzAC8wEqKK6PBru3jl7A_yl95bQpu6cVPTpK4Mqgkf1CXztLVBSt2Ks3oZwbuwXPXLWyouBWLVWGNWQexSgSxsj_Qulcy4a-fN", + ); + }); + + test("the browser it is for can read it, and it is different every time", () => { + const b = browser(); + const one = encryptPayload(Buffer.from("hello"), b.keys); + const two = encryptPayload(Buffer.from("hello"), b.keys); + assert.notDeepEqual(one, two, "a fresh key and salt each time"); + assert.equal(decrypt(one, b.priv, b.pub, b.auth).toString(), "hello"); + const other = browser(); + assert.throws(() => decrypt(one, other.priv, other.pub, other.auth), "someone else's browser can't"); + }); + + test("keys that aren't a browser's, or a message too long for one push, are refused", () => { + const b = browser(); + assert.throws(() => encryptPayload(Buffer.from("x"), { p256dh: "AAAA", auth: b.keys.auth }), /P-256/); + assert.throws(() => encryptPayload(Buffer.from("x"), { p256dh: b.keys.p256dh, auth: "AAAA" }), /16 bytes/); + assert.throws(() => encryptPayload(Buffer.alloc(4100), b.keys), /too long/); + }); +}); + +describe("the signed token", () => { + test("it names who it is for, who sent it and when it ends, and the signature checks out against the public key", async () => { + const keys = await getVapidKeys(); + const header = vapidAuthorization("https://push.example", "mailto:me@example.com", keys, 1_700_000_000_000); + const m = /^vapid t=([\w-]+)\.([\w-]+)\.([\w-]+), k=([\w-]+)$/.exec(header)!; + assert.ok(m, header); + assert.equal(m[4], keys.publicKey); + assert.deepEqual(JSON.parse(Buffer.from(m[1], "base64url").toString()), { typ: "JWT", alg: "ES256" }); + assert.deepEqual(JSON.parse(Buffer.from(m[2], "base64url").toString()), { aud: "https://push.example", exp: 1_700_000_000 + 12 * 3600, sub: "mailto:me@example.com" }); + const pub = b64u(keys.publicKey); + const key = createPublicKey({ key: { kty: "EC", crv: "P-256", x: pub.subarray(1, 33).toString("base64url"), y: pub.subarray(33, 65).toString("base64url") }, format: "jwk" }); + assert.equal(verify("sha256", Buffer.from(`${m[1]}.${m[2]}`), { key, dsaEncoding: "ieee-p1363" }, b64u(m[3])), true); + assert.equal(b64u(m[3]).length, 64, "the signature is the plain r and s, as JWT wants"); + }); + + test("the server's key pair is kept: the same one comes back", async () => { + const a = await getVapidKeys(); + const b = await getVapidKeys(); + assert.deepEqual(a, b); + assert.equal(b64u(a.publicKey).length, 65); + assert.equal(b64u(a.privateKey).length, 32); + }); +}); + +describe("which addresses are push services", () => { + test("https only, no login, and never an address on a private network", async () => { + await assert.rejects(checkEndpoint("http://fcm.googleapis.com/x"), /https/); + await assert.rejects(checkEndpoint("https://user:pw@fcm.googleapis.com/x"), /login/); + await assert.rejects(checkEndpoint("not a url"), /web address/); + await assert.rejects(checkEndpoint("https://127.0.0.1/x")); + await assert.rejects(checkEndpoint("https://192.168.1.10/x")); + await assert.rejects(checkEndpoint("https://169.254.169.254/latest")); + await assert.rejects(checkEndpoint("https://localhost/x")); + }); +}); + +describe("through the routes, the channel and a push service", () => { + let app: Server; + let base = ""; + let who = "ada"; + let pushService: Server; + let pushBase = ""; + const received: { path: string; headers: IncomingMessage["headers"]; body: Buffer }[] = []; + let respondWith = 201; + let ada = 0; + + before(async () => { + allowLocalPushEndpointsForTests(true); + const made = await db + .insert(users) + .values([ + { oidcSub: "ada", name: "Ada", role: "admin" }, + { oidcSub: "vic", name: "Vic", role: "viewer" }, + ]) + .returning({ id: users.id }); + ada = made[0].id; + pushService = createServer((req, res) => { + const chunks: Buffer[] = []; + req.on("data", (c) => chunks.push(c)); + req.on("end", () => { + received.push({ path: req.url ?? "", headers: req.headers, body: Buffer.concat(chunks) }); + res.statusCode = respondWith; + res.end(); + }); + }); + await new Promise((r) => pushService.listen(0, "127.0.0.1", r)); + pushBase = `http://127.0.0.1:${(pushService.address() as AddressInfo).port}`; + + const a = express(); + a.use(express.json()); + a.use((req, _res, next) => { + (req as unknown as { session: unknown }).session = { user: { sub: who } }; + next(); + }); + a.use("/api/push", pushRouter); + 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/push`; + }); + + after(() => { + allowLocalPushEndpointsForTests(false); + app.close(); + pushService.close(); + try { + rmSync(dir, { recursive: true, force: true }); + } catch { + // Windows keeps the database file locked until the process exits. + } + }); + + const send = (method: string, path: string, body?: unknown) => fetch(`${base}${path}`, { method, headers: { "content-type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) }); + const mine = browser(); + const vics = browser(); + let adaSubId = 0; + + test("while push is off nobody can subscribe, and there is no key to subscribe with", async () => { + assert.equal((await send("GET", "/key")).status, 409); + assert.equal((await send("POST", "/subscribe", { endpoint: `${pushBase}/a`, keys: mine.keys })).status, 409); + assert.equal(await enabledChannelCount(), 0); + }); + + test("with it on, a browser gets the key and subscribes; the same browser again is the same subscription", async () => { + await updateSettings({ webPush: { enabled: true, contact: "me@example.com" } }); + const key = await (await send("GET", "/key")).json(); + assert.equal(key.publicKey, (await getVapidKeys()).publicKey); + const res = await send("POST", "/subscribe", { endpoint: `${pushBase}/ada-phone`, keys: mine.keys, label: "Ada's phone" }); + assert.equal(res.status, 201); + adaSubId = (await res.json()).id; + assert.equal((await send("POST", "/subscribe", { endpoint: `${pushBase}/ada-phone`, keys: mine.keys, label: "Ada's phone" })).status, 201); + assert.equal((await db.select().from(pushSubscriptions)).length, 1); + const list = await (await send("GET", "/mine")).json(); + assert.equal(list.subscriptions.length, 1); + assert.equal(list.subscriptions[0].label, "Ada's phone"); + assert.equal((await db.select().from(auditLog)).filter((e) => e.category === "push" && e.action === "subscribe").length, 1, "only the first time"); + }); + + test("a subscription that isn't one is refused", async () => { + assert.equal((await send("POST", "/subscribe", { endpoint: "nonsense", keys: mine.keys })).status, 400); + assert.equal((await send("POST", "/subscribe", { endpoint: `${pushBase}/x`, keys: { p256dh: "short", auth: "short" } })).status, 400); + allowLocalPushEndpointsForTests(false); + const refused = await send("POST", "/subscribe", { endpoint: "https://10.0.0.5/push", keys: mine.keys }); + allowLocalPushEndpointsForTests(true); + assert.equal(refused.status, 400, "a private address is never a push service"); + }); + + test("a message through the channels is encrypted for the browser, signed, and addressed to the push service", async () => { + received.length = 0; + assert.equal(await enabledChannelCount(), 1, "push counts as a channel once someone is subscribed"); + await notifyNow("Server down", "elsa has not reported for 3 hours"); + assert.equal(received.length, 1); + const r = received[0]; + assert.equal(r.path, "/ada-phone"); + assert.equal(r.headers["content-encoding"], "aes128gcm"); + assert.equal(r.headers.ttl, "86400"); + assert.match(String(r.headers.authorization), /^vapid t=[\w-]+\.[\w-]+\.[\w-]+, k=[\w-]+$/); + const claims = JSON.parse(Buffer.from(String(r.headers.authorization).split(".")[1], "base64url").toString()); + assert.equal(claims.aud, pushBase); + assert.equal(claims.sub, "mailto:me@example.com"); + const message = JSON.parse(decrypt(r.body, mine.priv, mine.pub, mine.auth).toString()); + assert.deepEqual(message, { title: "Server down", body: "elsa has not reported for 3 hours", url: "/alerts" }); + assert.notEqual((await db.select().from(pushSubscriptions))[0].lastSuccessAt, null); + }); + + test("with push switched off nothing is sent", async () => { + await updateSettings({ webPush: { enabled: false } }); + received.length = 0; + await notifyNow("Server down", "x"); + assert.equal(received.length, 0); + await updateSettings({ webPush: { enabled: true } }); + }); + + test("a push service that says the browser is gone has that subscription removed; one that is merely failing keeps it", async () => { + const rows = await db.select().from(pushSubscriptions); + respondWith = 500; + assert.deepEqual(await sendPush({ title: "t", body: "b" }, rows), { sent: 0, removed: 0, failed: 1 }); + assert.equal((await db.select().from(pushSubscriptions)).length, 1); + respondWith = 410; + assert.deepEqual(await sendPush({ title: "t", body: "b" }, rows), { sent: 0, removed: 1, failed: 0 }); + assert.equal((await db.select().from(pushSubscriptions)).length, 0); + respondWith = 201; + }); + + test("the test button writes to this person's own browsers only", async () => { + assert.equal((await send("POST", "/test")).status, 400, "nothing subscribed now"); + await send("POST", "/subscribe", { endpoint: `${pushBase}/ada-phone`, keys: mine.keys }); + who = "vic"; + await send("POST", "/subscribe", { endpoint: `${pushBase}/vic-laptop`, keys: vics.keys }); + received.length = 0; + const res = await send("POST", "/test"); + assert.deepEqual(await res.json(), { sent: 1, removed: 0, failed: 0 }); + assert.deepEqual(received.map((r) => r.path), ["/vic-laptop"]); + assert.equal(JSON.parse(decrypt(received[0].body, vics.priv, vics.pub, vics.auth).toString()).title, "Homelab Manager — Test"); + }); + + test("a person removes their own browsers, not someone else's; an administrator can remove anyone's", async () => { + const all = await db.select().from(pushSubscriptions); + const adas = all.find((s) => s.userId === ada)!; + const vicsRow = all.find((s) => s.userId !== ada)!; + who = "vic"; + assert.equal((await send("DELETE", `/${adas.id}`)).status, 404, "not found, rather than 'not yours'"); + assert.equal((await send("DELETE", `/${vicsRow.id}`)).status, 204); + who = "ada"; + await send("POST", "/subscribe", { endpoint: `${pushBase}/vic-laptop`, keys: vics.keys }); + who = "vic"; + assert.equal((await send("POST", "/subscribe", { endpoint: `${pushBase}/vic-laptop`, keys: vics.keys })).status, 201, "taking a browser over makes it theirs"); + who = "ada"; + const taken = (await db.select().from(pushSubscriptions)).find((s) => s.endpoint.endsWith("/vic-laptop"))!; + assert.equal((await send("DELETE", `/${taken.id}`)).status, 204, "an administrator may"); + assert.ok(adaSubId > 0); + assert.equal((await db.select().from(auditLog)).filter((e) => e.category === "push" && e.action === "unsubscribe").length, 2); + assert.equal((await db.select().from(pushSubscriptions).where(eq(pushSubscriptions.userId, ada))).length, 1); + }); +}); diff --git a/server/test/windowsAgentHealth.test.ts b/server/test/windowsAgentHealth.test.ts new file mode 100644 index 0000000..6ac6528 --- /dev/null +++ b/server/test/windowsAgentHealth.test.ts @@ -0,0 +1,126 @@ +/** + * What the Windows agent says about the machine: services that have failed, each disk's health, Storage Spaces pools and what the machine + * is. The mapping from what Windows returns is tested with stand-in objects, and the real collectors are run once as a smoke test. + * + * Run with: npm test --workspace server + */ +import { test, describe } from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { spawnSync } from "node:child_process"; + +const repoRoot = join(dirname(fileURLToPath(import.meta.url)), "..", ".."); +const script = join(repoRoot, "agent", "windows", "report-tasks.ps1"); +const probe = process.platform === "win32" ? spawnSync("pwsh", ["-NoProfile", "-Command", "$PSVersionTable.PSVersion.Major"], { encoding: "utf8" }) : null; +const havePwsh = probe?.status === 0; + +/** Runs PowerShell with the agent script loaded (without running it) and returns what the snippet printed as JSON. */ +function run(snippet: string): unknown { + const work = mkdtempSync(join(tmpdir(), "hm-winhealth-")); + try { + const file = join(work, "t.ps1"); + writeFileSync(file, `$ErrorActionPreference = 'Stop'\n. '${script.replace(/'/g, "''")}'\n${snippet}\n`); + const r = spawnSync("pwsh", ["-NoProfile", "-NonInteractive", "-File", file], { encoding: "utf8" }); + assert.equal(r.stderr.trim(), "", `PowerShell said:\n${r.stderr}\n${r.stdout}`); + return JSON.parse(r.stdout.trim()); + } finally { + rmSync(work, { recursive: true, force: true }); + } +} + +describe("the Windows agent's health parts", { skip: !havePwsh }, () => { + test("it says it is version 4, and stays plain ASCII", () => { + const text = readFileSync(script, "utf8"); + assert.match(text, /^\$script:AgentVersion = 4\s*$/m); + assert.ok(!/[^\x00-\x7f]/.test(text)); + }); + + test("a service has failed when it starts by itself, isn't running, and stopped with an error — not for exit 0, never-started, or on request", () => { + const out = run(` + function svc($n, $d, $mode, $state, $code) { [pscustomobject]@{ Name = $n; DisplayName = $d; StartMode = $mode; State = $state; ExitCode = $code } } + $list = @( + (svc 'Crashed' 'A crashed service' 'Auto' 'Stopped' 1066), + (svc 'Crashed2' 'Another' 'Auto' 'Stopped' 2), + (svc 'Finished' 'Did its job' 'Auto' 'Stopped' 0), + (svc 'Triggered' 'Starts on a trigger' 'Auto' 'Stopped' 1077), + (svc 'OnRequest' 'Manual one' 'Manual' 'Stopped' 1066), + (svc 'Disabled' 'Disabled one' 'Disabled' 'Stopped' 1066), + (svc 'Fine' 'Running' 'Auto' 'Running' 0), + (svc 'Starting' 'On its way' 'Auto' 'Start Pending' 1066), + (svc 'gupdate' 'Google Update' 'Auto' 'Stopped' 1), + (svc 'NoCode' 'No code at all' 'Auto' 'Stopped' $null) + ) + ConvertTo-Json -InputObject @{ all = @(ConvertTo-FailedUnits $list); ignoring = @(ConvertTo-FailedUnits $list @('gupdate*', 'Crashed2')); none = @(ConvertTo-FailedUnits @()) } -Compress + `) as { all: { unit: string; description: string }[]; ignoring: { unit: string }[]; none: unknown[] }; + assert.deepEqual(out.all.map((u) => u.unit), ["Crashed", "Crashed2", "gupdate"]); + assert.equal(out.all[0].description, "A crashed service"); + assert.deepEqual(out.ignoring.map((u) => u.unit), ["Crashed"], "names and patterns in the ignore list are left out"); + assert.deepEqual(out.none, []); + }); + + test("a disk passes when Windows says Healthy; Warning and Unhealthy don't; Unknown says nothing; temperature and wear come from the counter where sane", () => { + const out = run(` + function disk($id, $name, $health, $bus = 'SATA') { [pscustomobject]@{ DeviceId = $id; FriendlyName = $name; HealthStatus = $health; BusType = $bus } } + $disks = @( + (disk '0' ' Samsung SSD 850 ' 'Healthy'), + (disk '1' 'Old HDD' 'Warning'), + (disk '2' 'Dead HDD' 'Unhealthy'), + (disk '3' 'Mystery' 'Unknown'), + (disk '4' 'NVMe' 'Healthy' 'NVMe'), + (disk '5' 'Virtual' 'Healthy' 'File Backed Virtual'), + (disk '6' 'Odd readings' 'Healthy') + ) + $counters = @{ + '0' = [pscustomobject]@{ Temperature = 36; Wear = 7 } + '4' = [pscustomobject]@{ Temperature = 0; Wear = 0 } + '6' = [pscustomobject]@{ Temperature = 4000; Wear = 900 } + } + ConvertTo-Json -InputObject @(ConvertTo-DiskHealth $disks $counters) -Compress + `) as { device: string; model: string; healthy: boolean | null; temperature_c: number | null; wear_percent: number | null }[]; + const byDevice = Object.fromEntries(out.map((d) => [d.device, d])); + assert.deepEqual(Object.keys(byDevice), ["PhysicalDisk0", "PhysicalDisk1", "PhysicalDisk2", "PhysicalDisk3", "PhysicalDisk4", "PhysicalDisk6"], "the virtual disk is left out"); + assert.deepEqual([byDevice.PhysicalDisk0.healthy, byDevice.PhysicalDisk1.healthy, byDevice.PhysicalDisk2.healthy, byDevice.PhysicalDisk3.healthy], [true, false, false, null]); + assert.equal(byDevice.PhysicalDisk0.model, "Samsung SSD 850", "names are trimmed"); + assert.deepEqual([byDevice.PhysicalDisk0.temperature_c, byDevice.PhysicalDisk0.wear_percent], [36, 7]); + assert.deepEqual([byDevice.PhysicalDisk4.temperature_c, byDevice.PhysicalDisk4.wear_percent], [null, 0], "0 degrees isn't a reading, 0% wear is"); + assert.deepEqual([byDevice.PhysicalDisk6.temperature_c, byDevice.PhysicalDisk6.wear_percent], [null, null], "nonsense is no reading"); + assert.deepEqual([byDevice.PhysicalDisk1.temperature_c, byDevice.PhysicalDisk1.wear_percent], [null, null], "a disk with no counter has none"); + }); + + test("Storage Spaces pools are reported in ZFS's words, with how full they are; one Windows can't judge is left out", () => { + const out = run(` + function pool($n, $h, $size, $alloc) { [pscustomobject]@{ FriendlyName = $n; HealthStatus = $h; Size = $size; AllocatedSize = $alloc } } + ConvertTo-Json -InputObject @(ConvertTo-PoolHealth @( + (pool 'Media' 'Healthy' 1000 250), + (pool 'Backups' 'Warning' 1000 900), + (pool 'Broken' 'Unhealthy' 0 0), + (pool 'Strange' 'Unknown' 1000 1) + )) -Compress + `) as { name: string; health: string; capacity_percent: number | null }[]; + assert.deepEqual(out.map((p) => [p.name, p.health, p.capacity_percent]), [["Media", "ONLINE", 25], ["Backups", "DEGRADED", 90], ["Broken", "FAULTED", null]]); + }); + + test("a maker's placeholders aren't a model or a serial number", () => { + const out = run(` + $t = @('To Be Filled By O.E.M.', 'Default string', 'System Serial Number', 'System Product Name', '0000000', ' ', 'None', 'Unknown', 'ASUS', 'ROG STRIX B560-F', 'PF2ABCDE', '0A1B') + ConvertTo-Json -InputObject @($t | ForEach-Object { Test-PlaceholderText $_ }) -Compress + `) as boolean[]; + assert.deepEqual(out, [true, true, true, true, true, true, true, true, false, false, false, false]); + }); + + test("on this machine the real collectors answer, in a shape the server reads, and one that can't be read is left out rather than reported well", () => { + const out = run(` + $health = Get-HostHealth @{ IgnoreServices = @() } + $hardware = Get-HardwareInfo + ConvertTo-Json -InputObject @{ health = $health; hardware = $hardware } -Depth 6 -Compress + `) as { health: { failed_units?: unknown[]; smart?: { device: string; healthy: boolean | null }[]; zfs?: unknown[] } | null; hardware: { manufacturer?: string; model?: string; serial?: string } | null }; + if (out.health) { + for (const part of ["failed_units", "smart", "zfs"] as const) if (out.health[part] !== undefined) assert.ok(Array.isArray(out.health[part]), `${part} is a list`); + for (const d of out.health.smart ?? []) assert.match(d.device, /^PhysicalDisk\d+$/); + } + if (out.hardware) for (const v of Object.values(out.hardware)) assert.ok(typeof v === "string" && v.length > 0 && v.length <= 150); + }); +}); diff --git a/server/test/windowsAgentUpdate.test.ts b/server/test/windowsAgentUpdate.test.ts index cd30d6b..8c9f74e 100644 --- a/server/test/windowsAgentUpdate.test.ts +++ b/server/test/windowsAgentUpdate.test.ts @@ -100,11 +100,12 @@ describe("the Windows agent updating itself", { skip: !havePwsh }, () => { test("a newer script that matches the checksum replaces the old one, and the token is sent only to the question", async () => { served = real(); - reply = { update: true, version: 3, sha256: sha(served) }; + const current = Number(/AgentVersion = (\d+)/.exec(served.toString())![1]); + reply = { update: true, version: current, sha256: sha(served) }; const out = await attempt(); assert.deepEqual(out.content, served, "the installed file is now the served script, byte for byte"); assert.deepEqual(out.leftovers, []); - assert.match(out.stderr, /Updated the agent from version 1 to version 3/); + assert.match(out.stderr, new RegExp(`Updated the agent from version 1 to version ${current}`)); const question = out.asked.find((l) => l.includes("/api/agent/report/update"))!; assert.match(question, /version=1/); assert.match(question, /auth=Bearer secret-token/); diff --git a/web/package.json b/web/package.json index 182d654..f49dec1 100644 --- a/web/package.json +++ b/web/package.json @@ -13,6 +13,7 @@ "@tabler/icons-react": "^3.46.0", "cron-parser": "^5.10.0", "cronstrue": "^2.53.0", + "qrcode-generator": "^2.0.4", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^7.1.1" diff --git a/web/public/sw.js b/web/public/sw.js index 12db9af..a6437bc 100644 --- a/web/public/sw.js +++ b/web/public/sw.js @@ -6,3 +6,38 @@ self.addEventListener("install", () => self.skipWaiting()); self.addEventListener("activate", (event) => event.waitUntil(self.clients.claim())); self.addEventListener("fetch", () => {}); + +// Push notifications (Settings > Notifications). The message arrives encrypted for this browser only and is read here; a tap opens the app +// at the page it names, reusing a window that is already open. +self.addEventListener("push", (event) => { + let data = {}; + try { + data = event.data ? event.data.json() : {}; + } catch { + data = { body: event.data ? event.data.text() : "" }; + } + event.waitUntil( + self.registration.showNotification(data.title || "Homelab Manager", { + body: data.body || "", + icon: "/icon-192.png", + badge: "/favicon-32.png", + tag: data.tag || undefined, + data: { url: typeof data.url === "string" && data.url.startsWith("/") ? data.url : "/alerts" }, + }), + ); +}); + +self.addEventListener("notificationclick", (event) => { + event.notification.close(); + const target = new URL((event.notification.data && event.notification.data.url) || "/alerts", self.location.origin).href; + event.waitUntil( + self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((windows) => { + for (const w of windows) { + if (new URL(w.url).origin === self.location.origin && "focus" in w) { + return w.focus().then(() => ("navigate" in w ? w.navigate(target) : undefined)); + } + } + return self.clients.openWindow(target); + }), + ); +}); diff --git a/web/src/App.tsx b/web/src/App.tsx index ef90b43..25a7e5c 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -32,6 +32,8 @@ import Updates from "./pages/Updates"; import Incidents from "./pages/Incidents"; import IncidentDetail from "./pages/IncidentDetail"; import Inventory from "./pages/Inventory"; +import InventoryLabels from "./pages/InventoryLabels"; +import Dependencies from "./pages/Dependencies"; import Backups from "./pages/Backups"; import Domains from "./pages/Domains"; import Consistency from "./pages/Consistency"; @@ -147,6 +149,8 @@ function Shelled({ user }: { user: CurrentUser }) { } /> } /> } /> + } /> + } /> } /> } /> } /> diff --git a/web/src/api/client.ts b/web/src/api/client.ts index 0a149d7..20a386d 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -409,6 +409,22 @@ export interface WebhookSettings { secret: string; } +export interface WebPushSettings { + enabled: boolean; + /** An email address or https address a push service can reach whoever runs this on. Blank is fine. */ + contact: string; +} + +/** A browser or phone that has asked for push notifications. */ +export interface PushDevice { + id: number; + label: string | null; + host: string; + endpoint: string; + createdAt: string; + lastSuccessAt: string | null; +} + export interface NotificationEvents { dnsAdd: boolean; dnsUpdate: boolean; @@ -473,6 +489,7 @@ export interface AppSettings { ntfy: NtfySettings; smtp: SmtpSettings; webhook: WebhookSettings; + webPush: WebPushSettings; notifications: NotificationEvents; providerColors: Record; integrationColors: Record; @@ -760,6 +777,21 @@ export interface BackupCoverage { export type AssetKind = "server" | "storage" | "network" | "power" | "client" | "other"; +export type DependencyNodeType = "server" | "integration"; +export interface DependencyNode { + key: string; + type: DependencyNodeType; + id: number; + name: string; +} +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 }[]; + /** The "runs on" links of servers, set on the server itself. */ + runsOn: { from: { key: string; name: string }; to: { key: string; name: string } }[]; + nodes: DependencyNode[]; +} + /** A piece of hardware in the inventory. */ export interface Asset { id: number; @@ -780,6 +812,8 @@ export interface Asset { updatedAt: string; /** The server it is, when it is one and that server still exists. */ server: { id: number; name: string } | null; + /** What that server's agent says the machine is, and the fields where that differs from what is written here. Null with no agent word. */ + agent: { manufacturer: string | null; model: string | null; serial: string | null; differs: { manufacturer?: string; model?: string; serial?: string } } | null; } /** What an entry is saved from: blank text and nulls mean "no value". */ @@ -1263,7 +1297,7 @@ export interface PrivacyOverview { tlsCertificateChecks: number; servers: number; serversWithAgent: number; - channels: Record<"gotify" | "ntfy" | "smtp" | "webhook", { enabled: boolean; host: string | null }>; + channels: Record<"gotify" | "ntfy" | "smtp" | "webhook" | "webPush", { enabled: boolean; host: string | null }>; }; } @@ -1651,11 +1685,24 @@ export const api = { backups: { coverage: (staleDays: number, refresh = false) => request(`/api/backups/coverage?staleDays=${staleDays}${refresh ? "&refresh=1" : ""}`), }, + push: { + key: () => request<{ publicKey: string }>("/api/push/key"), + mine: () => request<{ enabled: boolean; subscriptions: PushDevice[] }>("/api/push/mine"), + subscribe: (data: { endpoint: string; keys: { p256dh: string; auth: string }; label?: string }) => request<{ id: number }>("/api/push/subscribe", { method: "POST", body: JSON.stringify(data) }), + remove: (id: number) => request(`/api/push/${id}`, { method: "DELETE" }), + test: () => request<{ sent: number; removed: number; failed: number }>("/api/push/test", { method: "POST" }), + }, + dependencies: { + list: () => request("/api/dependencies"), + 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: { 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) }), remove: (id: number) => request(`/api/inventory/${id}`, { method: "DELETE" }), + refreshFromAgent: (id: number) => request<{ asset: Asset; changed: string[] }>(`/api/inventory/${id}/refresh-from-agent`, { method: "POST" }), setConfig: (data: InventoryConfig) => request<{ config: InventoryConfig }>("/api/inventory/config", { method: "PUT", body: JSON.stringify(data) }), }, runbooks: { diff --git a/web/src/components/HostHealthCard.tsx b/web/src/components/HostHealthCard.tsx index 025a219..1f7c512 100644 --- a/web/src/components/HostHealthCard.tsx +++ b/web/src/components/HostHealthCard.tsx @@ -6,7 +6,7 @@ const poolFine = (health: string) => health.toUpperCase() === "ONLINE"; /** * What the agent says about the machine itself: services that have failed, whether each disk's SMART check passes and how worn it is, and - * whether each ZFS pool is online. Each part appears only if the agent reported it (no smartctl or no ZFS on the host means no part), + * whether each storage pool (ZFS, or Storage Spaces on Windows) is online. Each part appears only if the agent reported it (no smartctl or no ZFS on the host means no part), * and the card is left out when it has nothing to say. */ export default function HostHealthCard({ health }: { health: HostHealth | null }) { @@ -88,7 +88,7 @@ export default function HostHealthCard({ health }: { health: HostHealth | null } {hasZfs && (
-
ZFS pools
+
Storage pools (ZFS or Storage Spaces)
diff --git a/web/src/components/PushDevices.tsx b/web/src/components/PushDevices.tsx new file mode 100644 index 0000000..59c3076 --- /dev/null +++ b/web/src/components/PushDevices.tsx @@ -0,0 +1,158 @@ +import { useCallback, useEffect, useState } from "react"; +import { api, type PushDevice } from "../api/client"; +import { readableError } from "../utils/errors"; +import { confirmDialog } from "../utils/dialogs"; +import { toast } from "../utils/toast"; + +const supported = typeof window !== "undefined" && "serviceWorker" in navigator && "PushManager" in window && "Notification" in window; + +/** The key as the bytes `subscribe` wants. */ +function keyBytes(base64url: string): Uint8Array { + const padded = base64url.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(base64url.length / 4) * 4, "="); + const raw = atob(padded); + const out = new Uint8Array(new ArrayBuffer(raw.length)); + for (let i = 0; i < raw.length; i++) out[i] = raw.charCodeAt(i); + return out; +} + +/** A short name for this browser, to tell the devices apart in the list. */ +function browserLabel(): string { + const ua = navigator.userAgent; + const browser = /Edg\//.test(ua) ? "Edge" : /Firefox\//.test(ua) ? "Firefox" : /Chrome\//.test(ua) ? "Chrome" : /Safari\//.test(ua) ? "Safari" : "Browser"; + const os = /Android/.test(ua) ? "Android" : /iPhone|iPad/.test(ua) ? "iOS" : /Windows/.test(ua) ? "Windows" : /Mac OS/.test(ua) ? "macOS" : /Linux/.test(ua) ? "Linux" : ""; + return os ? `${browser} on ${os}` : browser; +} + +async function registration(): Promise { + // (The production build registers the worker on load; a development server doesn't, so it is registered here if need be.) + if (!(await navigator.serviceWorker.getRegistration("/"))) await navigator.serviceWorker.register("/sw.js"); + return navigator.serviceWorker.ready; +} + +/** + * The browsers this person has asked to be notified on, and the button that makes this one of them. A browser can only be notified + * when the page is served over https (or from localhost), and has to be asked by a click, so it can't be done for anyone. + */ +export default function PushDevices({ serverEnabled }: { serverEnabled: boolean }) { + const [devices, setDevices] = useState(null); + const [thisEndpoint, setThisEndpoint] = useState(null); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(null); + const [permission, setPermission] = useState(supported ? Notification.permission : "denied"); + + const load = useCallback(async () => { + try { + setDevices((await api.push.mine()).subscriptions); + if (supported) { + const reg = await navigator.serviceWorker.getRegistration("/"); + setThisEndpoint((await reg?.pushManager.getSubscription())?.endpoint ?? null); + } + } catch (err) { + setError(readableError(err)); + } + }, []); + useEffect(() => { + void load(); + }, [load]); + + async function subscribe() { + setBusy(true); + setError(null); + try { + const { publicKey } = await api.push.key(); + const result = await Notification.requestPermission(); + setPermission(result); + if (result !== "granted") throw new Error("The browser wasn't allowed to show notifications. Allow them for this site in the browser's settings, then try again."); + const reg = await registration(); + // A subscription made for another key (the server's was made again) is no use: start over. + const existing = await reg.pushManager.getSubscription(); + if (existing) await existing.unsubscribe(); + const sub = await reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: keyBytes(publicKey) }); + const json = sub.toJSON(); + await api.push.subscribe({ endpoint: sub.endpoint, keys: { p256dh: json.keys?.p256dh ?? "", auth: json.keys?.auth ?? "" }, label: browserLabel() }); + toast.success("This browser will be notified."); + await load(); + } catch (err) { + setError(readableError(err)); + } finally { + setBusy(false); + } + } + + async function remove(d: PushDevice) { + if (!(await confirmDialog({ title: "Stop notifying a browser", message: `Stop sending notifications to ${d.label || d.host}?`, confirmLabel: "Stop", danger: true }))) return; + try { + await api.push.remove(d.id); + if (d.endpoint === thisEndpoint && supported) { + const reg = await navigator.serviceWorker.getRegistration("/"); + await (await reg?.pushManager.getSubscription())?.unsubscribe(); + } + await load(); + } catch (err) { + setError(readableError(err)); + } + } + + async function test() { + setBusy(true); + setError(null); + try { + const r = await api.push.test(); + if (r.sent > 0) toast.success(`Sent to ${r.sent} browser${r.sent === 1 ? "" : "s"}.`); + else setError("It could not be delivered. See the server's log for what the push service said."); + await load(); + } catch (err) { + setError(readableError(err)); + } finally { + setBusy(false); + } + } + + if (!serverEnabled) { + return
Switch this on and save, and then each person can add the browsers they want to be notified on.
; + } + + const secure = typeof window !== "undefined" && window.isSecureContext; + const thisSubscribed = thisEndpoint !== null && (devices ?? []).some((d) => d.endpoint === thisEndpoint); + + return ( +
+
Your browsers
+ {!supported || !secure ? ( +
+ This browser can’t receive push notifications here. {secure ? "It doesn't support them." : "They need the page to be opened over https (or from localhost)."} +
+ ) : ( +
+ {!thisSubscribed && ( + + )} + {(devices?.length ?? 0) > 0 && ( + + )} + {permission === "denied" && Notifications are blocked for this site in the browser.} +
+ )} + {error &&
{error}
} + {devices && devices.length === 0 &&
None yet.
} + {devices && devices.length > 0 && ( +
    + {devices.map((d) => ( +
  • + {d.label || d.host} + {d.endpoint === thisEndpoint && this browser} + via {d.host} + +
  • + ))} +
+ )} +
+ ); +} diff --git a/web/src/components/QrCode.tsx b/web/src/components/QrCode.tsx new file mode 100644 index 0000000..ada6d23 --- /dev/null +++ b/web/src/components/QrCode.tsx @@ -0,0 +1,29 @@ +import { useMemo } from "react"; +import qrcode from "qrcode-generator"; + +/** + * A QR code drawn as one SVG path, black on white with the quiet zone the scanners want. It takes its size from the box it is put in, and + * is made here in the browser: what it says never leaves the page. + */ +export default function QrCode({ text, label }: { text: string; label: string }) { + const { path, size } = useMemo(() => { + const qr = qrcode(0, "M"); + qr.addData(text); + qr.make(); + const n = qr.getModuleCount(); + let d = ""; + for (let r = 0; r < n; r++) { + for (let c = 0; c < n; c++) { + if (qr.isDark(r, c)) d += `M${c + 4} ${r + 4}h1v1h-1z`; + } + } + return { path: d, size: n + 8 }; + }, [text]); + + return ( + + + + + ); +} diff --git a/web/src/layout/nav.tsx b/web/src/layout/nav.tsx index 5d90a58..7adc696 100644 --- a/web/src/layout/nav.tsx +++ b/web/src/layout/nav.tsx @@ -25,6 +25,7 @@ import { IconRefresh, IconDownload, IconBox, + IconHierarchy2, IconShieldCheck, IconActivityHeartbeat, IconCopyCheck, @@ -76,6 +77,7 @@ export const NAV: NavEntry[] = [ { to: "/backups", label: "Backup coverage", icon: }, { to: "/map", label: "Map", icon: }, { to: "/inventory", label: "Inventory", icon: }, + { to: "/dependencies", label: "Dependencies", icon: }, ], }, { diff --git a/web/src/pages/Dashboard.tsx b/web/src/pages/Dashboard.tsx index 51a55a4..1eecb55 100644 --- a/web/src/pages/Dashboard.tsx +++ b/web/src/pages/Dashboard.tsx @@ -336,7 +336,7 @@ export default function Dashboard({ user }: { user: CurrentUser }) { .get() .then((res) => { const s = res.settings; - setNotifyConfigured(s.gotify.enabled || s.ntfy.enabled || s.smtp.enabled || s.webhook.enabled); + setNotifyConfigured(s.gotify.enabled || s.ntfy.enabled || s.smtp.enabled || s.webhook.enabled || !!s.webPush?.enabled); }) .catch(() => setNotifyConfigured(null)); api.users @@ -589,7 +589,7 @@ export default function Dashboard({ user }: { user: CurrentUser }) { { id: "server", title: "Add a server and install its agent", description: "The agent reports scheduled tasks, disks, memory and open ports, and lets the app tell when a server goes quiet.", to: "/servers", action: "Add a server", done: (serverSummary?.total ?? 0) > 0 }, { id: "dns", title: "Connect a DNS provider", description: "See your zones and records, and have names matched to servers.", to: "/dns", action: "Connect", done: (dnsStats?.totalProviders ?? 0) > 0 }, { id: "secret", title: "Track something that expires", description: "An API token, a certificate or a password — you're warned before it runs out.", to: "/secrets", action: "Add one", done: (secrets?.length ?? 0) > 0 }, - { id: "notify", title: "Choose how you'll be told about problems", description: "Gotify, ntfy, email or a webhook, with the checks you want.", to: "/settings/notifications", action: "Set up", done: notifyConfigured === true }, + { id: "notify", title: "Choose how you'll be told about problems", description: "Gotify, ntfy, email, a webhook or push to your phone, with the checks you want.", to: "/settings/notifications", action: "Set up", done: notifyConfigured === true }, { id: "people", title: "Let someone else in (optional)", description: "Others sign in with Authentik and appear under Users; you decide their role.", to: "/users", action: "Open Users", done: (userCount ?? 0) > 1 }, ]; diff --git a/web/src/pages/Dependencies.tsx b/web/src/pages/Dependencies.tsx new file mode 100644 index 0000000..816c382 --- /dev/null +++ b/web/src/pages/Dependencies.tsx @@ -0,0 +1,199 @@ +import { useEffect, useState } from "react"; +import { Link } from "react-router-dom"; +import { api, type CurrentUser, type DependenciesResponse, type DependencyNode } from "../api/client"; +import { ErrorNotice } from "../components/Notice"; +import { BlockSkeleton } from "../components/Skeleton"; +import { confirmDialog } from "../utils/dialogs"; +import { readableError } from "../utils/errors"; +import { toast } from "../utils/toast"; + +const TYPE_LABELS = { server: "Server", integration: "Integration" } as const; + +const linkTo = (type: string, id: number) => (type === "server" ? `/servers/${id}` : "/integrations"); + +/** The options of a node picker, grouped by what they are. */ +function NodeSelect({ id, label, nodes, value, onChange }: { id: string; label: string; nodes: DependencyNode[]; value: string; onChange: (key: string) => void }) { + return ( + <> + + + + ); +} + +/** + * What needs what. When something is down, whatever depends on it is down too, and only the one that matters should raise the alarm — so the + * alerts of the things that need it are folded under it, like a guest under its host. + */ +export default function Dependencies({ user }: { user: CurrentUser }) { + const canEdit = user.role === "admin" || user.role === "operator"; + const [data, setData] = useState(null); + const [error, setError] = useState(null); + const [from, setFrom] = useState(""); + const [to, setTo] = useState(""); + const [busy, setBusy] = useState(false); + + function load() { + api.dependencies + .list() + .then(setData) + .catch((err) => setError(readableError(err))); + } + useEffect(load, []); + + const parse = (key: string) => { + const [type, id] = key.split(":"); + return { type: type as "server" | "integration", id: Number(id) }; + }; + + async function add(e: React.FormEvent) { + e.preventDefault(); + if (!from || !to) return; + setBusy(true); + setError(null); + try { + const f = parse(from); + const t = parse(to); + await api.dependencies.create({ fromType: f.type, fromId: f.id, toType: t.type, toId: t.id }); + toast.success("Saved."); + setFrom(""); + setTo(""); + load(); + } catch (err) { + setError(readableError(err)); + } finally { + setBusy(false); + } + } + + async function remove(d: DependenciesResponse["dependencies"][number]) { + if (!(await confirmDialog({ title: "Remove a dependency", message: `${d.from.name} no longer needs ${d.to.name}?`, confirmLabel: "Remove", danger: true }))) return; + try { + await api.dependencies.remove(d.id); + load(); + } catch (err) { + setError(readableError(err)); + } + } + + return ( + <> +
+

Dependencies

+
+

+ Say what needs what: Gitea needs the server it is installed on; a Proxmox guest needs the Proxmox it runs on. When the thing that is needed is down, what needs it is down too — and its alert is + held back under the first one on the Alerts page instead of adding to the noise. A service that was down for its own reasons still alerts once what it needs is back. +

+ + + {canEdit && ( +
+
+

Add a dependency

+
+
+
+ +
+
+ n.key !== from)} value={to} onChange={setTo} /> +
+
+ +
+
+ + )} + +
+
+

Written here

+
+
+
+ + + + + {canEdit && } + + + + {data === null && !error && ( + + + + )} + {data?.dependencies.map((d) => ( + + + + {canEdit && ( + + )} + + ))} + {data && data.dependencies.length === 0 && ( + + + + )} + +
ThisneedsActions
+ +
+ {d.from.name} {TYPE_LABELS[d.from.type].toLowerCase()} + + {d.to.name} {TYPE_LABELS[d.to.type].toLowerCase()} + + +
+ Nothing written yet.{canEdit ? " Add the first above." : ""} +
+
+
+ + {data && data.runsOn.length > 0 && ( +
+
+

Servers that run on servers

+
+
These are set on each server (“runs on”), or worked out from the Proxmox node it is a guest of. They count here too.
+
+ + + {data.runsOn.map((r) => ( + ${r.to.key}`}> + + + + + ))} + +
{r.from.name}runs on{r.to.name}
+
+
+ )} + + ); +} diff --git a/web/src/pages/Inventory.tsx b/web/src/pages/Inventory.tsx index f6504f9..9d19eb5 100644 --- a/web/src/pages/Inventory.tsx +++ b/web/src/pages/Inventory.tsx @@ -102,6 +102,9 @@ export default function Inventory({ user }: { user: CurrentUser }) { const [params, setParams] = useSearchParams(); const kind = (KINDS as string[]).includes(params.get("kind") ?? "") ? (params.get("kind") as AssetKind) : ""; + // A scanned label comes here with ?asset=ID: that one piece of hardware is shown first. + const focusId = /^\d+$/.test(params.get("asset") ?? "") ? Number(params.get("asset")) : null; + const focused = focusId === null ? null : (assets ?? []).find((a) => a.id === focusId) ?? null; function load() { api.inventory @@ -158,6 +161,19 @@ export default function Inventory({ user }: { user: CurrentUser }) { } } + async function refreshFromAgent(a: Asset) { + const d = a.agent?.differs ?? {}; + const lines = (Object.keys(d) as (keyof typeof d)[]).map((k) => `${k}: "${a[k] ?? ""}" becomes "${d[k]}"`); + if (!(await confirmDialog({ title: "Take over what the agent says", message: `${a.name}: ${lines.join("; ")}.`, confirmLabel: "Replace" }))) return; + try { + await api.inventory.refreshFromAgent(a.id); + toast.success("Updated from the agent."); + load(); + } catch (err) { + setError(readableError(err)); + } + } + async function saveConfig(e: React.FormEvent) { e.preventDefault(); setError(null); @@ -180,6 +196,13 @@ export default function Inventory({ user }: { user: CurrentUser }) { ); } + // A name that is a server's name (or holds it) is probably that server. + const suggestion = (() => { + const n = draft?.name.trim().toLowerCase(); + if (!n) return null; + return servers.find((s) => s.name.toLowerCase() === n) ?? servers.find((s) => s.name.length >= 3 && n.includes(s.name.toLowerCase())) ?? null; + })(); + const set = (key: K, value: Draft[K]) => setDraft((d) => (d ? { ...d, [key]: value } : d)); const cards: { label: string; value: string; note?: string; color: string }[] = [ @@ -198,14 +221,60 @@ export default function Inventory({ user }: { user: CurrentUser }) { <>

Inventory

- {canEdit && !draft && ( - - )} +
+ + Print labels + + {canEdit && !draft && ( + + )} +
+ {focused && ( +
+
+

{focused.name}

+
+ +
+
+
+
+ {([ + ["Kind", KIND_LABELS[focused.kind]], + ["Maker and model", [focused.manufacturer, focused.model].filter(Boolean).join(" ") || null], + ["Serial number", focused.serial], + ["Where", [focused.location, focused.rackUnit].filter(Boolean).join(" · ") || null], + ["Bought", focused.purchaseDate], + ["Warranty until", focused.warrantyUntil], + ["Power draw", focused.powerWatts === null ? null : `${focused.powerWatts} W`], + ["Notes", focused.notes], + ] as [string, string | null][]).map(([label, value]) => ( +
+
{label}
+
{value ?? "—"}
+
+ ))} + {focused.server && ( +
+
Is the server
+
+ {focused.server.name} +
+
+ )} +
+
+
+ )} + {focusId !== null && assets !== null && !focused &&
That piece of hardware isn't in the inventory any more.
} +
{cards.map((c) => (
@@ -256,6 +325,15 @@ export default function Inventory({ user }: { user: CurrentUser }) { ))} + {draft.serverId === "" && suggestion && ( +
+ Looks like {suggestion.name}.{" "} + +
+ )} + {draft.serverId !== "" &&
Blank maker, model and serial number are filled in from the server's agent when you save.
}
)} + {canEdit && a.agent && Object.keys(a.agent.differs).length > 0 && ( +
+ The agent says {Object.entries(a.agent.differs).map(([k, v]) => `${k === "manufacturer" ? "maker" : k === "serial" ? "serial number" : k} ${v}`).join(", ")}.{" "} + +
+ )} {KIND_LABELS[a.kind]} diff --git a/web/src/pages/InventoryLabels.tsx b/web/src/pages/InventoryLabels.tsx new file mode 100644 index 0000000..d013be9 --- /dev/null +++ b/web/src/pages/InventoryLabels.tsx @@ -0,0 +1,143 @@ +import { useEffect, useMemo, useState } from "react"; +import { Link } from "react-router-dom"; +import { api, type Asset } from "../api/client"; +import QrCode from "../components/QrCode"; +import { ErrorNotice } from "../components/Notice"; +import { BlockSkeleton } from "../components/Skeleton"; +import { readableError } from "../utils/errors"; +import { KIND_LABELS } from "../utils/inventory"; + +/** Label sizes, in millimetres, as they are stuck on: a rack-mount sticker, a standard address label, a larger one for a shelf. */ +const SIZES = { + small: { label: "Small (50 × 25 mm)", w: 50, h: 25, qr: 21 }, + medium: { label: "Medium (70 × 35 mm)", w: 70, h: 35, qr: 29 }, + large: { label: "Large (90 × 50 mm)", w: 90, h: 50, qr: 42 }, +} as const; +type SizeKey = keyof typeof SIZES; + +/** What a label's code opens: that piece of hardware in the inventory. */ +export const labelUrl = (id: number) => `${window.location.origin}/inventory?asset=${id}`; + +/** + * Labels for the hardware, to print on a sheet of stickers (or plain paper and cut out): a QR code that opens the entry in the inventory, + * and the name, what it is, its serial number and where it sits in words for when a phone isn't to hand. + */ +export default function InventoryLabels() { + const [assets, setAssets] = useState(null); + const [error, setError] = useState(null); + const [chosen, setChosen] = useState>(new Set()); + const [size, setSize] = useState("medium"); + const [showBorder, setShowBorder] = useState(true); + + useEffect(() => { + api.inventory + .list() + .then((res) => { + setAssets(res.assets); + setChosen(new Set(res.assets.map((a) => a.id))); + }) + .catch((err) => setError(readableError(err))); + }, []); + + const picked = useMemo(() => (assets ?? []).filter((a) => chosen.has(a.id)), [assets, chosen]); + const dims = SIZES[size]; + + const toggle = (id: number) => + setChosen((prev) => { + const next = new Set(prev); + if (next.has(id)) next.delete(id); + else next.add(id); + return next; + }); + + return ( + <> +
+

Labels

+
+ + Back to the inventory + + +
+
+ + {/* The page's size is the label sheet's own: set here so the print dialog starts out right. */} + + +
+
+
+
+ + + +
Each code opens the entry in the inventory, so whoever scans it must be signed in here. Printed sizes are exact only with "Scale: 100%" in the print dialog.
+
+
+
+
+
+
+

Which hardware

+
+ + +
+
+
+ {assets === null && !error && } + {assets?.length === 0 &&
Nothing in the inventory yet.
} +
+ {assets?.map((a) => ( +
+ +
+ ))} +
+
+
+
+
+ +
+ {picked.map((a) => ( +
+
+ +
+
+
{a.name}
+ {(a.manufacturer || a.model) &&
{[a.manufacturer, a.model].filter(Boolean).join(" ")}
} + {a.serial &&
S/N {a.serial}
} + {(a.location || a.rackUnit) &&
{[a.location, a.rackUnit].filter(Boolean).join(" · ")}
} +
#{a.id}
+
+
+ ))} +
+ + ); +} diff --git a/web/src/pages/Privacy.tsx b/web/src/pages/Privacy.tsx index 4ddf533..957d437 100644 --- a/web/src/pages/Privacy.tsx +++ b/web/src/pages/Privacy.tsx @@ -7,7 +7,7 @@ import { formatAgo } from "../utils/duration"; import { readableError } from "../utils/errors"; import { ErrorNotice } from "../components/Notice"; -const CHANNEL_LABELS = { gotify: "Gotify", ntfy: "ntfy", smtp: "email (SMTP)", webhook: "webhook" } as const; +const CHANNEL_LABELS = { gotify: "Gotify", ntfy: "ntfy", smtp: "email (SMTP)", webhook: "webhook", webPush: "web push" } as const; /** SQLite timestamps ("2026-09-26 04:07:21") are UTC without a zone marker. */ function parseTime(value: string): Date { diff --git a/web/src/pages/settings/NotificationSettings.tsx b/web/src/pages/settings/NotificationSettings.tsx index f4739a2..cafe2e7 100644 --- a/web/src/pages/settings/NotificationSettings.tsx +++ b/web/src/pages/settings/NotificationSettings.tsx @@ -7,6 +7,7 @@ import { type NtfySettings, type SmtpSettings, type WebhookSettings, + type WebPushSettings, type NotificationEvents, type DigestSettings, type QuietHoursSettings, @@ -15,6 +16,7 @@ import { import { readableError } from "../../utils/errors"; import { ErrorNotice } from "../../components/Notice"; import { PageSkeleton } from "../../components/Skeleton"; +import PushDevices from "../../components/PushDevices"; const TIMEZONES = [ "UTC", @@ -43,6 +45,7 @@ const DEFAULT_GOTIFY: GotifySettings = { enabled: false, url: "", token: "", pri const DEFAULT_NTFY: NtfySettings = { enabled: false, url: "https://ntfy.sh", topic: "", token: "", priority: 3 }; const DEFAULT_SMTP: SmtpSettings = { enabled: false, host: "", port: 587, secure: false, username: "", password: "", from: "", to: "" }; const DEFAULT_WEBHOOK: WebhookSettings = { enabled: false, url: "", secret: "" }; +const DEFAULT_WEBPUSH: WebPushSettings = { enabled: false, contact: "" }; const DEFAULT_NOTIFICATIONS: NotificationEvents = { dnsAdd: true, dnsUpdate: true, @@ -219,6 +222,9 @@ export default function NotificationSettings() { const [ntfy, setNtfy] = useState(DEFAULT_NTFY); const [smtp, setSmtp] = useState(DEFAULT_SMTP); const [webhook, setWebhook] = useState(DEFAULT_WEBHOOK); + const [webPush, setWebPush] = useState(DEFAULT_WEBPUSH); + // Whether push is on as saved: people can only add their browsers once the server knows it is on. + const [webPushSaved, setWebPushSaved] = useState(false); const [notifications, setNotifications] = useState(DEFAULT_NOTIFICATIONS); const [quietHours, setQuietHours] = useState(DEFAULT_QUIET_HOURS); const [healthChecks, setHealthChecks] = useState(DEFAULT_HEALTH_CHECKS); @@ -239,7 +245,7 @@ export default function NotificationSettings() { const [testingWebhook, setTestingWebhook] = useState(false); const [testWebhookResult, setTestWebhookResult] = useState(null); - const snapshot = JSON.stringify({ gotify, ntfy, smtp, webhook, notifications, quietHours, healthChecks, digest }); + const snapshot = JSON.stringify({ gotify, ntfy, smtp, webhook, webPush, notifications, quietHours, healthChecks, digest }); const dirty = baseline !== null && snapshot !== baseline; useEffect(() => { @@ -251,12 +257,15 @@ export default function NotificationSettings() { setNtfy(s.ntfy); setSmtp(s.smtp); setWebhook(s.webhook); + const wp = s.webPush ?? DEFAULT_WEBPUSH; + setWebPush(wp); + setWebPushSaved(wp.enabled); setNotifications(s.notifications); setQuietHours(s.quietHours); setHealthChecks(s.healthChecks); const d = s.digest ?? DEFAULT_DIGEST; setDigest(d); - setBaseline(JSON.stringify({ gotify: s.gotify, ntfy: s.ntfy, smtp: s.smtp, webhook: s.webhook, notifications: s.notifications, quietHours: s.quietHours, healthChecks: s.healthChecks, digest: d })); + setBaseline(JSON.stringify({ gotify: s.gotify, ntfy: s.ntfy, smtp: s.smtp, webhook: s.webhook, webPush: wp, notifications: s.notifications, quietHours: s.quietHours, healthChecks: s.healthChecks, digest: d })); }) .catch((err) => setLoadError(err instanceof Error ? err.message : String(err))) .finally(() => setLoading(false)); @@ -303,8 +312,9 @@ export default function NotificationSettings() { setSaveError(null); setSaved(false); try { - await api.settings.update({ gotify, ntfy, smtp, webhook, notifications, quietHours, healthChecks, digest }); + await api.settings.update({ gotify, ntfy, smtp, webhook, webPush, notifications, quietHours, healthChecks, digest }); setBaseline(snapshot); + setWebPushSaved(webPush.enabled); setSaved(true); setTimeout(() => setSaved(false), 3000); } catch (err) { @@ -412,7 +422,7 @@ export default function NotificationSettings() { const ntfyComplete = !!(ntfy.url && ntfy.topic); const smtpComplete = !!(smtp.host && smtp.from && smtp.to); const webhookComplete = !!webhook.url; - const channelsOn = [gotify.enabled && gotifyComplete, ntfy.enabled && ntfyComplete, smtp.enabled && smtpComplete, webhook.enabled && webhookComplete].filter(Boolean).length; + const channelsOn = [gotify.enabled && gotifyComplete, ntfy.enabled && ntfyComplete, smtp.enabled && smtpComplete, webhook.enabled && webhookComplete, webPush.enabled].filter(Boolean).length; const toggle = (key: EventKey, label: string) => setNotifications((n) => ({ ...n, [key]: on }))} />; const dailyChecksEnabled = notifications.secretCheck || notifications.tailscaleKeyCheck || notifications.dockerUpdateCheck || notifications.proxmoxBackupCheck || notifications.pbsVerificationCheck || notifications.domainExpiryCheck; @@ -614,6 +624,30 @@ export default function NotificationSettings() { + + Push notifications to a phone or browser that asks for them, with no app or account. They need this page to be opened over https.} + enabled={webPush.enabled} + onToggle={(on) => setWebPush((w) => ({ ...w, enabled: on }))} + complete + summary="Web push" + open={openChannel === "webpush"} + onOpen={() => setOpenChannel(openChannel === "webpush" ? null : "webpush")} + > +
+ + setWebPush((w) => ({ ...w, contact: e.target.value }))} + /> +
Given to the browsers’ push services (Google, Mozilla, Apple) so they can reach you if this misbehaves. An email address or an https address.
+
+ +
{/* ── What to send ── */} diff --git a/web/src/styles.css b/web/src/styles.css index 23c6c24..a3c3b89 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -1477,3 +1477,62 @@ html[data-density="roomy"] .table > :not(caption) > * > * { height: auto; color: var(--tblr-body-color); } + +/* ── Labels for the hardware: cut out or stuck on, so they print alone, at their real size. ── */ +.label-sheet { + display: flex; + flex-wrap: wrap; + gap: 3mm; + align-items: flex-start; +} + +.asset-label { + display: flex; + gap: 2mm; + padding: 2mm; + overflow: hidden; + background: #fff; + color: #000; + font-size: 7pt; + line-height: 1.25; + break-inside: avoid; + box-sizing: border-box; +} + +.asset-label-border { + border: 0.3mm solid #000; +} + +.asset-label-qr { + flex: none; +} + +.asset-label-text { + min-width: 0; + overflow-wrap: anywhere; +} + +.asset-label-name { + font-size: 9pt; + font-weight: 700; +} + +.asset-label-id { + opacity: 0.6; +} + +@media print { + .no-print, + .navbar-vertical { + display: none !important; + } + + .page-wrapper { + margin: 0 !important; + padding: 0 !important; + } + + .page-body { + margin: 0 !important; + } +}