Add address aliases for the Uptime Kuma maintenance sync, and ignore Kuma's "null"
Uptime Kuma often watches a host by another address than the one it was added with here (a Proxmox host monitored over Tailscale, say). Address aliases on the Maintenance page say that an address belongs to a server, integration or DNS provider, so the sync puts the window there; matching stays exact. Migration 0018 adds maintenance_aliases. Also fixes monitors whose empty hostname/URL/port arrive from Kuma's metrics as the text "null": they were taken as an address, hiding the real URL. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e6404371b
commit
44cc9d1cf2
12 files changed
+2239
-14
No files matched your search
+14
-1
@@ -46,6 +46,16 @@ export interface MaintenanceWindow {
|
||||
source: string | null;
|
||||
}
|
||||
|
||||
export interface MaintenanceAlias {
|
||||
id: number;
|
||||
/** A bare host: a name or an IP. */
|
||||
address: string;
|
||||
targetType: MaintenanceTargetType;
|
||||
targetId: number;
|
||||
targetName: string;
|
||||
targetKind: string;
|
||||
}
|
||||
|
||||
export interface MaintenanceTargets {
|
||||
servers: { id: number; name: string }[];
|
||||
integrations: { id: number; name: string; type: string }[];
|
||||
@@ -1063,7 +1073,10 @@ export const api = {
|
||||
}),
|
||||
},
|
||||
maintenance: {
|
||||
list: () => request<{ windows: MaintenanceWindow[]; upcoming: MaintenanceWindow[]; targets: MaintenanceTargets }>("/api/maintenance"),
|
||||
list: () => request<{ windows: MaintenanceWindow[]; upcoming: MaintenanceWindow[]; aliases: MaintenanceAlias[]; targets: MaintenanceTargets }>("/api/maintenance"),
|
||||
addAlias: (data: { address: string; targetType: MaintenanceTargetType; targetId: number }) =>
|
||||
request<{ alias: MaintenanceAlias }>("/api/maintenance/aliases", { method: "POST", body: JSON.stringify(data) }),
|
||||
removeAlias: (id: number) => request<void>(`/api/maintenance/aliases/${id}`, { method: "DELETE" }),
|
||||
start: (data: { targetType: MaintenanceTargetType; targetId: number; minutes: number; reason?: string }) =>
|
||||
request<{ window: MaintenanceWindow }>("/api/maintenance", { method: "POST", body: JSON.stringify(data) }),
|
||||
end: (id: number) => request<void>(`/api/maintenance/${id}`, { method: "DELETE" }),
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
api,
|
||||
type CurrentUser,
|
||||
type IntegrationSummary,
|
||||
type MaintenanceAlias,
|
||||
type MaintenanceTargets,
|
||||
type MaintenanceTargetType,
|
||||
type MaintenanceWindow,
|
||||
@@ -32,6 +33,11 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
const canEdit = user.role === "admin" || user.role === "operator";
|
||||
const [windows, setWindows] = useState<MaintenanceWindow[] | null>(null);
|
||||
const [upcoming, setUpcoming] = useState<MaintenanceWindow[]>([]);
|
||||
const [aliases, setAliases] = useState<MaintenanceAlias[]>([]);
|
||||
const [aliasAddress, setAliasAddress] = useState("");
|
||||
const [aliasTarget, setAliasTarget] = useState("");
|
||||
const [aliasBusy, setAliasBusy] = useState(false);
|
||||
const [aliasError, setAliasError] = useState<string | null>(null);
|
||||
const [targets, setTargets] = useState<MaintenanceTargets | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
@@ -69,6 +75,7 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
.then((res) => {
|
||||
setWindows(res.windows);
|
||||
setUpcoming(res.upcoming ?? []);
|
||||
setAliases(res.aliases ?? []);
|
||||
setTargets(res.targets);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
@@ -104,6 +111,34 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function addAlias(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
const [targetType, id] = aliasTarget.split(":");
|
||||
if (!targetType || !id) return;
|
||||
setAliasError(null);
|
||||
setAliasBusy(true);
|
||||
try {
|
||||
await api.maintenance.addAlias({ address: aliasAddress.trim(), targetType: targetType as MaintenanceTargetType, targetId: Number(id) });
|
||||
setAliasAddress("");
|
||||
setAliasTarget("");
|
||||
load();
|
||||
} catch (err) {
|
||||
setAliasError(readableError(err));
|
||||
} finally {
|
||||
setAliasBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function removeAlias(a: MaintenanceAlias) {
|
||||
setAliasError(null);
|
||||
try {
|
||||
await api.maintenance.removeAlias(a.id);
|
||||
load();
|
||||
} catch (err) {
|
||||
setAliasError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function end(w: MaintenanceWindow) {
|
||||
setError(null);
|
||||
try {
|
||||
@@ -298,6 +333,11 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
</span>
|
||||
{m.targets.length > 0 ? ` → ${m.targets.map((t) => `${t.name} (${t.type === "dns_provider" ? "DNS provider" : t.type})`).join(", ")}` : m.note ? ` — nothing to schedule: ${m.note}` : ""}
|
||||
{m.unmatched.length > 0 && <span className="text-secondary"> · nothing here for {m.unmatched.join(", ")}</span>}
|
||||
{m.unmatched.length > 0 && (
|
||||
<div className="text-secondary small">
|
||||
Is one of those yours? Add its address under <em>Address aliases</em> below, saying what it belongs to.
|
||||
</div>
|
||||
)}
|
||||
<div className="text-secondary small">
|
||||
Covers {m.monitorCount} monitor{m.monitorCount === 1 ? "" : "s"} in Uptime Kuma ·{" "}
|
||||
{m.slots.length === 0
|
||||
@@ -365,6 +405,106 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{canEdit && kumaIntegrations && kumaIntegrations.length > 0 && (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Address aliases</h3>
|
||||
</div>
|
||||
<form onSubmit={addAlias}>
|
||||
<div className="card-body row g-3">
|
||||
<div className="text-secondary">
|
||||
Uptime Kuma may watch something by a different address than the one you added it with here — a host
|
||||
added by its LAN address but monitored over Tailscale, for instance. An alias says that an address
|
||||
belongs to a server, integration or DNS provider, so the syncing above puts the maintenance window
|
||||
there. Matching stays exact: only the address you list counts.
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label">Address in Uptime Kuma</label>
|
||||
<input
|
||||
className="form-control"
|
||||
required
|
||||
maxLength={253}
|
||||
placeholder="e.g. 100.116.179.43 or felicia.tail1234.ts.net"
|
||||
value={aliasAddress}
|
||||
onChange={(e) => setAliasAddress(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-5">
|
||||
<label className="form-label">Belongs to</label>
|
||||
<select className="form-select" required value={aliasTarget} onChange={(e) => setAliasTarget(e.target.value)}>
|
||||
<option value="">Choose…</option>
|
||||
{targets && targets.servers.length > 0 && (
|
||||
<optgroup label="Servers">
|
||||
{targets.servers.map((s) => (
|
||||
<option key={`s${s.id}`} value={`server:${s.id}`}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
)}
|
||||
{targets && targets.integrations.length > 0 && (
|
||||
<optgroup label="Integrations">
|
||||
{targets.integrations.map((i) => (
|
||||
<option key={`i${i.id}`} value={`integration:${i.id}`}>
|
||||
{i.name} ({i.type})
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
)}
|
||||
{targets && targets.dnsProviders.length > 0 && (
|
||||
<optgroup label="DNS providers">
|
||||
{targets.dnsProviders.map((p) => (
|
||||
<option key={`d${p.id}`} value={`dns_provider:${p.id}`}>
|
||||
{p.name} ({p.providerType})
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-3 d-flex align-items-end">
|
||||
<button type="submit" className="btn btn-primary" disabled={aliasBusy || !aliasTarget || !aliasAddress.trim()}>
|
||||
{aliasBusy ? "Adding…" : "Add alias"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{aliasError && (
|
||||
<div className="card-body pt-0">
|
||||
<div className="alert alert-danger mb-0">{aliasError}</div>
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
{aliases.length > 0 && (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Address</th>
|
||||
<th>Belongs to</th>
|
||||
<th className="w-1">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{aliases.map((a) => (
|
||||
<tr key={a.id}>
|
||||
<td>{a.address}</td>
|
||||
<td>
|
||||
{a.targetName} <span className="text-secondary">· {a.targetKind}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button className="btn btn-sm btn-outline-danger" onClick={() => removeAlias(a)}>
|
||||
Remove
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{upcoming.length > 0 && (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
|
||||
Reference in new issue
Block a user