Add Hetzner Robot: dedicated servers and storage boxes, with shutting-down, locked and rescue-left-on alerts
Read every 15 minutes (Robot allows 200 requests an hour; read-only): each server's product, addresses, status, rescue system and paid-until, and the storage boxes. Adapter, sync service, hetzner_robot_state table, /api/hetzner-robot, Infrastructure → Hetzner Robot page, metrics and docs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7618bf0f0a
commit
01acbaf831
31 files changed
+10105
-10
No files matched your search
@@ -0,0 +1,221 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type RobotAccount } from "../api/client";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
function Badge({ a }: { a: RobotAccount }) {
|
||||
if (!a.enabled) return <span className="badge bg-secondary-lt text-secondary">Off</span>;
|
||||
if (!a.state) return <span className="badge bg-secondary-lt text-secondary">Not read yet</span>;
|
||||
if (!a.fresh) return <span className="badge bg-yellow-lt text-yellow">Can’t be read</span>;
|
||||
if (a.problems.some((x) => x.severity === "critical")) return <span className="badge bg-red-lt text-red">Needs a look</span>;
|
||||
if (a.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">Needs a look</span>;
|
||||
return <span className="badge bg-green-lt text-green">In order</span>;
|
||||
}
|
||||
|
||||
function Tile({ label, value, sub, warn }: { label: string; value: string; sub?: string | null; warn?: boolean }) {
|
||||
return (
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm h-100">
|
||||
<div className="card-body">
|
||||
<div className="text-secondary small">{label}</div>
|
||||
<div className={`h2 mb-0 ${warn ? "text-yellow" : ""}`}>{value}</div>
|
||||
{sub && <div className="text-secondary small">{sub}</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** "Paid until 2026-12-01", or, for one that is cancelled, when it ends and how long that is. */
|
||||
function Until({ date, cancelled, days }: { date: string | null; cancelled: boolean; days: number | null | undefined }) {
|
||||
if (!date) return <span className="text-secondary">—</span>;
|
||||
if (!cancelled) return <span className="text-secondary">paid until {date}</span>;
|
||||
const urgent = days !== null && days !== undefined && days <= 7;
|
||||
const soon = days !== null && days !== undefined && days <= 30;
|
||||
return (
|
||||
<>
|
||||
<span className={`badge ${urgent ? "bg-red-lt text-red" : soon ? "bg-yellow-lt text-yellow" : "bg-secondary-lt text-secondary"}`}>cancelled</span>
|
||||
<div className={`small ${urgent ? "text-red" : soon ? "text-yellow" : "text-secondary"}`}>
|
||||
ends {date}
|
||||
{days !== null && days !== undefined ? (days < 0 ? " — has ended" : days === 0 ? " — today" : ` — ${days} day${days === 1 ? "" : "s"} left`) : ""}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ a }: { a: RobotAccount }) {
|
||||
const s = a.state;
|
||||
const rescue = s?.servers.filter((v) => v.rescue === true).length ?? 0;
|
||||
const cancelled = (s?.servers.filter((v) => v.cancelled).length ?? 0) + (s?.storageBoxes?.filter((b) => b.cancelled).length ?? 0);
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">
|
||||
{a.name} <Badge a={a} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{a.status && !a.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {a.status.error ?? "no answer"}.</div>}
|
||||
{a.problems.length > 0 && (
|
||||
<ul className="mb-3">
|
||||
{a.problems.map((x) => (
|
||||
<li key={x.key} className={x.severity === "critical" ? "text-red" : ""}>
|
||||
{x.message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{s && (
|
||||
<>
|
||||
<div className="row g-3 mb-3">
|
||||
<Tile label="Dedicated servers" value={String(s.servers.length)} sub={s.servers.length === 0 ? "none on this account" : null} />
|
||||
<Tile label="Rescue system on" value={String(rescue)} sub={rescue > 0 ? "the next boot is into it" : "none"} warn={rescue > 0} />
|
||||
<Tile label="Cancelled" value={String(cancelled)} sub={cancelled > 0 ? "servers and storage boxes shutting down" : "nothing shutting down"} warn={cancelled > 0} />
|
||||
<Tile label="Storage boxes" value={s.storageBoxes === null ? "—" : String(s.storageBoxes.length)} sub={s.storageBoxes === null ? "could not be read" : s.storageBoxes.some((b) => b.locked) ? "one is locked" : null} warn={!!s.storageBoxes?.some((b) => b.locked)} />
|
||||
</div>
|
||||
{s.skippedDetail > 0 && <div className="text-secondary small mb-2">{s.skippedDetail} server{s.skippedDetail === 1 ? "" : "s"} beyond the first 25 were not asked about their rescue system (Hetzner allows 200 requests an hour).</div>}
|
||||
{s.servers.length > 0 && (
|
||||
<div className="table-responsive mb-3">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Server</th>
|
||||
<th>Product</th>
|
||||
<th>Address</th>
|
||||
<th>Traffic</th>
|
||||
<th>Status</th>
|
||||
<th>Rescue</th>
|
||||
<th>Paid</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{s.servers.map((v) => (
|
||||
<tr key={v.number}>
|
||||
<td>
|
||||
{v.name}
|
||||
<div className="small text-secondary">#{v.number}</div>
|
||||
</td>
|
||||
<td className="text-secondary">
|
||||
{v.product ?? "—"}
|
||||
{v.dc && <div className="small">{v.dc}</div>}
|
||||
</td>
|
||||
<td className="text-secondary">
|
||||
{v.ip ? <code>{v.ip}</code> : "—"}
|
||||
{v.ipv6 && (
|
||||
<div className="small">
|
||||
<code>{v.ipv6}</code>
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td className="text-secondary">{v.traffic ?? "—"}</td>
|
||||
<td>{v.status === "ready" ? <span className="badge bg-green-lt text-green">ready</span> : <span className="badge bg-yellow-lt text-yellow">{v.status}</span>}</td>
|
||||
<td>
|
||||
{v.rescue === null ? (
|
||||
<span className="text-secondary">—</span>
|
||||
) : v.rescue ? (
|
||||
<>
|
||||
<span className="badge bg-yellow-lt text-yellow">on</span>
|
||||
{v.rescueSince && (
|
||||
<div className="small text-secondary">
|
||||
since <TimeAgo value={v.rescueSince} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<span className="text-secondary">off</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<Until date={v.paidUntil} cancelled={v.cancelled} days={s.serverDays[String(v.number)]} />
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
{s.storageBoxes && s.storageBoxes.length > 0 && (
|
||||
<>
|
||||
<h4>Storage boxes</h4>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Storage box</th>
|
||||
<th>Product</th>
|
||||
<th>Location</th>
|
||||
<th>Linked to</th>
|
||||
<th>State</th>
|
||||
<th>Paid</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{s.storageBoxes.map((b) => (
|
||||
<tr key={b.id}>
|
||||
<td>
|
||||
{b.name}
|
||||
<div className="small text-secondary">{b.login ?? `#${b.id}`}</div>
|
||||
</td>
|
||||
<td className="text-secondary">{b.product ?? "—"}</td>
|
||||
<td className="text-secondary">{b.location ?? "—"}</td>
|
||||
<td className="text-secondary">{b.linkedServer !== null ? (s.servers.find((v) => v.number === b.linkedServer)?.name ?? `server ${b.linkedServer}`) : "—"}</td>
|
||||
<td>{b.locked ? <span className="badge bg-red-lt text-red">locked</span> : <span className="badge bg-green-lt text-green">open</span>}</td>
|
||||
<td>
|
||||
<Until date={b.paidUntil} cancelled={b.cancelled} days={s.boxDays[String(b.id)]} />
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Hetzner Robot: the account's dedicated servers (rescue system, cancellation) and storage boxes. */
|
||||
export default function HetznerRobot() {
|
||||
const [data, setData] = useState<RobotAccount[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.hetznerRobot
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.accounts);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Hetzner Robot</h2>
|
||||
<p className="text-secondary">
|
||||
Dedicated servers and storage boxes at Hetzner (Robot — the cloud servers are on <Link to="/hetzner">Hetzner Cloud</Link>), read every fifteen minutes (see <Link to="/integrations">Integrations</Link>) — nothing is reset, ordered or cancelled.{" "}
|
||||
<strong>A server or storage box that is cancelled and about to shut down</strong>, <strong>a locked storage box</strong>, <strong>a rescue system left on</strong> and <strong>a server stuck being set up</strong> are alerts — see <Link to="/alerts">Alerts</Link>.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
{!data && !error && <BlockSkeleton lines={4} />}
|
||||
{data && data.length === 0 && (
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<EmptyState title="No Hetzner Robot account connected" hint="Add one under Integrations with a webservice user (Robot → Settings → Webservice and app settings) and its password." />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user