Let each kind of game server alert be switched off
Three tick boxes on the Fragnet integration: do not alert about disk space, memory or backups. The page still shows the figures (a switched-off bar is blue and the backups tile says not judged); /metrics is unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4a7b1494c8
commit
1ef686d1ba
8 files changed
+58
-15
No files matched your search
@@ -182,6 +182,9 @@ export const INTEGRATION_FIELDS: Partial<Record<IntegrationType, IntegrationFiel
|
||||
{ key: "backupDays", label: "Warn when the newest backup is older than, days (optional)", secret: false, optional: true, placeholder: "7 — 0 to not judge backups" },
|
||||
{ key: "fullPercent", label: "Warn when disk or memory is fuller than, % (optional)", secret: false, optional: true, placeholder: "90" },
|
||||
{ key: "ignoreBackups", label: "Servers whose backups are not judged (optional)", secret: false, optional: true, placeholder: "names, separated by commas" },
|
||||
{ key: "muteDisk", label: "Do not alert about disk space (the page still shows it)", secret: false, optional: true, type: "checkbox" },
|
||||
{ key: "muteMemory", label: "Do not alert about memory (the page still shows it)", secret: false, optional: true, type: "checkbox" },
|
||||
{ key: "muteBackups", label: "Do not alert about backups (the page still shows them)", secret: false, optional: true, type: "checkbox" },
|
||||
],
|
||||
netbox: [
|
||||
{ key: "url", label: "NetBox URL", secret: false, placeholder: "https://netbox.example.lan" },
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Fragnet game server adapter. Fragnet's game panel (https://panel.fragnet.net) is a fork of Pterodactyl, so this speaks Pterodactyl's *client* API
|
||||
* (https://dashflo.net/docs/api/pterodactyl/v1/#req_…, base `/api/client`). Config: token (the account's API key — the panel's profile menu → API Credentials; it starts with **ptlc_**, an
|
||||
* Application key, ptla_, does not work), optionally url (the panel; https://panel.fragnet.net when left out) and the three that the alerts use (see services/fragnetSync.ts): backupDays,
|
||||
* fullPercent, ignoreBackups.
|
||||
* fullPercent, ignoreBackups, and muteDisk, muteMemory, muteBackups (each switches one kind of alert off).
|
||||
*
|
||||
* Reading: the servers of the account (`GET /api/client`, paged, with the game — the egg — and the addresses) and, for each, `…/resources` (running or not, memory, CPU, disk, uptime), `…/backups`,
|
||||
* `…/schedules` and `…/databases`. A part that cannot be read (a sub-user without that permission gets a 403) is null for that server, which is not the same as none. The only thing ever
|
||||
|
||||
@@ -135,8 +135,13 @@ export interface FragnetOptions {
|
||||
fullPercent: number;
|
||||
/** Names (lower case) of the servers whose backups are not judged. */
|
||||
ignoreBackups: string[];
|
||||
/** Which kinds of alert are raised at all: each can be switched off in the integration's settings (everything is still shown on the page). */
|
||||
alerts: { backups: boolean; disk: boolean; memory: boolean };
|
||||
}
|
||||
|
||||
/** A checkbox as the settings keep it: true, or the text "true". */
|
||||
const ticked = (v: unknown): boolean => v === true || v === "true";
|
||||
|
||||
const positive = (v: unknown): number | null => {
|
||||
const n = typeof v === "number" ? v : typeof v === "string" && v.trim() !== "" ? Number(v.trim().replace(",", ".")) : NaN;
|
||||
return Number.isFinite(n) && n >= 0 ? n : null;
|
||||
@@ -150,6 +155,7 @@ export function optionsOf(config: Record<string, unknown> | null | undefined): F
|
||||
backupDays: days === null ? DEFAULT_BACKUP_DAYS : days,
|
||||
fullPercent: percent === null || percent < 1 ? DEFAULT_FULL_PERCENT : Math.min(100, percent),
|
||||
ignoreBackups: ignore.split(/[,\n]/).map((s) => s.trim().toLowerCase()).filter(Boolean),
|
||||
alerts: { backups: !ticked(config?.muteBackups), disk: !ticked(config?.muteDisk), memory: !ticked(config?.muteMemory) },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -191,7 +197,7 @@ export function fragnetProblems(id: number, name: string, servers: StoredServer[
|
||||
for (const s of [...servers].sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
// A server being installed or suspended is in no state to judge.
|
||||
if (s.suspended || s.installing) continue;
|
||||
if (options.backupDays > 0 && mayHaveBackups(s) && !options.ignoreBackups.includes(s.name.toLowerCase())) {
|
||||
if (options.alerts.backups && options.backupDays > 0 && mayHaveBackups(s) && !options.ignoreBackups.includes(s.name.toLowerCase())) {
|
||||
const newest = newestBackup(s);
|
||||
if (newest !== null) {
|
||||
const window = options.backupDays * DAY;
|
||||
@@ -207,7 +213,7 @@ export function fragnetProblems(id: number, name: string, servers: StoredServer[
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s.usage !== null && s.diskLimitMb !== null && s.diskLimitMb > 0) {
|
||||
if (options.alerts.disk && s.usage !== null && s.diskLimitMb !== null && s.diskLimitMb > 0) {
|
||||
const share = s.usage.diskBytes / (s.diskLimitMb * 1024 ** 2);
|
||||
if (share >= limit) {
|
||||
out.push({
|
||||
@@ -218,7 +224,7 @@ export function fragnetProblems(id: number, name: string, servers: StoredServer[
|
||||
});
|
||||
}
|
||||
}
|
||||
if (s.state === "running" && s.usage !== null && s.memoryLimitMb !== null && s.memoryLimitMb > 0) {
|
||||
if (options.alerts.memory && s.state === "running" && s.usage !== null && s.memoryLimitMb !== null && s.memoryLimitMb > 0) {
|
||||
const share = s.usage.memoryBytes / (s.memoryLimitMb * 1024 ** 2);
|
||||
if (share >= limit) {
|
||||
out.push({
|
||||
|
||||
Reference in new issue
Block a user