Add runbooks, backup coverage, inventory, roles from groups, Prometheus metrics and event webhooks
- Runbooks: notes per server/integration, shown next to matching alerts - Backup coverage page across Proxmox and PBS, with a digest section - Hardware inventory with warranty, power and running cost - Authentik group to role mapping with preview and safeguards - /metrics (bearer token) and signed outgoing event webhooks - Docs: README, DATABASE, NOTIFICATIONS, ROLES and new API.md Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c36e2092c5
commit
c17e9aa140
55 files changed
+7177
-27
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import type { Asset } from "../api/client";
|
||||
|
||||
// The same arithmetic the server uses for the weekly digest, so a page and the digest never disagree about a warranty.
|
||||
|
||||
export type WarrantyState = "none" | "ok" | "expiring" | "expired";
|
||||
export const WARRANTY_WARN_DAYS = 90;
|
||||
|
||||
/** Whole days from today (UTC) to the end of a warranty; negative once it has ended. Null without one. */
|
||||
export function warrantyDays(warrantyUntil: string | null, now: Date = new Date()): number | null {
|
||||
if (!warrantyUntil) return null;
|
||||
const end = Date.parse(`${warrantyUntil}T00:00:00Z`);
|
||||
if (!Number.isFinite(end)) return null;
|
||||
const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
||||
return Math.round((end - today) / 86_400_000);
|
||||
}
|
||||
|
||||
export function warrantyState(warrantyUntil: string | null, now: Date = new Date()): WarrantyState {
|
||||
const days = warrantyDays(warrantyUntil, now);
|
||||
if (days === null) return "none";
|
||||
if (days < 0) return "expired";
|
||||
return days <= WARRANTY_WARN_DAYS ? "expiring" : "ok";
|
||||
}
|
||||
|
||||
export const yearlyKwh = (watts: number) => Math.round((watts / 1000) * 24 * 365 * 100) / 100;
|
||||
|
||||
export function yearlyCost(watts: number | null, pricePerKwh: number | null): number | null {
|
||||
if (watts === null || watts <= 0 || pricePerKwh === null || !(pricePerKwh > 0)) return null;
|
||||
return Math.round(yearlyKwh(watts) * pricePerKwh);
|
||||
}
|
||||
|
||||
export const KIND_LABELS: Record<Asset["kind"], string> = {
|
||||
server: "Server",
|
||||
storage: "Storage",
|
||||
network: "Network",
|
||||
power: "Power",
|
||||
client: "Client",
|
||||
other: "Other",
|
||||
};
|
||||
|
||||
export const KIND_HINTS: Record<Asset["kind"], string> = {
|
||||
server: "a server or mini PC",
|
||||
storage: "a NAS or disk shelf",
|
||||
network: "a switch, router or access point",
|
||||
power: "a UPS or power strip",
|
||||
client: "a PC, laptop or Raspberry Pi",
|
||||
other: "anything else",
|
||||
};
|
||||
|
||||
/** "12 340 kr" or "12 340": a figure in the chosen currency, which may be blank. */
|
||||
export function money(amount: number, currency: string): string {
|
||||
const n = new Intl.NumberFormat("sv-SE", { maximumFractionDigits: 0 }).format(amount);
|
||||
return currency ? `${n} ${currency}` : n;
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
// search words, the status or tag chosen, the sort — so a view can also be bookmarked or sent to someone, and it needs no storage of its own.
|
||||
|
||||
/** The address parts that narrow or order a table. Anything else in an address (an id to edit, say) is not part of a view. */
|
||||
const VIEW_PARAMS = ["q", "status", "tag", "sort", "dir"] as const;
|
||||
const VIEW_PARAMS = ["q", "status", "kind", "tag", "sort", "dir"] as const;
|
||||
|
||||
/** Only these make a page worth saving as a view: sorting alone does, a lone `dir` doesn't. */
|
||||
const NARROWING = new Set(["q", "status", "tag", "sort"]);
|
||||
const NARROWING = new Set(["q", "status", "kind", "tag", "sort"]);
|
||||
|
||||
/** "/servers?q=elsa" → ["/servers", "?q=elsa"]; a plain page has an empty second part. */
|
||||
export function splitView(path: string): [string, string] {
|
||||
@@ -42,6 +42,8 @@ export function describeView(search: string): string {
|
||||
if (q) parts.push(`“${q}”`);
|
||||
const status = p.get("status");
|
||||
if (status) parts.push(STATUS_WORDS[status] ?? status);
|
||||
const kind = p.get("kind");
|
||||
if (kind) parts.push(kind);
|
||||
for (const t of p.getAll("tag")) parts.push(`tag ${t}`);
|
||||
const sort = p.get("sort");
|
||||
if (sort) parts.push(`by ${sort.replace(/([A-Z])/g, " $1").toLowerCase()} ${p.get("dir") === "desc" ? "↓" : "↑"}`);
|
||||
|
||||
Reference in new issue
Block a user