Patch plans, a monthly report and new-port alerts
Patch plans (Updates -> Patch plans): updates on a schedule, one server at a time, each by an ordinary update run, stopping at the first failure by default, silencing what depends on a server while it is updated, with one message at the end. Monthly report (Operations -> Monthly report, and optionally a message on a day of the month): availability, incidents, updates, restore tests, backups and renewals for a calendar month, printable. Backed by daily endpoint figures and a record of renewals. New ports: the first report with ports is the baseline; a TCP port that begins listening later and is not noted on the server's Ports card is a warning, cleared by Mark as expected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ddd0aa622a
commit
be6c5552bd
46 files changed
+7836
-26
No files matched your search
+88
-1
@@ -1,5 +1,5 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { sqliteTable, text, integer, real, uniqueIndex, index } from "drizzle-orm/sqlite-core";
|
||||
import { sqliteTable, text, integer, real, uniqueIndex, index, primaryKey } from "drizzle-orm/sqlite-core";
|
||||
|
||||
// ─── Users & roles ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -447,6 +447,10 @@ export const servers = sqliteTable("servers", {
|
||||
// What the agent says it could not collect, as JSON: {items: [{check, status, reason?, detail?}], reportedAt} — see services/agentDiagnostics.ts. Null until an agent that can say so has.
|
||||
agentDiagnostics: text("agent_diagnostics"),
|
||||
|
||||
// The ports this server was listening on when its agent first said so, as a JSON array like ["tcp:22","tcp:443"]. A port that is listening later and is
|
||||
// not in this list, and not noted on the Ports page, is a "new port" (services/newPorts.ts). Null until the first report that carries ports.
|
||||
portBaseline: text("port_baseline"),
|
||||
|
||||
// What the machine is, as its firmware says (agents report it): maker, model and serial number. Used to fill in the inventory.
|
||||
hwManufacturer: text("hw_manufacturer"),
|
||||
hwModel: text("hw_model"),
|
||||
@@ -846,6 +850,89 @@ export const updateRuns = sqliteTable(
|
||||
(t) => [index("update_runs_server_idx").on(t.serverId, t.startedAt), index("update_runs_status_idx").on(t.status)],
|
||||
);
|
||||
|
||||
// ─── Patch plans: updates, on a schedule, one server at a time ─────────────
|
||||
|
||||
// "Sundays at 02:00, the servers tagged lab, one at a time, stop at the first failure." A plan only says when, to whom and how; each server is updated by an
|
||||
// ordinary update run (services/updateRuns.ts), and the plan waits for it to finish before the next — see services/patchPlans.ts.
|
||||
export const patchPlans = sqliteTable("patch_plans", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
|
||||
days: text("days").notNull(), // JSON: weekdays, 0 = Sunday … 6 = Saturday
|
||||
startTime: text("start_time").notNull(), // "HH:MM" on the clock of `timezone`
|
||||
timezone: text("timezone").notNull(),
|
||||
tags: text("tags").notNull().default("[]"), // JSON string[]: servers that have any of these tags
|
||||
serverIds: text("server_ids").notNull().default("[]"), // JSON number[]: and these servers by name, whatever their tags
|
||||
integrationId: integer("integration_id").notNull(), // the Semaphore integration; no FK, like update runs
|
||||
projectId: integer("project_id").notNull(),
|
||||
templateId: integer("template_id").notNull(),
|
||||
templateName: text("template_name").notNull(),
|
||||
limitFrom: text("limit_from").notNull().default("name"), // what ansible's --limit is for a server: its name here, or its host name
|
||||
stopOnFailure: integer("stop_on_failure", { mode: "boolean" }).notNull().default(true),
|
||||
onlyWithUpdates: integer("only_with_updates", { mode: "boolean" }).notNull().default(true), // leave out a server that has nothing waiting
|
||||
silenceDependents: integer("silence_dependents", { mode: "boolean" }).notNull().default(true), // what depends on a server is silenced while it is updated
|
||||
windowMinutes: integer("window_minutes").notNull().default(90), // at most this long under maintenance per server
|
||||
lastRunDate: text("last_run_date"), // the local day (YYYY-MM-DD) it last started on — so it starts once a day, even if the app is restarted
|
||||
createdBy: text("created_by"),
|
||||
createdAt: text("created_at")
|
||||
.notNull()
|
||||
.default(sql`(current_timestamp)`),
|
||||
});
|
||||
|
||||
// One time a plan ran, and how it went for each server: items is JSON [{serverId, name, status, updateRunId, message, windowIds}].
|
||||
export const patchPlanRuns = sqliteTable(
|
||||
"patch_plan_runs",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
planId: integer("plan_id")
|
||||
.notNull()
|
||||
.references(() => patchPlans.id, { onDelete: "cascade" }),
|
||||
planName: text("plan_name").notNull(), // as it was, so a renamed plan's history still reads right
|
||||
trigger: text("trigger").notNull(), // schedule | manual
|
||||
startedBy: text("started_by"),
|
||||
status: text("status").notNull(), // running | done | failed | cancelled
|
||||
message: text("message"),
|
||||
items: text("items").notNull().default("[]"),
|
||||
startedAt: text("started_at").notNull(), // ISO
|
||||
finishedAt: text("finished_at"), // ISO
|
||||
},
|
||||
(t) => [index("patch_plan_runs_plan_idx").on(t.planId, t.startedAt), index("patch_plan_runs_status_idx").on(t.status)],
|
||||
);
|
||||
|
||||
// ─── The monthly report's long memory ───────────────────────────────────────
|
||||
|
||||
// One row per endpoint check per day: how many times it was asked, how many answered, and the answer times — kept for years, where the individual
|
||||
// results are kept for two weeks. What the monthly report's availability is worked from (services/endpointChecks.ts).
|
||||
export const endpointDaily = sqliteTable(
|
||||
"endpoint_daily",
|
||||
{
|
||||
checkId: integer("check_id")
|
||||
.notNull()
|
||||
.references(() => endpointChecks.id, { onDelete: "cascade" }),
|
||||
day: text("day").notNull(), // YYYY-MM-DD, UTC
|
||||
total: integer("total").notNull().default(0),
|
||||
ok: integer("ok").notNull().default(0),
|
||||
msSum: integer("ms_sum").notNull().default(0), // of the answers that were good and timed
|
||||
msCount: integer("ms_count").notNull().default(0),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.checkId, t.day] })],
|
||||
);
|
||||
|
||||
// A certificate, domain registration or secret whose expiry moved later: it was renewed. Written when the app sees it happen, so it only goes back
|
||||
// as far as the version that began watching (services/renewals.ts).
|
||||
export const renewals = sqliteTable(
|
||||
"renewals",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
kind: text("kind").notNull(), // certificate | domain | secret
|
||||
subject: text("subject").notNull(), // its name, as it was
|
||||
at: text("at").notNull(), // ISO — when it was seen
|
||||
fromDate: text("from_date").notNull(), // YYYY-MM-DD — the expiry before
|
||||
toDate: text("to_date").notNull(), // YYYY-MM-DD — and after
|
||||
},
|
||||
(t) => [index("renewals_at_idx").on(t.at)],
|
||||
);
|
||||
|
||||
// ─── Inventory: the hardware behind it all ──────────────────────────────────
|
||||
|
||||
export const assetKinds = ["server", "storage", "network", "power", "client", "other"] as const;
|
||||
|
||||
Reference in new issue
Block a user