feat(hosts): Host-Tabelle mit Filtern, CSV-Export und Detailansicht (#007)
Suche ueber Hostname, Key, Server-ID, IP und Rechnungsnummer, fuenf Filter, Sortierung mit nulls-last, Seitenblaettern und CSV-Export. Detailansicht mit sechs Tabs, Notizen, Tags und Token-Widerruf. 59 Tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { PRODUKT_TEXT, STATUS_TEXT, statusAusDatenbank } from "@/lib/anzeige";
|
||||
import { csvAntwort, csvDatei } from "@/lib/csv";
|
||||
import { hostListe, type HostFilter } from "@/server/queries/hostliste";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/** CSV-Export der Host-Tabelle; übernimmt die Filter aus der Adresse. */
|
||||
export async function GET(request: Request) {
|
||||
const parameter = new URL(request.url).searchParams;
|
||||
const filter: HostFilter = {
|
||||
q: parameter.get("q") ?? undefined,
|
||||
kunde: parameter.get("kunde") ?? undefined,
|
||||
status: parameter.get("status") ?? undefined,
|
||||
produkt: parameter.get("produkt") ?? undefined,
|
||||
ablauf: (parameter.get("ablauf") as HostFilter["ablauf"]) ?? undefined,
|
||||
rechnung: (parameter.get("rechnung") as HostFilter["rechnung"]) ?? undefined,
|
||||
sortierung: parameter.get("sortierung") ?? undefined,
|
||||
// Der Export enthält alle Treffer, nicht nur die aktuelle Seite.
|
||||
seite: 1,
|
||||
};
|
||||
|
||||
const { gesamt } = await hostListe({ ...filter }, new Date());
|
||||
const alle = [];
|
||||
for (let seite = 1; alle.length < gesamt; seite++) {
|
||||
const teil = await hostListe({ ...filter, seite }, new Date());
|
||||
if (teil.hosts.length === 0) break;
|
||||
alle.push(...teil.hosts);
|
||||
}
|
||||
|
||||
const inhalt = csvDatei(
|
||||
[
|
||||
"Hostname",
|
||||
"FQDN",
|
||||
"Kunde",
|
||||
"Standort",
|
||||
"Produkt",
|
||||
"Version",
|
||||
"Status",
|
||||
"Subscription-Key",
|
||||
"Server-ID",
|
||||
"Sockets lizenziert",
|
||||
"Sockets physisch",
|
||||
"Ablauf",
|
||||
"Letzte Meldung",
|
||||
"IP-Adressen",
|
||||
"Agent-Version",
|
||||
],
|
||||
alle.map((host) => [
|
||||
host.hostname,
|
||||
host.fqdn,
|
||||
host.kunde?.name ?? "Nicht zugeordnet",
|
||||
host.standort?.name ?? "",
|
||||
PRODUKT_TEXT[host.produkt],
|
||||
host.produktVersion,
|
||||
STATUS_TEXT[statusAusDatenbank(host.subStatus)],
|
||||
host.subKey,
|
||||
host.serverId,
|
||||
host.subLizenzierteSockets,
|
||||
host.sockets,
|
||||
host.subNextduedate,
|
||||
host.letzterReportAm,
|
||||
host.ips.join(", "),
|
||||
host.agentVersion,
|
||||
]),
|
||||
);
|
||||
|
||||
const datum = new Date().toISOString().slice(0, 10);
|
||||
return csvAntwort(inhalt, `proxledger-hosts-${datum}.csv`);
|
||||
}
|
||||
Reference in New Issue
Block a user