Add Read now to every integration
POST /api/integrations/:id/read-now reads one integration at once (operators and administrators; not again within 20 s): a kind with a stored reading is read and judged again, a kind read live is asked whether it answers. The three per-kind lists in the integrations routes (add, change, delete) are now one map in services/integrationSyncs.ts. Button on the Integrations cards and the Media managers, Download clients and Hetzner Robot pages. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
01acbaf831
commit
b29c0b7d04
13 files changed
+413
-107
No files matched your search
@@ -13,6 +13,15 @@ the dashboard views themselves load fine. (UniFi, Nginx Proxy Manager, Home Assi
|
||||
|
||||
## Integrations
|
||||
|
||||
### Reading one now
|
||||
|
||||
Every integration has a **Read now** button on the Integrations page (operators and administrators; the pages of Media managers, Download clients and Hetzner Robot have it too, on each card). `POST /api/integrations/{id}/read-now` answers `{ kind, ok, error, at, latencyMs }`:
|
||||
|
||||
- **`kind: "stored"`** — the integration has a reading that is kept (everything but the ones below): it is read the way its schedule reads it, stored, and the alerts are worked out again at once. A read that fails says why and leaves what was stored as it was.
|
||||
- **`kind: "live"`** — Proxmox, Synology, Tailscale, Gitea, Semaphore, Uptime Kuma, Proxmox Backup Server, osTicket, phpIPAM and Nginx Proxy Manager keep nothing: their pages and the health pass read them live every time. Here it asks whether the integration answers (the question *Test* asks, with what is saved) and brings its Working/Failing mark up to date; the alerts, which read it live, are worked out again at the next look.
|
||||
- **Not too often:** the same integration is not read again within **20 seconds** (HTTP 429, `Retry-After`) — some systems limit how often they may be asked. One that is switched off cannot be read (HTTP 400); one that is not there is a 404.
|
||||
- Which kinds have a stored reading is one list in `server/src/services/integrationSyncs.ts`, which also decides what happens when an integration is added, changed (a new address or credentials, or switched on) or deleted: it is read at once, and what was read is forgotten on delete. A new kind with a schedule is added there.
|
||||
|
||||
### Checking what an integration can read
|
||||
|
||||
On the Integrations page an administrator has an **Inspect** button on each integration that reads through the shared HTTP helper (Authentik, Immich, Jellyfin, NetBox, Nextcloud, Paperless-ngx, Prometheus, Hetzner Cloud, Hetzner Robot, Speedtest Tracker, Fragnet, Sonarr, Radarr, Prowlarr, Lidarr, Readarr, qBittorrent, SABnzbd, AdGuard Home, Technitium DNS and Grafana). It runs the integration's reader once and shows:
|
||||
|
||||
@@ -566,6 +566,8 @@ The page also shows the users, the files and the app updates waiting. Whether it
|
||||
|
||||
**App versions** (Operations → App versions). The version each connected application runs — as its integration last read it — against the newest release of it, with how far behind it is (a patch, a minor update, a major version) and how long the newer release has been out. It looks the newest releases up on GitHub once a day, and **that is the only thing this app asks of an address that is not yours, so it is switched off until an administrator switches it on**. A number of days (0 = never) makes a newer release that has been out that long a warning. Sonarr, Radarr, Prowlarr, Lidarr, Readarr, AdGuard Home, Grafana, Jellyfin, Immich, Paperless-ngx, Nextcloud, NetBox, Authentik and Prometheus are compared. See docs/MONITORING.md.
|
||||
|
||||
**Read now** (Integrations → *Read now* on each integration, and on the pages of Media managers, Download clients and Hetzner Robot; operators and administrators). Reads one integration at once instead of waiting for its next turn, and says how it went. An integration that is read on a schedule and stored (most of them) is read the way the schedule reads it, and what it says is judged again at once, so an alert that has cleared clears and a new one appears without waiting. One that is read live (Proxmox, Synology, Tailscale, Gitea, Semaphore, Uptime Kuma, Proxmox Backup Server, osTicket, phpIPAM, Nginx Proxy Manager) is asked whether it answers — the question *Test* asks — which also brings its Working/Failing mark up to date. The same integration is not read again within 20 seconds, since some systems limit how often they may be asked (Hetzner Robot allows 200 requests an hour). See INTEGRATIONS.md.
|
||||
|
||||
**Inspect an integration** (Integrations → *Inspect*, administrators). Runs the integration's reader once, now, and shows what each request asked and got back — the **shape** of every answer (the names and kinds of its fields, never the values) — beside what the reader made of it and the fields that came out empty. It is how an integration written from documentation is checked against the real system: an answer with a field the reader did not expect shows up as an empty field. *Copy the report* gives plain text that can be pasted into a message. Each inspection is written to the audit log; nothing is stored or changed.
|
||||
|
||||
**Grouping alerts.** On the Alerts page a *Group by* choice puts the alerts under a header for each source (Hetzner, Sonarr …), kind of problem (Disk, Backups …) or type of alert (a Hetzner certificate about to end …) — worst group first, each header showing how many and how serious, each group folding away, and a tick on the header picking everything in it for a bulk action. Remembered per browser; not grouped is the default.
|
||||
|
||||
@@ -171,6 +171,7 @@ even further, to admin only:
|
||||
- **Media managers** (Apps → Media managers, for Sonarr, Radarr and Prowlarr): everyone signed in sees what each says is wrong, its queue, disks and indexers; adding one (its API key) is an administrator's job, like any integration. Nothing on the page changes anything in them.
|
||||
- **Download clients** (Apps → Download clients, for qBittorrent and SABnzbd): everyone signed in sees speed, queue, what is stuck or failed and the room left; adding one (its user name and password, or its API key) is an administrator's job, like any integration. Nothing on the page adds, pauses or removes anything in them.
|
||||
- **App versions** (Operations → App versions): everyone signed in sees what each application runs against the newest release; switching the lookup of releases on and off, and the number of days after which a newer release is a warning, are an administrator's.
|
||||
- **Read now** (Integrations → Read now, and on the Media managers, Download clients and Hetzner Robot pages): operators and administrators. It only reads — nothing at the other end is changed — but it makes the integration's requests at once, so the same integration cannot be read again within 20 seconds. Viewers do not see the button.
|
||||
- **Inspecting an integration** (Integrations → Inspect): administrators only — it makes the integration's requests, here and now (and says what came back, as shapes without values); each one is in the audit log.
|
||||
- **Grouping the alerts** is each person's own view, remembered in their browser; it needs no role.
|
||||
- **AdGuard Home** (Network → AdGuard Home), **Technitium DNS** (Network → Technitium DNS) and **Grafana** (Monitoring → Grafana): everyone signed in sees what each says is wrong, the statistics, lists, zones, rules and data sources; adding one (its sign-in or token) is an administrator's job, like any integration. Nothing on the pages changes anything in them.
|
||||
|
||||
@@ -27,30 +27,9 @@ import { createPbsAdapter } from "../integrations/pbs/adapter.js";
|
||||
import { createOsTicketAdapter } from "../integrations/osticket/adapter.js";
|
||||
import { attachMatchedServers, summarizeMonitors, toMatchableServers } from "../services/uptimeKumaMatch.js";
|
||||
import { getSourceStatus } from "../services/integrationHealthMonitor.js";
|
||||
import { removeIntegrationData, syncUnifiIntegration } from "../services/unifiSync.js";
|
||||
import { removeHomeAssistantData, syncHomeAssistant } from "../services/homeAssistantSync.js";
|
||||
import { forgetUps, syncUps } from "../services/upsSync.js";
|
||||
import { forgetJellyfin, syncJellyfin } from "../services/jellyfinSync.js";
|
||||
import { forgetAuthentik, syncAuthentik } from "../services/authentikSync.js";
|
||||
import { forgetPrometheus, syncPrometheus } from "../services/prometheusSync.js";
|
||||
import { forgetImmich, syncImmich } from "../services/immichSync.js";
|
||||
import { forgetPaperless, syncPaperless } from "../services/paperlessSync.js";
|
||||
import { forgetN8n, syncN8n } from "../services/n8nSync.js";
|
||||
import { forgetNetBox, syncNetBox } from "../services/netboxSync.js";
|
||||
import { forgetHetzner, syncHetzner } from "../services/hetznerSync.js";
|
||||
import { forgetSpeedtest, syncSpeedtest } from "../services/speedtestSync.js";
|
||||
import { forgetFragnet, syncFragnet } from "../services/fragnetSync.js";
|
||||
import { forgetArr, syncArr } from "../services/arrSync.js";
|
||||
import { ARR_KINDS } from "../integrations/arr/adapter.js";
|
||||
import { forgetAdguard, syncAdguard } from "../services/adguardSync.js";
|
||||
import { forgetDownload, syncDownload } from "../services/downloadsSync.js";
|
||||
import { DOWNLOAD_KINDS } from "../integrations/downloads/adapter.js";
|
||||
import { forgetRobot, syncRobot } from "../services/hetznerRobotSync.js";
|
||||
import { forgetTechnitium, syncTechnitium } from "../services/technitiumSync.js";
|
||||
import { forgetGrafana, syncGrafana } from "../services/grafanaSync.js";
|
||||
import { forgetNextcloud, syncNextcloud } from "../services/nextcloudSync.js";
|
||||
import { dockerVulnSyncStatuses, findingsOf, forgetDockerVulns, imageAgeDays, imagesOf, isDockerVulnFresh, syncDockerVulns } from "../services/dockerVulnSync.js";
|
||||
import { dockerVulnSyncStatuses, findingsOf, imageAgeDays, imagesOf, isDockerVulnFresh } from "../services/dockerVulnSync.js";
|
||||
import { invalidateAlertsCache } from "../services/alerts.js";
|
||||
import { forgetReading, readAfterChange, readIntegrationNow } from "../services/integrationSyncs.js";
|
||||
import { getSettings, updateSettings } from "../services/settingsStore.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
import { ID_PATTERNS, isValidId } from "../utils/pathSegment.js";
|
||||
@@ -149,27 +128,7 @@ integrationsRouter.post("/", requireRole("admin"), asyncHandler(async (req, res)
|
||||
});
|
||||
|
||||
// A new UniFi controller is read at once, so its equipment is there when the person opens the page (not waited for: a slow controller must not slow this).
|
||||
if (type === "unifi") void syncUnifiIntegration(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "homeassistant") void syncHomeAssistant(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "ups") void syncUps(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "jellyfin") void syncJellyfin(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "authentik") void syncAuthentik(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "prometheus") void syncPrometheus(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "immich") void syncImmich(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "paperless") void syncPaperless(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "n8n") void syncN8n(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "netbox") void syncNetBox(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "hetzner") void syncHetzner(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "speedtest") void syncSpeedtest(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "fragnet") void syncFragnet(created.id).then(() => invalidateAlertsCache());
|
||||
if ((ARR_KINDS as string[]).includes(type)) void syncArr(created.id).then(() => invalidateAlertsCache());
|
||||
if ((DOWNLOAD_KINDS as string[]).includes(type)) void syncDownload(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "hetznerrobot") void syncRobot(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "adguard") void syncAdguard(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "technitium") void syncTechnitium(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "grafana") void syncGrafana(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "nextcloud") void syncNextcloud(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "dockhand") void syncDockerVulns(created.id).then(() => invalidateAlertsCache());
|
||||
readAfterChange(type, created.id);
|
||||
|
||||
res.status(201).json({
|
||||
integration: {
|
||||
@@ -270,27 +229,7 @@ integrationsRouter.patch("/:id", requireRole("admin"), asyncHandler(async (req,
|
||||
},
|
||||
});
|
||||
|
||||
if (updated.type === "unifi" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncUnifiIntegration(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "homeassistant" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncHomeAssistant(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "ups" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncUps(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "jellyfin" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncJellyfin(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "authentik" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncAuthentik(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "prometheus" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncPrometheus(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "immich" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncImmich(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "paperless" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncPaperless(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "n8n" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncN8n(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "netbox" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncNetBox(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "hetzner" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncHetzner(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "speedtest" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncSpeedtest(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "fragnet" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncFragnet(updated.id).then(() => invalidateAlertsCache());
|
||||
if ((ARR_KINDS as string[]).includes(updated.type) && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncArr(updated.id).then(() => invalidateAlertsCache());
|
||||
if ((DOWNLOAD_KINDS as string[]).includes(updated.type) && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncDownload(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "hetznerrobot" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncRobot(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "adguard" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncAdguard(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "technitium" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncTechnitium(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "grafana" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncGrafana(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "nextcloud" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncNextcloud(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "dockhand" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncDockerVulns(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.enabled && (parsed.data.config || parsed.data.enabled === true)) readAfterChange(updated.type, updated.id);
|
||||
|
||||
res.json({
|
||||
integration: {
|
||||
@@ -352,6 +291,18 @@ integrationsRouter.post("/:id/test", requireRole("admin"), asyncHandler(async (r
|
||||
res.json(result);
|
||||
}));
|
||||
|
||||
// Reads one integration now, instead of waiting for its next turn: a kind with a stored reading is read the way its schedule reads it (and what it says is judged again at once); a kind that is read live
|
||||
// is asked whether it answers. Operators and administrators — it only reads, but some systems limit how often they may be asked, so the same integration is not read again within 20 seconds.
|
||||
integrationsRouter.post("/:id/read-now", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const id = Number(req.params.id);
|
||||
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });
|
||||
const r = await readIntegrationNow(id);
|
||||
if (r.state === "not_found") return res.status(404).json({ error: "not_found" });
|
||||
if (r.state === "disabled") return res.status(400).json({ error: "integration_disabled", message: "It is switched off." });
|
||||
if (r.state === "too_soon") return res.status(429).set("Retry-After", String(r.retryAfterSeconds)).json({ error: "too_soon", message: `It was read a moment ago — try again in ${r.retryAfterSeconds} s.`, retryAfterSeconds: r.retryAfterSeconds });
|
||||
res.json({ kind: r.kind, ok: r.ok, error: r.error, at: r.at, latencyMs: r.latencyMs });
|
||||
}));
|
||||
|
||||
/** How long an inspection may take: a read makes a handful of requests, each with a timeout of its own. */
|
||||
const INSPECT_LIMIT_MS = 90_000;
|
||||
|
||||
@@ -398,27 +349,7 @@ integrationsRouter.delete("/:id", requireRole("admin"), asyncHandler(async (req,
|
||||
.where(eq(servers.proxmoxIntegrationId, id))
|
||||
.returning({ id: servers.id });
|
||||
|
||||
if (existing.type === "unifi") await removeIntegrationData(id);
|
||||
if (existing.type === "homeassistant") await removeHomeAssistantData(id);
|
||||
if (existing.type === "ups") await forgetUps(id);
|
||||
if (existing.type === "jellyfin") await forgetJellyfin(id);
|
||||
if (existing.type === "authentik") await forgetAuthentik(id);
|
||||
if (existing.type === "prometheus") await forgetPrometheus(id);
|
||||
if (existing.type === "immich") await forgetImmich(id);
|
||||
if (existing.type === "paperless") await forgetPaperless(id);
|
||||
if (existing.type === "n8n") await forgetN8n(id);
|
||||
if (existing.type === "netbox") await forgetNetBox(id);
|
||||
if (existing.type === "hetzner") await forgetHetzner(id);
|
||||
if (existing.type === "speedtest") await forgetSpeedtest(id);
|
||||
if (existing.type === "fragnet") await forgetFragnet(id);
|
||||
if ((ARR_KINDS as string[]).includes(existing.type)) await forgetArr(id);
|
||||
if ((DOWNLOAD_KINDS as string[]).includes(existing.type)) await forgetDownload(id);
|
||||
if (existing.type === "hetznerrobot") await forgetRobot(id);
|
||||
if (existing.type === "adguard") await forgetAdguard(id);
|
||||
if (existing.type === "technitium") await forgetTechnitium(id);
|
||||
if (existing.type === "grafana") await forgetGrafana(id);
|
||||
if (existing.type === "nextcloud") await forgetNextcloud(id);
|
||||
if (existing.type === "dockhand") await forgetDockerVulns(id);
|
||||
await forgetReading(existing.type, id);
|
||||
await db.delete(integrations).where(eq(integrations.id, id));
|
||||
if (existing.credentialId) {
|
||||
await db.delete(integrationCredentials).where(eq(integrationCredentials.id, existing.credentialId));
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* What each kind of integration has that is read on a schedule and stored (a "sync") — in one place, so that adding an integration, changing one, taking one away and asking for it to be read *now* all
|
||||
* agree on which kinds have one. A kind that is not here (Proxmox, Synology, Tailscale, Gitea, Semaphore, Uptime Kuma, Proxmox Backup Server, osTicket, phpIPAM, Nginx Proxy Manager) has nothing stored:
|
||||
* its pages and the health pass read it live, every time.
|
||||
*/
|
||||
import type { IntegrationType } from "../db/schema.js";
|
||||
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
|
||||
import { createIntegrationAdapter } from "../integrations/registry.js";
|
||||
import { ARR_KINDS } from "../integrations/arr/adapter.js";
|
||||
import { DOWNLOAD_KINDS } from "../integrations/downloads/adapter.js";
|
||||
import { invalidateAlertsCache } from "./alerts.js";
|
||||
import { forgetAdguard, syncAdguard } from "./adguardSync.js";
|
||||
import { forgetArr, syncArr } from "./arrSync.js";
|
||||
import { forgetAuthentik, syncAuthentik } from "./authentikSync.js";
|
||||
import { forgetDockerVulns, syncDockerVulns } from "./dockerVulnSync.js";
|
||||
import { forgetDownload, syncDownload } from "./downloadsSync.js";
|
||||
import { forgetFragnet, syncFragnet } from "./fragnetSync.js";
|
||||
import { forgetGrafana, syncGrafana } from "./grafanaSync.js";
|
||||
import { forgetHetzner, syncHetzner } from "./hetznerSync.js";
|
||||
import { forgetRobot, syncRobot } from "./hetznerRobotSync.js";
|
||||
import { removeHomeAssistantData, syncHomeAssistant } from "./homeAssistantSync.js";
|
||||
import { forgetImmich, syncImmich } from "./immichSync.js";
|
||||
import { forgetJellyfin, syncJellyfin } from "./jellyfinSync.js";
|
||||
import { forgetN8n, syncN8n } from "./n8nSync.js";
|
||||
import { forgetNetBox, syncNetBox } from "./netboxSync.js";
|
||||
import { forgetNextcloud, syncNextcloud } from "./nextcloudSync.js";
|
||||
import { forgetPaperless, syncPaperless } from "./paperlessSync.js";
|
||||
import { forgetPrometheus, syncPrometheus } from "./prometheusSync.js";
|
||||
import { forgetSpeedtest, syncSpeedtest } from "./speedtestSync.js";
|
||||
import { forgetTechnitium, syncTechnitium } from "./technitiumSync.js";
|
||||
import { removeIntegrationData, syncUnifiIntegration } from "./unifiSync.js";
|
||||
import { forgetUps, syncUps } from "./upsSync.js";
|
||||
|
||||
/** How a read went, as every sync says it (some say more, which is not needed here). */
|
||||
export interface ReadStatus {
|
||||
at?: string;
|
||||
ok: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
interface Entry {
|
||||
sync: (id: number) => Promise<ReadStatus>;
|
||||
forget: (id: number) => Promise<void>;
|
||||
}
|
||||
|
||||
const BY_TYPE: Partial<Record<IntegrationType, Entry>> = {
|
||||
unifi: { sync: syncUnifiIntegration, forget: removeIntegrationData },
|
||||
homeassistant: { sync: syncHomeAssistant, forget: removeHomeAssistantData },
|
||||
ups: { sync: syncUps, forget: forgetUps },
|
||||
jellyfin: { sync: syncJellyfin, forget: forgetJellyfin },
|
||||
authentik: { sync: syncAuthentik, forget: forgetAuthentik },
|
||||
prometheus: { sync: syncPrometheus, forget: forgetPrometheus },
|
||||
immich: { sync: syncImmich, forget: forgetImmich },
|
||||
paperless: { sync: syncPaperless, forget: forgetPaperless },
|
||||
n8n: { sync: syncN8n, forget: forgetN8n },
|
||||
netbox: { sync: syncNetBox, forget: forgetNetBox },
|
||||
hetzner: { sync: syncHetzner, forget: forgetHetzner },
|
||||
hetznerrobot: { sync: syncRobot, forget: forgetRobot },
|
||||
speedtest: { sync: syncSpeedtest, forget: forgetSpeedtest },
|
||||
fragnet: { sync: syncFragnet, forget: forgetFragnet },
|
||||
adguard: { sync: syncAdguard, forget: forgetAdguard },
|
||||
technitium: { sync: syncTechnitium, forget: forgetTechnitium },
|
||||
grafana: { sync: syncGrafana, forget: forgetGrafana },
|
||||
nextcloud: { sync: syncNextcloud, forget: forgetNextcloud },
|
||||
dockhand: { sync: (id) => syncDockerVulns(id), forget: forgetDockerVulns },
|
||||
};
|
||||
for (const k of ARR_KINDS) BY_TYPE[k] = { sync: (id) => syncArr(id), forget: forgetArr };
|
||||
for (const k of DOWNLOAD_KINDS) BY_TYPE[k] = { sync: (id) => syncDownload(id), forget: forgetDownload };
|
||||
|
||||
/** Whether this kind of integration has a reading that is stored. */
|
||||
export const hasStoredReading = (type: IntegrationType): boolean => BY_TYPE[type] !== undefined;
|
||||
|
||||
/** A new integration, or one whose settings changed or that was switched on, is read at once (not waited for: a slow system must not slow the request), so what it shows and says is there when the page is opened. */
|
||||
export function readAfterChange(type: IntegrationType, id: number): void {
|
||||
const entry = BY_TYPE[type];
|
||||
if (entry) void entry.sync(id).then(() => invalidateAlertsCache());
|
||||
}
|
||||
|
||||
/** An integration that is being taken away: what was read from it goes too. */
|
||||
export async function forgetReading(type: IntegrationType, id: number): Promise<void> {
|
||||
await BY_TYPE[type]?.forget(id);
|
||||
}
|
||||
|
||||
/** Wait this long between two reads of the same integration asked for by hand: some systems limit how often they may be asked (Hetzner Robot: 200 requests an hour). */
|
||||
export const READ_NOW_COOLDOWN_MS = 20_000;
|
||||
const lastAsked = new Map<number, number>();
|
||||
|
||||
export type ReadNowResult =
|
||||
| { state: "read"; kind: "stored" | "live"; ok: boolean; error: string | null; at: string; latencyMs: number | null }
|
||||
| { state: "not_found" }
|
||||
| { state: "disabled" }
|
||||
| { state: "too_soon"; retryAfterSeconds: number };
|
||||
|
||||
/**
|
||||
* Reads one integration now. A kind with a stored reading is read the way its schedule reads it, and what it says is judged again at once; a kind that is read live (nothing stored) is asked whether it
|
||||
* answers — the same question *Test* asks — which also brings its Working/Failing status up to date, and the alerts, which read it live, are worked out again at the next look. Never throws.
|
||||
*/
|
||||
export async function readIntegrationNow(id: number, now: number = Date.now()): Promise<ReadNowResult> {
|
||||
const loaded = await loadIntegrationConfig(id);
|
||||
if (!loaded) return { state: "not_found" };
|
||||
if (!loaded.integration.enabled) return { state: "disabled" };
|
||||
const before = lastAsked.get(id);
|
||||
if (before !== undefined && now - before < READ_NOW_COOLDOWN_MS) return { state: "too_soon", retryAfterSeconds: Math.ceil((READ_NOW_COOLDOWN_MS - (now - before)) / 1000) };
|
||||
lastAsked.set(id, now);
|
||||
const type = loaded.integration.type;
|
||||
const entry = BY_TYPE[type];
|
||||
const started = Date.now();
|
||||
try {
|
||||
if (entry) {
|
||||
const status = await entry.sync(id);
|
||||
invalidateAlertsCache();
|
||||
return { state: "read", kind: "stored", ok: status.ok, error: status.error, at: status.at ?? new Date().toISOString(), latencyMs: Date.now() - started };
|
||||
}
|
||||
const result = await createIntegrationAdapter(type, loaded.config).ping();
|
||||
invalidateAlertsCache();
|
||||
return { state: "read", kind: "live", ok: result.ok, error: result.ok ? null : (result.error ?? "no answer"), at: new Date().toISOString(), latencyMs: result.latencyMs ?? Date.now() - started };
|
||||
} catch (err) {
|
||||
return { state: "read", kind: entry ? "stored" : "live", ok: false, error: err instanceof Error ? err.message : String(err), at: new Date().toISOString(), latencyMs: null };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* "Read now": one integration read at once instead of at its next turn — a kind with a stored reading is read the way its schedule reads it, a kind that is read live is asked whether it answers; the
|
||||
* same one not again within twenty seconds; operators and administrators only; and the one list of which kinds have a stored reading.
|
||||
*
|
||||
* Run with: npm test --workspace server
|
||||
*/
|
||||
import { test, describe, before, after } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createServer as createHttpServer, type 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-readnow-"));
|
||||
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, integrations, integrationTypes, downloadState } = await import("../src/db/schema.js");
|
||||
const { runMigrations } = await import("../src/db/migrate.js");
|
||||
const syncs = await import("../src/services/integrationSyncs.js");
|
||||
const { downloadSyncStatuses } = await import("../src/services/downloadsSync.js");
|
||||
const { integrationsRouter } = await import("../src/routes/integrations.js");
|
||||
const { eq } = await import("drizzle-orm");
|
||||
|
||||
await runMigrations();
|
||||
|
||||
describe("which kinds have a stored reading", () => {
|
||||
test("every kind is either read on a schedule and stored, or read live — so a new kind is placed on purpose", () => {
|
||||
const live = integrationTypes.filter((t) => !syncs.hasStoredReading(t)).sort();
|
||||
assert.deepEqual(live, ["gitea", "npm", "osticket", "pbs", "phpipam", "proxmox", "semaphore", "synology", "tailscale", "uptimekuma"]);
|
||||
for (const t of ["sonarr", "lidarr", "qbittorrent", "sabnzbd", "hetznerrobot", "dockhand", "unifi", "homeassistant", "ups", "grafana"] as const) assert.equal(syncs.hasStoredReading(t), true, t);
|
||||
});
|
||||
});
|
||||
|
||||
describe("reading one now", () => {
|
||||
let fake: Server;
|
||||
let url = "";
|
||||
let sabStatus = 200;
|
||||
let giteaStatus = 200;
|
||||
let sabId = 0;
|
||||
let giteaId = 0;
|
||||
let offId = 0;
|
||||
before(async () => {
|
||||
fake = createHttpServer((req, res) => {
|
||||
const u = new URL(req.url ?? "", "http://x");
|
||||
const send = (code: number, v: unknown) => {
|
||||
res.writeHead(code, { "content-type": "application/json" });
|
||||
res.end(JSON.stringify(v));
|
||||
};
|
||||
if (u.pathname === "/api") {
|
||||
if (sabStatus !== 200) return send(sabStatus, {});
|
||||
const mode = u.searchParams.get("mode");
|
||||
if (mode === "queue") return send(200, { queue: { version: "4.3.2", paused: false, kbpersec: "100", slots: [{ nzo_id: "a", filename: "A", status: "Downloading", mb: "10", mbleft: "5" }] } });
|
||||
if (mode === "history") return send(200, { history: { slots: [] } });
|
||||
return send(200, { warnings: [] });
|
||||
}
|
||||
if (u.pathname === "/api/v1/user/repos") return giteaStatus === 200 ? send(200, []) : send(giteaStatus, { message: "no" });
|
||||
send(404, {});
|
||||
});
|
||||
await new Promise<void>((resolve) => fake.listen(0, "127.0.0.1", resolve));
|
||||
url = `http://127.0.0.1:${(fake.address() as AddressInfo).port}`;
|
||||
const mk = async (type: "sabnzbd" | "gitea", name: string, config: Record<string, unknown>, enabled = true) => (await db.insert(integrations).values({ type, name, baseUrl: url, config: JSON.stringify(config), enabled }).returning({ id: integrations.id }))[0].id;
|
||||
sabId = await mk("sabnzbd", "Usenet", { url, apiKey: "k" });
|
||||
giteaId = await mk("gitea", "Git", { url, token: "t" });
|
||||
offId = await mk("sabnzbd", "Usenet off", { url, apiKey: "k" }, false);
|
||||
});
|
||||
after(() => fake.close());
|
||||
|
||||
test("a kind with a stored reading is read and stored, and the answer says it was a stored one", async () => {
|
||||
const r = await syncs.readIntegrationNow(sabId);
|
||||
assert.equal(r.state, "read");
|
||||
if (r.state !== "read") return;
|
||||
assert.deepEqual([r.kind, r.ok, r.error], ["stored", true, null]);
|
||||
assert.ok(Date.parse(r.at) > Date.now() - 60_000);
|
||||
assert.equal((await downloadSyncStatuses())[sabId]?.ok, true);
|
||||
assert.equal((await db.select().from(downloadState).where(eq(downloadState.integrationId, sabId))).length, 1);
|
||||
});
|
||||
|
||||
test("the same one is not read again within twenty seconds — and is, after", async () => {
|
||||
const t0 = Date.now() + 1_000_000;
|
||||
assert.equal((await syncs.readIntegrationNow(sabId, t0)).state, "read");
|
||||
const soon = await syncs.readIntegrationNow(sabId, t0 + 5_000);
|
||||
assert.deepEqual(soon, { state: "too_soon", retryAfterSeconds: 15 });
|
||||
assert.equal((await syncs.readIntegrationNow(sabId, t0 + syncs.READ_NOW_COOLDOWN_MS)).state, "read");
|
||||
assert.equal((await syncs.readIntegrationNow(giteaId, t0 + 5_000)).state, "read", "another integration is not held up by it");
|
||||
});
|
||||
|
||||
test("a read that fails says why, and what was stored is kept", async () => {
|
||||
sabStatus = 500;
|
||||
const r = await syncs.readIntegrationNow(sabId, Date.now() + 2_000_000);
|
||||
assert.equal(r.state, "read");
|
||||
if (r.state !== "read") return;
|
||||
assert.deepEqual([r.kind, r.ok], ["stored", false]);
|
||||
assert.match(r.error ?? "", /SABnzbd error: HTTP 500/);
|
||||
const status = (await downloadSyncStatuses())[sabId];
|
||||
assert.equal(status?.ok, false);
|
||||
assert.equal((await db.select().from(downloadState).where(eq(downloadState.integrationId, sabId))).length, 1);
|
||||
sabStatus = 200;
|
||||
});
|
||||
|
||||
test("a kind that is read live is asked whether it answers, like Test", async () => {
|
||||
const ok = await syncs.readIntegrationNow(giteaId, Date.now() + 3_000_000);
|
||||
assert.equal(ok.state, "read");
|
||||
if (ok.state !== "read") return;
|
||||
assert.deepEqual([ok.kind, ok.ok, ok.error], ["live", true, null]);
|
||||
assert.equal(typeof ok.latencyMs, "number");
|
||||
giteaStatus = 401;
|
||||
const bad = await syncs.readIntegrationNow(giteaId, Date.now() + 4_000_000);
|
||||
assert.equal(bad.state, "read");
|
||||
if (bad.state !== "read") return;
|
||||
assert.deepEqual([bad.kind, bad.ok], ["live", false]);
|
||||
assert.ok((bad.error ?? "").length > 0);
|
||||
giteaStatus = 200;
|
||||
});
|
||||
|
||||
test("one that is switched off, and one that is not there, are said", async () => {
|
||||
assert.deepEqual(await syncs.readIntegrationNow(offId), { state: "disabled" });
|
||||
assert.deepEqual(await syncs.readIntegrationNow(999_999), { state: "not_found" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("the route", () => {
|
||||
let app: Server;
|
||||
let base = "";
|
||||
let sessionSub = "operator";
|
||||
let id = 0;
|
||||
let fake: Server;
|
||||
before(async () => {
|
||||
fake = createHttpServer((req, res) => {
|
||||
const u = new URL(req.url ?? "", "http://x");
|
||||
res.writeHead(200, { "content-type": "application/json" });
|
||||
res.end(JSON.stringify(u.searchParams.get("mode") === "queue" ? { queue: { version: "4", slots: [] } } : u.searchParams.get("mode") === "history" ? { history: { slots: [] } } : { warnings: [] }));
|
||||
});
|
||||
await new Promise<void>((resolve) => fake.listen(0, "127.0.0.1", resolve));
|
||||
const furl = `http://127.0.0.1:${(fake.address() as AddressInfo).port}`;
|
||||
await db.insert(users).values([
|
||||
{ oidcSub: "operator", name: "Olle", role: "operator" },
|
||||
{ oidcSub: "viewer", name: "Vic", role: "viewer" },
|
||||
]);
|
||||
id = (await db.insert(integrations).values({ type: "sabnzbd", name: "Route", baseUrl: furl, config: JSON.stringify({ url: furl, apiKey: "k" }) }).returning({ id: integrations.id }))[0].id;
|
||||
const a = express();
|
||||
a.use((req, _res, next) => {
|
||||
(req as unknown as { session: unknown }).session = { user: { sub: sessionSub } };
|
||||
next();
|
||||
});
|
||||
a.use("/api/integrations", integrationsRouter);
|
||||
app = await new Promise<Server>((resolve) => {
|
||||
const s = a.listen(0, "127.0.0.1", () => resolve(s));
|
||||
});
|
||||
base = `http://127.0.0.1:${(app.address() as AddressInfo).port}/api/integrations`;
|
||||
});
|
||||
after(() => {
|
||||
app.close();
|
||||
fake.close();
|
||||
try {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
} catch {
|
||||
// Windows keeps the database file locked until the process exits.
|
||||
}
|
||||
});
|
||||
|
||||
test("an operator reads it and is told how it went; a viewer is not allowed", async () => {
|
||||
sessionSub = "viewer";
|
||||
assert.equal((await fetch(`${base}/${id}/read-now`, { method: "POST" })).status, 403);
|
||||
sessionSub = "operator";
|
||||
const res = await fetch(`${base}/${id}/read-now`, { method: "POST" });
|
||||
assert.equal(res.status, 200);
|
||||
const body = (await res.json()) as { kind: string; ok: boolean; error: string | null; at: string };
|
||||
assert.deepEqual([body.kind, body.ok, body.error], ["stored", true, null]);
|
||||
});
|
||||
|
||||
test("asked again at once it says to wait, with the time in the answer and in Retry-After", async () => {
|
||||
const res = await fetch(`${base}/${id}/read-now`, { method: "POST" });
|
||||
assert.equal(res.status, 429);
|
||||
const body = (await res.json()) as { error: string; retryAfterSeconds: number; message: string };
|
||||
assert.equal(body.error, "too_soon");
|
||||
assert.ok(body.retryAfterSeconds >= 1 && body.retryAfterSeconds <= 20);
|
||||
assert.equal(res.headers.get("retry-after"), String(body.retryAfterSeconds));
|
||||
assert.match(body.message, /try again in \d+ s/);
|
||||
});
|
||||
|
||||
test("an integration that is not there is a 404, and an id that is not a number a 400", async () => {
|
||||
assert.equal((await fetch(`${base}/999999/read-now`, { method: "POST" })).status, 404);
|
||||
assert.equal((await fetch(`${base}/abc/read-now`, { method: "POST" })).status, 400);
|
||||
});
|
||||
});
|
||||
+3
-3
@@ -186,9 +186,9 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/nextcloud" element={<Nextcloud />} />
|
||||
<Route path="/hetzner" element={<Hetzner />} />
|
||||
<Route path="/game-servers" element={<GameServers user={user} />} />
|
||||
<Route path="/media" element={<Media />} />
|
||||
<Route path="/downloads" element={<Downloads />} />
|
||||
<Route path="/hetzner-robot" element={<HetznerRobot />} />
|
||||
<Route path="/media" element={<Media user={user} />} />
|
||||
<Route path="/downloads" element={<Downloads user={user} />} />
|
||||
<Route path="/hetzner-robot" element={<HetznerRobot user={user} />} />
|
||||
<Route path="/versions" element={<Versions user={user} />} />
|
||||
<Route path="/adguard" element={<AdguardHome />} />
|
||||
<Route path="/technitium" element={<TechnitiumDns />} />
|
||||
|
||||
@@ -4242,6 +4242,8 @@ export const api = {
|
||||
config: Record<string, string | boolean>;
|
||||
}>(`/api/integrations/${id}/config`),
|
||||
inspect: (id: number) => request<IntegrationInspection>(`/api/integrations/${id}/inspect`, { method: "POST" }),
|
||||
/** Reads it now instead of at its next turn. A kind with a stored reading is read and judged again; a kind that is read live is asked whether it answers. */
|
||||
readNow: (id: number) => request<{ kind: "stored" | "live"; ok: boolean; error: string | null; at: string; latencyMs: number | null }>(`/api/integrations/${id}/read-now`, { method: "POST" }),
|
||||
testExisting: (id: number, config: Record<string, string | boolean>) =>
|
||||
request<{ ok: boolean; latencyMs?: number; error?: string }>(`/api/integrations/${id}/test`, {
|
||||
method: "POST",
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useState } from "react";
|
||||
import { IconRefresh } from "@tabler/icons-react";
|
||||
import { api } from "../api/client";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
/**
|
||||
* "Read now": reads one integration at once instead of at its next turn, then says how it went and — if the page that holds the button has something to refresh — asks it to (`onDone`). For
|
||||
* operators and administrators; the button is for the page to show or not. The same integration cannot be read again within twenty seconds (some systems limit how often they may be asked), which
|
||||
* the server says and the toast repeats.
|
||||
*/
|
||||
export default function ReadNowButton({ integrationId, name, onDone, className = "btn btn-sm" }: { integrationId: number; name: string; onDone?: () => void; className?: string }) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
async function readNow() {
|
||||
setBusy(true);
|
||||
try {
|
||||
const r = await api.integrations.readNow(integrationId);
|
||||
if (r.ok) toast.success(r.kind === "live" ? `${name} answers.` : `${name} was read.`);
|
||||
else toast.error(`${name} could not be read: ${r.error ?? "no answer"}`);
|
||||
} catch (err) {
|
||||
toast.error(`${name}: ${readableError(err)}`);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
onDone?.();
|
||||
}
|
||||
}
|
||||
return (
|
||||
<button type="button" className={className} onClick={() => void readNow()} disabled={busy} title="Read it now, instead of waiting for its next turn">
|
||||
<IconRefresh size={14} className="me-1" />
|
||||
{busy ? "Reading…" : "Read now"}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type DownloadClient, type DownloadItem, type DownloadState } from "../api/client";
|
||||
import { api, type CurrentUser, type DownloadClient, type DownloadItem, type DownloadState } from "../api/client";
|
||||
import ReadNowButton from "../components/ReadNowButton";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
@@ -120,7 +121,7 @@ function ItemsTable({ items, stuck }: { items: DownloadItem[]; stuck: Set<string
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ c }: { c: DownloadClient }) {
|
||||
function Card({ c, canRead, onRead }: { c: DownloadClient; canRead: boolean; onRead: () => void }) {
|
||||
const s = c.state;
|
||||
const stuck = new Set(s?.stuck ?? []);
|
||||
const failedRecent = new Set(s?.failedRecent ?? []);
|
||||
@@ -133,7 +134,10 @@ function Card({ c }: { c: DownloadClient }) {
|
||||
<h3 className="card-title">
|
||||
{c.name} <span className="text-secondary fw-normal">{KIND_NAMES[c.kind]}{s?.version ? ` ${s.version}` : ""}</span> <Badge c={c} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{c.status ? <>read <TimeAgo value={c.status.at} /></> : "not read yet"}</div>
|
||||
<div className="card-actions d-flex align-items-center gap-2 text-secondary small">
|
||||
{c.status ? <>read <TimeAgo value={c.status.at} /></> : "not read yet"}
|
||||
{canRead && c.enabled && <ReadNowButton integrationId={c.id} name={c.name} onDone={onRead} />}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{c.status && !c.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {c.status.error ?? "no answer"}.</div>}
|
||||
@@ -235,10 +239,9 @@ function Card({ c }: { c: DownloadClient }) {
|
||||
}
|
||||
|
||||
/** qBittorrent and SABnzbd: how fast they are going, what is in their queues and in what state, what is stuck or failed, and the room they have. */
|
||||
export default function Downloads() {
|
||||
export default function Downloads({ user }: { user: CurrentUser }) {
|
||||
const [data, setData] = useState<DownloadClient[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.downloads
|
||||
.list()
|
||||
@@ -247,10 +250,12 @@ export default function Downloads() {
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
useEffect(() => {
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
const canRead = user.role === "admin" || user.role === "operator";
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Download clients</h2>
|
||||
@@ -267,7 +272,7 @@ export default function Downloads() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((c) => <Card key={c.id} c={c} />)}
|
||||
{data?.map((c) => <Card key={c.id} c={c} canRead={canRead} onRead={() => void load()} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type RobotAccount } from "../api/client";
|
||||
import { api, type CurrentUser, type RobotAccount } from "../api/client";
|
||||
import ReadNowButton from "../components/ReadNowButton";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
@@ -47,7 +48,7 @@ function Until({ date, cancelled, days }: { date: string | null; cancelled: bool
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ a }: { a: RobotAccount }) {
|
||||
function Card({ a, canRead, onRead }: { a: RobotAccount; canRead: boolean; onRead: () => void }) {
|
||||
const s = a.state;
|
||||
const rescue = s?.servers.filter((v) => v.rescue === true).length ?? 0;
|
||||
const cancelled = (s?.servers.filter((v) => v.cancelled).length ?? 0) + (s?.storageBoxes?.filter((b) => b.cancelled).length ?? 0);
|
||||
@@ -57,7 +58,10 @@ function Card({ a }: { a: RobotAccount }) {
|
||||
<h3 className="card-title">
|
||||
{a.name} <Badge a={a} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}</div>
|
||||
<div className="card-actions d-flex align-items-center gap-2 text-secondary small">
|
||||
{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}
|
||||
{canRead && a.enabled && <ReadNowButton integrationId={a.id} name={a.name} onDone={onRead} />}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{a.status && !a.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {a.status.error ?? "no answer"}.</div>}
|
||||
@@ -183,10 +187,9 @@ function Card({ a }: { a: RobotAccount }) {
|
||||
}
|
||||
|
||||
/** Hetzner Robot: the account's dedicated servers (rescue system, cancellation) and storage boxes. */
|
||||
export default function HetznerRobot() {
|
||||
export default function HetznerRobot({ user }: { user: CurrentUser }) {
|
||||
const [data, setData] = useState<RobotAccount[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.hetznerRobot
|
||||
.list()
|
||||
@@ -195,10 +198,12 @@ export default function HetznerRobot() {
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
useEffect(() => {
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
const canRead = user.role === "admin" || user.role === "operator";
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Hetzner Robot</h2>
|
||||
@@ -215,7 +220,7 @@ export default function HetznerRobot() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} />)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} canRead={canRead} onRead={() => void load()} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { toast } from "../utils/toast";
|
||||
import UptimeRibbon from "../components/UptimeRibbon";
|
||||
import RunbookEntry from "../components/RunbookEntry";
|
||||
import IntegrationInspector from "../components/IntegrationInspector";
|
||||
import ReadNowButton from "../components/ReadNowButton";
|
||||
import { groupOfType, INSPECTABLE, TYPE_GROUPS, TYPE_LABELS, TYPE_PAGES } from "../utils/integrationTypes";
|
||||
|
||||
/** "pve.example.lan" out of "https://pve.example.lan:8006/", or the text itself when it isn't an address. */
|
||||
@@ -291,6 +292,7 @@ function IntegrationsList({ user, tabs }: { user: CurrentUser; tabs: ReactNode }
|
||||
Open
|
||||
</Link>
|
||||
)}
|
||||
{isOperator && i.enabled && <ReadNowButton integrationId={i.id} name={i.name} onDone={loadIntegrations} />}
|
||||
{isAdmin && (
|
||||
<>
|
||||
<button className="btn btn-sm" onClick={() => testIntegration(i)} disabled={testingId === i.id}>
|
||||
|
||||
+11
-6
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type ArrApp } from "../api/client";
|
||||
import { api, type ArrApp, type CurrentUser } from "../api/client";
|
||||
import ReadNowButton from "../components/ReadNowButton";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
@@ -34,7 +35,7 @@ function Tile({ label, value, sub, warn }: { label: string; value: string; sub?:
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ a }: { a: ArrApp }) {
|
||||
function Card({ a, canRead, onRead }: { a: ArrApp; canRead: boolean; onRead: () => void }) {
|
||||
const s = a.state;
|
||||
const stuck = new Set(s?.stuck ?? []);
|
||||
const queue = s?.queue ?? null;
|
||||
@@ -47,7 +48,10 @@ function Card({ a }: { a: ArrApp }) {
|
||||
<h3 className="card-title">
|
||||
{a.name} <span className="text-secondary fw-normal">{KIND_NAMES[a.kind]}{s?.version ? ` ${s.version}` : ""}</span> <Badge a={a} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}</div>
|
||||
<div className="card-actions d-flex align-items-center gap-2 text-secondary small">
|
||||
{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}
|
||||
{canRead && a.enabled && <ReadNowButton integrationId={a.id} name={a.name} onDone={onRead} />}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{a.status && !a.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {a.status.error ?? "no answer"}.</div>}
|
||||
@@ -194,10 +198,9 @@ function Card({ a }: { a: ArrApp }) {
|
||||
}
|
||||
|
||||
/** Sonarr, Radarr and Prowlarr: what each says is wrong, the downloads that are stuck, the disks they fill and the indexers that have failed. */
|
||||
export default function Media() {
|
||||
export default function Media({ user }: { user: CurrentUser }) {
|
||||
const [data, setData] = useState<ArrApp[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.arr
|
||||
.list()
|
||||
@@ -206,10 +209,12 @@ export default function Media() {
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
useEffect(() => {
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
const canRead = user.role === "admin" || user.role === "operator";
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Media managers</h2>
|
||||
@@ -226,7 +231,7 @@ export default function Media() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} />)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} canRead={canRead} onRead={() => void load()} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user