Notify when a game server is turned on or off
A read of a Fragnet account that shows a server on (running or starting) after it was off, or off (stopped or stopping) after it was on, sends one message through the configured channels and routing rules, a line for each server. A server first seen, one whose state is unknown and one being installed or moved say nothing. Switch: Settings -> Notifications -> What to send (on by default). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d653f5a80
commit
5c6ccc0a4b
10 files changed
+193
-5
No files matched your search
+1
-1
@@ -475,7 +475,7 @@ osTicket's API cannot close a ticket, so this is the one place in the app that *
|
||||
- **What it does:** every **five minutes** each game server of the account (also those shared with it) is read — the game (the panel's *egg*, for example *Minecraft: Paper*), every IP address and port, SFTP, the plan's memory, disk and CPU limits and its room for backups and databases, whether it is running, what it uses, its backups, schedules and databases. **Infrastructure → Game servers** shows them; a row opens to show every address (click to copy), the backups, the schedules and a link to the server in the game panel.
|
||||
- **Power:** operators can **start, stop, restart and kill** a server from the page (a confirmation first; kill says it loses unsaved progress). It sends exactly that signal to the panel and writes it to the audit log (`start_game_server` …). The page reads again a few seconds later. Beside backups, it is the only thing this integration ever sends but reads, and only a server the last read found can be signalled.
|
||||
- **Back up now:** operators can ask for a backup of a server whose plan has room for backups (*Back up* on its row, or *Back up now* beside its backups; a confirmation first, which says how many the plan allows and how many are made). It is `POST /api/client/servers/{id}/backups` with a name that says it was asked for here (`Homelab Manager — 2026-11-04 14:30 UTC`) and nothing else — no file is left out, nothing is locked. The panel makes it in the background; the page reads the account again after a few seconds and then every twenty seconds until the backup has finished. It is written to the audit log (`backup_game_server`, with the backup's id). **Refused here before the panel is asked:** a plan with no room for backups, a server that is suspended or being installed, one for which a backup is already being made (one that has been "being made" for more than two hours is taken to be lost and does not count), and the same server asked again within 30 seconds (HTTP 429). **Refused by the panel, and said in its words:** a server at the number of backups its plan allows (delete one in the panel first — the app never deletes a backup), the panel's own limit of a couple of backups in ten minutes (429), an account that may not make backups on a shared server (403 — it needs the *Backups → Create* permission) and a server that is busy (409). A refusal costs no wait before the next try.
|
||||
- **Alerts** (source *Fragnet*; held back by maintenance on the integration): a server whose plan allows backups and whose **newest successful backup is older** than the limit (or has none, once the app has known it for that long; a backup that failed does not count, and the message says when the newest attempt failed); **disk** over the limit (critical from 98%); **memory** over the limit while it runs. A server that is **stopped** is not an alert. See [MONITORING.md](docs/MONITORING.md#game-servers-fragnet).
|
||||
- **Alerts** (source *Fragnet*; held back by maintenance on the integration): a server whose plan allows backups and whose **newest successful backup is older** than the limit (or has none, once the app has known it for that long; a backup that failed does not count, and the message says when the newest attempt failed); **disk** over the limit (critical from 98%); **memory** over the limit while it runs. A server that is **stopped** is not an alert. (When one is turned on or off, a notification says so: [NOTIFICATIONS.md](NOTIFICATIONS.md).) See [MONITORING.md](docs/MONITORING.md#game-servers-fragnet).
|
||||
- If the panel cannot be read for 20 minutes its alerts are neither raised nor cleared, the Alerts page says it could not check, and the integration is raised as failing like any other. A part that cannot be read for one server (a sub-user without the *database* permission, say) is shown as *could not be listed*, never as none.
|
||||
- `/metrics` has `homelab_fragnet_server_running`, `homelab_fragnet_disk_used_bytes`, `homelab_fragnet_disk_limit_bytes`, `homelab_fragnet_memory_used_bytes`, `homelab_fragnet_memory_limit_bytes` and `homelab_fragnet_newest_backup_timestamp_seconds`.
|
||||
- **Not verified against a live account** — the endpoints (`/api/client?include=egg,allocations`, `/servers/{id}/resources`, `…/backups`, `…/schedules`, `…/databases`, `POST …/power`) and their fields are as Pterodactyl's own source and Fragnet's documentation have them, and the reader is tried against a pretend panel. Fragnet's fork may differ: the game is left out (shown as the Docker image) if the panel does not send the egg, and a panel that refuses the extra `include` is asked again plainly. Disk and memory limits are in MB as the panel counts them and shown in binary units. What the servers cost is not in the API: add it under Records → Costs.
|
||||
|
||||
@@ -132,6 +132,7 @@ until the next scheduled time to catch up.
|
||||
| Docker containers broken | *Warn when a Docker container is broken* | A container keeps restarting, is unhealthy, stopped unexpectedly or never started, or a Docker host cannot be reached, as Dockhand reports on the 15-minute pass — announced once with the server problems (*Server offline, disk nearly full …*, `healthAlerts`), with a recovery message when it runs again. See [MONITORING.md](docs/MONITORING.md#docker-containers-that-are-broken). | Its own switch; *Containers to leave alone* |
|
||||
| Docker image updates | *Docker image update available* | Any container (across every enabled Dockhand integration) has an image update available, per Dockhand's own cached update-check results — this doesn't trigger a fresh registry lookup, just reads what the Docker page itself would show. | Not configurable (reflects Dockhand's own check interval) |
|
||||
| Proxmox backups — gone stale | *(same toggle as the Proxmox backup check)* | Once a day with the other backup messages: a guest whose newest backup (on Proxmox or a Backup Server) is older than the limit. Guests under maintenance (on the server or the Proxmox integration) are left out. | Settings → Notifications → **A guest's backup is too old after** (default 48 h; 0 off); a server can have its own limit on its page |
|
||||
| Game server turned on or off | *A game server (Fragnet) was turned on or off* | A read of a Fragnet account shows a game server **on** (running or starting) when the one before showed it off, or **off** (stopped or stopping) when it showed it on — however it came about: someone pressed Start or Stop, the game crashed, the host stopped it. One message for what changed in one read, a line for each server (name, game, account); *starting* counts as on, so a start is said once. A server met for the first time, one whose state could not be read and one being installed or moved say nothing. Goes through the routing rules as a *services* notification and waits for quiet hours like any other that is not critical; the accounts are read every five minutes, so it can be that late. On unless switched off. | Settings → Notifications → What to send |
|
||||
| Update run finished | *An update run you started finished, or didn't* | An update run started from the Updates page ended: what is still waiting and whether a restart is due, or why it failed. Sent at once (not held for the daily check). | Settings → Notifications → What to send |
|
||||
| Proxmox backups | *Proxmox backup failed or a guest has no coverage* | Two independent conditions, both under this one toggle: (1) a node's most recent `vzdump` backup task (across every enabled Proxmox integration) didn't succeed; (2) a VM/LXC isn't covered by any enabled backup job at all. | Not configurable |
|
||||
| Proxmox Backup Server verification | *Proxmox Backup Server snapshot failed verification* | Across every enabled PBS integration: any datastore has at least one stored snapshot whose verification state is "failed", or a datastore couldn't be read at all (e.g. a permissions problem). This is distinct from the Proxmox check above — PVE only knows a backup *ran*, PBS is the only place that knows whether the stored data still verifies. | Not configurable |
|
||||
|
||||
@@ -349,6 +349,8 @@ An integration of type *Fragnet game servers* ([INTEGRATIONS.md](../INTEGRATIONS
|
||||
|
||||
Each of the three can be **switched off on its own** in the integration's settings (Administration → Integrations → edit: *Do not alert about disk space / memory / backups*) — for example to hear about disk and backups but not memory. The page keeps showing the figures; a bar for something switched off is blue instead of green, yellow or red, and the backups tile says *not judged*. There is no CPU alert: the CPU is shown on the server's row only.
|
||||
|
||||
When a server is **turned on or off** it is not an alert but a **notification** — see [NOTIFICATIONS.md](../NOTIFICATIONS.md): one message, through the configured channels, when a read shows it changed since the last one (switch it off under Settings → Notifications → What to send).
|
||||
|
||||
A server that is **stopped** is not an alert (game servers are often stopped on purpose), and one that is suspended or being installed is not judged. "Since when" a server has been in its state is **when the app first saw it** in a read. Maintenance on the integration holds the alerts; a reading older than 20 minutes is not believed (they are neither raised nor cleared, and the Alerts page says it could not check). `/metrics` has the running state, disk and memory against their limits and when the newest backup finished.
|
||||
|
||||
## AdGuard Home
|
||||
|
||||
@@ -127,6 +127,7 @@ const updateSchema = z.object({
|
||||
healthAlerts: z.boolean(),
|
||||
automationAlerts: z.boolean(),
|
||||
updateRunResults: z.boolean(),
|
||||
gameServerPower: z.boolean(),
|
||||
domainExpiryCheck: z.boolean(),
|
||||
secretCheckTime: z.string().regex(/^\d{2}:\d{2}$/),
|
||||
timezone: z.string(),
|
||||
|
||||
@@ -6,12 +6,17 @@
|
||||
* not judged), or that has none and has been known for longer than that; a server can be left out by name (`ignoreBackups`). **Disk or memory nearly full** — over `fullPercent` (90 unless you
|
||||
* say otherwise) of its limit; memory is judged only while it runs. A server that is stopped is not an alert: game servers are often stopped on purpose. A panel that cannot be reached shows
|
||||
* as the integration being down, like any other. "Since when" a server has been in its state is what this app saw: the time of the first read that showed it.
|
||||
*
|
||||
* Not an alert but a message: when a read shows a game server **turned on or off** since the read before (however it happened: someone pressed Start, it crashed, the host stopped it), one notification
|
||||
* goes through the configured channels (and routing rules), with a line for each server that changed in that read. A server met for the first time says nothing; neither does one whose state could
|
||||
* not be read, or that is being installed or moved; "starting" counts as on and "stopping" as off, so a start is said when it begins and not again when it has finished.
|
||||
*/
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { fragnetState, integrations } from "../db/schema.js";
|
||||
import { createFragnetAdapter, type FragnetRead, type FragnetServer } from "../integrations/fragnet/adapter.js";
|
||||
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
|
||||
import { notifyGameServerPower } from "./notify.js";
|
||||
import { getInternalFlag, setInternalFlag } from "./settingsStore.js";
|
||||
|
||||
export const SYNC_INTERVAL_MS = 5 * 60_000;
|
||||
@@ -79,11 +84,40 @@ export function carryTimes(servers: FragnetServer[], previous: StoredServer[], n
|
||||
});
|
||||
}
|
||||
|
||||
/** Writes down one read, replacing the last (and carrying what was seen between reads). */
|
||||
export async function storeRead(integrationId: number, r: FragnetRead, now: Date = new Date()): Promise<void> {
|
||||
/** Whether a panel state means on (running, starting) or off (offline, stopping); null when it says neither (unknown: the resources could not be read). */
|
||||
export function powerOf(state: string): boolean | null {
|
||||
return state === "running" || state === "starting" ? true : state === "offline" || state === "stopping" ? false : null;
|
||||
}
|
||||
|
||||
export interface PowerChange {
|
||||
id: string;
|
||||
name: string;
|
||||
game: string | null;
|
||||
on: boolean;
|
||||
}
|
||||
|
||||
/** Pure: the servers that were turned on or off between the last read and this one. A server not seen before, one whose state is unknown before or now, and one being installed or moved are left out. */
|
||||
export function powerChanges(previous: Pick<StoredServer, "id" | "state">[], current: Pick<FragnetServer, "id" | "name" | "game" | "state" | "installing" | "transferring">[]): PowerChange[] {
|
||||
const before = new Map(previous.map((p) => [p.id, powerOf(p.state)]));
|
||||
const out: PowerChange[] = [];
|
||||
for (const s of current) {
|
||||
if (s.installing || s.transferring) continue;
|
||||
const was = before.get(s.id);
|
||||
const now = powerOf(s.state);
|
||||
if (was === undefined || was === null || now === null || was === now) continue;
|
||||
out.push({ id: s.id, name: s.name, game: s.game, on: now });
|
||||
}
|
||||
return out.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
/** Writes down one read, replacing the last (and carrying what was seen between reads). Says which servers were turned on or off since the read before. */
|
||||
export async function storeRead(integrationId: number, r: FragnetRead, now: Date = new Date()): Promise<PowerChange[]> {
|
||||
const [previous] = await db.select({ servers: fragnetState.servers }).from(fragnetState).where(eq(fragnetState.integrationId, integrationId)).limit(1);
|
||||
const values = { servers: JSON.stringify(carryTimes(r.servers, previous ? serversOf(previous) : [], now)), updatedAt: now.toISOString() };
|
||||
const before = previous ? serversOf(previous) : [];
|
||||
const values = { servers: JSON.stringify(carryTimes(r.servers, before, now)), updatedAt: now.toISOString() };
|
||||
await db.insert(fragnetState).values({ integrationId, ...values }).onConflictDoUpdate({ target: fragnetState.integrationId, set: values });
|
||||
// An account read for the first time has nothing to compare with: nothing is said.
|
||||
return previous ? powerChanges(before, r.servers) : [];
|
||||
}
|
||||
|
||||
/** Reads one account and stores it. Never throws: how it went is the answer, and what was stored is left alone when it failed. */
|
||||
@@ -93,8 +127,16 @@ export async function syncFragnet(integrationId: number, now: Date = new Date(),
|
||||
const loaded = await loadIntegrationConfig(integrationId);
|
||||
if (!loaded || loaded.integration.type !== "fragnet") throw new Error("not a Fragnet integration");
|
||||
const result = await (read ? read(loaded.config) : createFragnetAdapter(loaded.config as never).read());
|
||||
await storeRead(integrationId, result, now);
|
||||
const changes = await storeRead(integrationId, result, now);
|
||||
status = { at: now.toISOString(), ok: true, error: null };
|
||||
// Said after it is stored and recorded as read: a message that fails to send must not make the read look failed.
|
||||
if (changes.length > 0) {
|
||||
try {
|
||||
await notifyGameServerPower(changes.map((c) => ({ integrationName: loaded.integration.name, serverName: c.name, game: c.game, on: c.on })));
|
||||
} catch (err) {
|
||||
console.error("[fragnet] couldn't send the power notification:", err);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
const previous = (await readStatuses())[String(integrationId)];
|
||||
status = { at: previous?.at ?? now.toISOString(), ok: false, error: err instanceof Error ? err.message : String(err) };
|
||||
|
||||
@@ -535,6 +535,16 @@ export async function notifyUpdateRunFinished(run: { serverName: string; templat
|
||||
);
|
||||
}
|
||||
|
||||
/** A game server was turned on or off: one message for what changed in one read, a line for each. Held for quiet hours like the rest (it is not critical). */
|
||||
export async function notifyGameServerPower(changes: { integrationName: string; serverName: string; game: string | null; on: boolean }[]): Promise<void> {
|
||||
if (changes.length === 0) return;
|
||||
if (!(await eventEnabled("gameServerPower"))) return;
|
||||
const ons = changes.filter((c) => c.on).length;
|
||||
const title = ons === changes.length ? (changes.length === 1 ? `Homelab Manager — ${changes[0].serverName} turned on` : "Homelab Manager — Game servers turned on") : ons === 0 ? (changes.length === 1 ? `Homelab Manager — ${changes[0].serverName} turned off` : "Homelab Manager — Game servers turned off") : "Homelab Manager — Game servers turned on or off";
|
||||
const lines = changes.map((c) => `${c.serverName}${c.game ? ` (${c.game})` : ""} [${c.integrationName}]: now ${c.on ? "on" : "off"}`);
|
||||
await notify(title, lines.join("\n"), { category: "services", severity: "warning" });
|
||||
}
|
||||
|
||||
/** How a patch plan's run ended: one message, with a line for each server. Held back or sent with the other update-run results. */
|
||||
export async function notifyPatchPlanFinished(run: { planName: string; ok: boolean; message: string; lines: string[] }): Promise<void> {
|
||||
if (!(await eventEnabled("updateRunResults"))) return;
|
||||
|
||||
@@ -82,6 +82,8 @@ export interface NotificationEvents {
|
||||
automationAlerts: boolean;
|
||||
/** How an update run started from the Updates page ended: what is still waiting, whether a restart is due, or why it failed. */
|
||||
updateRunResults: boolean;
|
||||
/** A game server (Fragnet) was turned on or off: said once, when the app sees it change between two reads. */
|
||||
gameServerPower: boolean;
|
||||
/** Daily reminder while a domain registration is close to expiring or has expired. */
|
||||
domainExpiryCheck: boolean;
|
||||
secretCheckTime: string; // "HH:MM" — shared by the secret-expiry, Tailscale key-expiry, Docker update, and Proxmox backup checks
|
||||
@@ -348,6 +350,7 @@ const DEFAULTS: AppSettings = {
|
||||
healthAlerts: true,
|
||||
automationAlerts: true,
|
||||
updateRunResults: true,
|
||||
gameServerPower: true,
|
||||
domainExpiryCheck: true,
|
||||
secretCheckTime: "08:00",
|
||||
timezone: "UTC",
|
||||
|
||||
@@ -27,6 +27,7 @@ const fn = await import("../src/services/fragnetSync.js");
|
||||
const { evaluateHealth, collectSnapshot } = await import("../src/services/healthMonitor.js");
|
||||
const { subjectOfConditionKey } = await import("../src/services/maintenance.js");
|
||||
const { getAlerts, invalidateAlertsCache } = await import("../src/services/alerts.js");
|
||||
const { updateSettings } = await import("../src/services/settingsStore.js");
|
||||
const { fragnetRouter } = await import("../src/routes/fragnet.js");
|
||||
const { buildMetrics } = await import("../src/services/metrics.js");
|
||||
const { setInternalFlag } = await import("../src/services/settingsStore.js");
|
||||
@@ -440,6 +441,131 @@ describe("what is stored", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("a game server turned on or off", () => {
|
||||
const prev = (state: string, id = "abcd1234") => ({ id, state });
|
||||
const cur = (extra: Partial<Srv> = {}) => server(extra);
|
||||
|
||||
describe("what counts", () => {
|
||||
test("running and starting are on; offline and stopping are off; anything else is neither", () => {
|
||||
assert.deepEqual(["running", "starting", "offline", "stopping", "unknown", "", "suspended"].map(fn.powerOf), [true, true, false, false, null, null, null]);
|
||||
});
|
||||
|
||||
test("on to off and off to on are changes, with the name and the game; the same state is not", () => {
|
||||
assert.deepEqual(fn.powerChanges([prev("offline")], [cur({ state: "running" })]), [{ id: "abcd1234", name: "survival", game: "Minecraft: Paper", on: true }]);
|
||||
assert.deepEqual(fn.powerChanges([prev("running")], [cur({ state: "offline" })]).map((c) => c.on), [false]);
|
||||
assert.deepEqual(fn.powerChanges([prev("running")], [cur({ state: "running" })]), []);
|
||||
assert.deepEqual(fn.powerChanges([prev("offline")], [cur({ state: "offline" })]), []);
|
||||
});
|
||||
|
||||
test("starting is on and stopping is off, so a start is said once: when it begins, not again when it has finished", () => {
|
||||
assert.deepEqual(fn.powerChanges([prev("offline")], [cur({ state: "starting" })]).map((c) => c.on), [true]);
|
||||
assert.deepEqual(fn.powerChanges([prev("starting")], [cur({ state: "running" })]), []);
|
||||
assert.deepEqual(fn.powerChanges([prev("running")], [cur({ state: "stopping" })]).map((c) => c.on), [false]);
|
||||
assert.deepEqual(fn.powerChanges([prev("stopping")], [cur({ state: "offline" })]), []);
|
||||
});
|
||||
|
||||
test("a server not seen before, one whose state was or is unknown, and one being installed or moved say nothing", () => {
|
||||
assert.deepEqual(fn.powerChanges([], [cur()]), []);
|
||||
assert.deepEqual(fn.powerChanges([prev("unknown")], [cur({ state: "running" })]), []);
|
||||
assert.deepEqual(fn.powerChanges([prev("running")], [cur({ state: "unknown" })]), []);
|
||||
assert.deepEqual(fn.powerChanges([prev("offline")], [cur({ state: "running", installing: true })]), []);
|
||||
assert.deepEqual(fn.powerChanges([prev("offline")], [cur({ state: "running", transferring: true })]), []);
|
||||
});
|
||||
|
||||
test("each server is judged on its own, and they come by name", () => {
|
||||
const out = fn.powerChanges([prev("running", "a1"), prev("offline", "b2"), prev("running", "c3")], [cur({ id: "c3", name: "rust", state: "offline" }), cur({ id: "a1", name: "ark", state: "running" }), cur({ id: "b2", name: "valheim", state: "running" })]);
|
||||
assert.deepEqual(out.map((c) => [c.name, c.on]), [["rust", false], ["valheim", true]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when a read is stored", () => {
|
||||
let id = 0;
|
||||
before(async () => {
|
||||
id = (await db.insert(integrations).values({ type: "fragnet", name: "Power account", baseUrl: "https://panel.fragnet.net", config: JSON.stringify({}) }).returning({ id: integrations.id }))[0].id;
|
||||
});
|
||||
after(async () => {
|
||||
await fn.forgetFragnet(id);
|
||||
await db.delete(integrations).where(eq(integrations.id, id));
|
||||
});
|
||||
|
||||
test("the first read of an account says nothing; the next says what changed since", async () => {
|
||||
assert.deepEqual(await fn.storeRead(id, read(server({ state: "running" })), new Date()), []);
|
||||
assert.deepEqual(await fn.storeRead(id, read(server({ state: "running" })), new Date()), []);
|
||||
const changes = await fn.storeRead(id, read(server({ state: "offline" })), new Date());
|
||||
assert.deepEqual(changes.map((c) => [c.name, c.on]), [["survival", false]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the message", () => {
|
||||
let id = 0;
|
||||
let hook: Server;
|
||||
const got: string[] = [];
|
||||
before(async () => {
|
||||
hook = createHttpServer((req, res) => {
|
||||
let body = "";
|
||||
req.on("data", (c) => (body += c));
|
||||
req.on("end", () => {
|
||||
got.push((JSON.parse(body) as { content: string }).content);
|
||||
res.writeHead(200).end("ok");
|
||||
});
|
||||
});
|
||||
await new Promise<void>((resolve) => hook.listen(0, "127.0.0.1", resolve));
|
||||
await updateSettings({ webhook: { enabled: true, url: `http://127.0.0.1:${(hook.address() as AddressInfo).port}/hook` } });
|
||||
id = (await db.insert(integrations).values({ type: "fragnet", name: "Fragnet account", baseUrl: "https://panel.fragnet.net", config: JSON.stringify({}) }).returning({ id: integrations.id }))[0].id;
|
||||
});
|
||||
after(async () => {
|
||||
hook.close();
|
||||
await updateSettings({ webhook: { enabled: false }, notifications: { gameServerPower: true } });
|
||||
await fn.forgetFragnet(id);
|
||||
await db.delete(integrations).where(eq(integrations.id, id));
|
||||
});
|
||||
const sync = (...servers: Srv[]) => fn.syncFragnet(id, new Date(), async () => read(...servers));
|
||||
|
||||
test("a server turned off is said through the configured channels, with its name, game and account", async () => {
|
||||
await sync(server({ state: "running" }));
|
||||
assert.equal(got.length, 0, "the first read says nothing");
|
||||
await sync(server({ state: "offline" }));
|
||||
assert.equal(got.length, 1);
|
||||
assert.match(got[0], /^\*\*Homelab Manager — survival turned off\*\*\nsurvival \(Minecraft: Paper\) \[Fragnet account\]: now off$/);
|
||||
});
|
||||
|
||||
test("and turned on again, in the same words", async () => {
|
||||
await sync(server({ state: "starting" }));
|
||||
assert.equal(got.length, 2);
|
||||
assert.match(got[1], /survival turned on\*\*\nsurvival \(Minecraft: Paper\) \[Fragnet account\]: now on$/);
|
||||
await sync(server({ state: "running" }));
|
||||
assert.equal(got.length, 2, "the start finishing is not another change");
|
||||
});
|
||||
|
||||
test("several that changed in one read are one message with a line each, and mixed ones say so", async () => {
|
||||
await sync(server({ id: "aaaa1111", name: "ark", state: "running" }), server({ id: "bbbb2222", name: "rust", state: "offline" }));
|
||||
got.length = 0;
|
||||
await sync(server({ id: "aaaa1111", name: "ark", state: "offline" }), server({ id: "bbbb2222", name: "rust", state: "running" }));
|
||||
assert.equal(got.length, 1);
|
||||
assert.match(got[0], /^\*\*Homelab Manager — Game servers turned on or off\*\*\nark \(Minecraft: Paper\) \[Fragnet account\]: now off\nrust \(Minecraft: Paper\) \[Fragnet account\]: now on$/);
|
||||
});
|
||||
|
||||
test("a server that is unchanged, or a read that failed, says nothing", async () => {
|
||||
got.length = 0;
|
||||
await sync(server({ id: "aaaa1111", name: "ark", state: "offline" }), server({ id: "bbbb2222", name: "rust", state: "running" }));
|
||||
await fn.syncFragnet(id, new Date(), async () => {
|
||||
throw new Error("panel down");
|
||||
});
|
||||
assert.equal(got.length, 0);
|
||||
});
|
||||
|
||||
test("it is off with its switch in Settings → Notifications → What to send, and a failing channel does not make the read fail", async () => {
|
||||
await updateSettings({ notifications: { gameServerPower: false } });
|
||||
got.length = 0;
|
||||
await sync(server({ id: "aaaa1111", name: "ark", state: "running" }), server({ id: "bbbb2222", name: "rust", state: "offline" }));
|
||||
assert.equal(got.length, 0, "switched off");
|
||||
await updateSettings({ notifications: { gameServerPower: true }, webhook: { enabled: true, url: "http://127.0.0.1:1/nothing-listens-here" } });
|
||||
const status = await sync(server({ id: "aaaa1111", name: "ark", state: "offline" }), server({ id: "bbbb2222", name: "rust", state: "offline" }));
|
||||
assert.equal(status.ok, true, "the read counts as done whatever happened to the message");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("the health pass, the page, the power signals and /metrics", () => {
|
||||
let fgId = 0;
|
||||
let app: Server;
|
||||
|
||||
@@ -549,6 +549,7 @@ export interface NotificationEvents {
|
||||
healthAlerts: boolean;
|
||||
automationAlerts: boolean;
|
||||
updateRunResults: boolean;
|
||||
gameServerPower: boolean;
|
||||
domainExpiryCheck: boolean;
|
||||
secretCheckTime: string;
|
||||
timezone: string;
|
||||
|
||||
@@ -70,6 +70,7 @@ const DEFAULT_NOTIFICATIONS: NotificationEvents = {
|
||||
healthAlerts: true,
|
||||
automationAlerts: true,
|
||||
updateRunResults: true,
|
||||
gameServerPower: true,
|
||||
domainExpiryCheck: true,
|
||||
secretCheckTime: "08:00",
|
||||
timezone: "UTC",
|
||||
@@ -1084,6 +1085,7 @@ export default function NotificationSettings() {
|
||||
/>
|
||||
<div className="mt-3">{toggle("automationAlerts", "Semaphore template or Gitea workflow run failed")}</div>
|
||||
<div className="mt-3">{toggle("updateRunResults", "An update run you started finished, or didn't")}</div>
|
||||
<div className="mt-3">{toggle("gameServerPower", "A game server (Fragnet) was turned on or off")}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user