Add standard diagnostics and typed restart planning
This commit is contained in:
+1
-1
@@ -705,7 +705,7 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
|
||||
{route.page === 'auftraege' && (
|
||||
route.tab === 'neu' ? <>
|
||||
<a href="#auftraege" className="back-link">← Zu den Aufträgen</a>
|
||||
<OrderComposer tenantId={customer} customerName={customerName} auth={scoped} initialAssetIds={selected} onSubmitted={afterSubmission} />
|
||||
<OrderComposer tenantId={customer} customerName={customerName} auth={scoped} initialAssetIds={selected} onSubmitted={afterSubmission} onDraft={showDraft} />
|
||||
<details className="advanced-order"><summary>Weitere Wartungsaktionen</summary>
|
||||
<p>Inventur, Dienstverwaltung und weitere Wartungsaufträge planen.</p>
|
||||
<a className="quiet" href="#auftraege/wartung">Wartungsauftrag planen</a>
|
||||
|
||||
+127
-70
@@ -37,6 +37,7 @@ type Props = {
|
||||
auth: Session;
|
||||
initialAssetIds: string[];
|
||||
onSubmitted: (operationId: string) => void;
|
||||
onDraft: (planId: string) => void;
|
||||
};
|
||||
type Target = {
|
||||
id: string;
|
||||
@@ -119,17 +120,22 @@ function issueMessage(err: unknown) {
|
||||
return errorText(err);
|
||||
}
|
||||
|
||||
export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, customerName }: Props) {
|
||||
export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, onDraft, customerName }: Props) {
|
||||
const path = (suffix: string) => tenantPath(tenantId, suffix);
|
||||
const key = 'rmm:order-plan:' + JSON.stringify([auth.principal.id, tenantId]);
|
||||
const [ticket, setTicket] = useState<Ticket | null>(() => resumeTicket(key));
|
||||
const [savedTicket, setTicket] = useState<Ticket | null>(() => resumeTicket(key));
|
||||
const [step, setStep] = useState<1 | 2>(1);
|
||||
const [selected, setSelected] = useState<string[]>(() => [...new Set(initialAssetIds)]);
|
||||
const [known, setKnown] = useState<Record<string, Target>>({});
|
||||
const [query, setQuery] = useState('');
|
||||
const [cursor, setCursor] = useState<string | null>(null);
|
||||
const [prior, setPrior] = useState<(string | null)[]>([]);
|
||||
const [mode, setMode] = useState<'library' | 'once'>('library');
|
||||
const canCreate = ['inventory:read', 'operations:read', 'operations:plan', 'operations:submit']
|
||||
.every((permission) => allowed(auth, permission));
|
||||
const canPlanScript = canCreate && allowed(auth, 'scripts:execute');
|
||||
const canPlanReboot = canCreate && (allowed(auth, 'root:execute') || allowed(auth, 'system:execute'));
|
||||
const ticket = canPlanScript ? savedTicket : null;
|
||||
const [mode, setMode] = useState<'library' | 'once' | 'reboot'>(() => canPlanScript ? 'library' : 'reboot');
|
||||
const [revisionId, choose] = useState('');
|
||||
const [linux, setLinux] = useState<Script>(() => emptyScript('posix_sh'));
|
||||
const [windows, setWindows] = useState<Script>(() => emptyScript('powershell'));
|
||||
@@ -153,13 +159,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
mounted.current = false;
|
||||
};
|
||||
}, []);
|
||||
const canPlan = [
|
||||
'inventory:read',
|
||||
'operations:read',
|
||||
'operations:plan',
|
||||
'scripts:execute',
|
||||
'operations:submit'
|
||||
].every((p) => allowed(auth, p));
|
||||
const canPlan = canPlanScript || canPlanReboot;
|
||||
|
||||
const devices = useResource(
|
||||
async (signal) => {
|
||||
@@ -174,7 +174,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
);
|
||||
const review = useResource(
|
||||
async (signal) => {
|
||||
if (!ticket) return null;
|
||||
if (!ticket || !canPlanScript) return null;
|
||||
const checked = await verifiedScriptOrder(
|
||||
await request(path('/operation-plans/' + ticket.id), { signal }),
|
||||
tenantId,
|
||||
@@ -184,7 +184,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
throw Error('Der gespeicherte Plan entspricht nicht dem ausgewählten Auftrag.');
|
||||
return checked;
|
||||
},
|
||||
[tenantId, ticket?.id, ticket?.hash, auth.principal.id]
|
||||
[tenantId, ticket?.id, ticket?.hash, auth.principal.id, canPlanScript]
|
||||
);
|
||||
const missingIds = (review.data?.jobs.map((job) => job.assetId) ?? initialAssetIds).filter((id) => !known[id]);
|
||||
const restored = useResource(
|
||||
@@ -216,11 +216,12 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
const hasLinux = targets.some((d) => d?.platform === 'linux');
|
||||
const hasWindows = targets.some((d) => d?.platform === 'windows');
|
||||
const scripts = useResource(
|
||||
(signal) => (canPlan && step === 2 && !ticket ? loadRevisions(tenantId, signal) : Promise.resolve([])),
|
||||
[tenantId, canPlan, step, !!ticket]
|
||||
(signal) => (canPlanScript && step === 2 && !ticket && mode === 'library' ? loadRevisions(tenantId, signal) : Promise.resolve([])),
|
||||
[tenantId, canPlanScript, step, !!ticket, mode]
|
||||
);
|
||||
const revision = scripts.data?.find((r) => r.revision_id === revisionId);
|
||||
const heads = latestRevisions(scripts.data ?? []);
|
||||
const rebootIdentity = hasWindows ? 'system' : 'root';
|
||||
const issues: string[] = [];
|
||||
if (targets.some((d) => !d?.current))
|
||||
issues.push('Ein Zielgerät fehlt im aktuellen Bestand. Entfernen Sie es aus der Auswahl.');
|
||||
@@ -237,6 +238,10 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
if (identity !== 'agent_service' && !allowed(auth, identity + ':execute'))
|
||||
issues.push('Die Berechtigung für ' + identityNames[identity] + ' fehlt.');
|
||||
}
|
||||
if (mode === 'reboot') {
|
||||
if (selected.length !== 1) issues.push('Wählen Sie ein einzelnes Gerät für den Neustart.');
|
||||
if (!allowed(auth, rebootIdentity + ':execute')) issues.push('Die Berechtigung für ' + identityNames[rebootIdentity] + ' fehlt.');
|
||||
}
|
||||
if (
|
||||
mode === 'once' &&
|
||||
hasLinux &&
|
||||
@@ -275,7 +280,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
: 3600;
|
||||
async function prepare(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
if (lock.current || !canPlan || issues.length || !selected.length) return;
|
||||
if (lock.current || !(mode === 'reboot' ? canPlanReboot : canPlanScript) || issues.length || !selected.length) return;
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
@@ -285,6 +290,47 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
throw Error('Die Startfrist muss nach dem frühesten Start und in der Zukunft liegen.');
|
||||
const rollout = { max_parallel: parallel, halt_after_failures: halt };
|
||||
const bound = { targets: { asset_ids: selected }, rollout, reason: reason.trim() };
|
||||
if (mode === 'reboot') {
|
||||
const input: PlanInput = {
|
||||
...bound,
|
||||
tenant_id: tenantId,
|
||||
action: 'reboot',
|
||||
schedule: { ...schedule, offline_policy: 'wait_until_deadline' },
|
||||
rollout: { max_parallel: 1, halt_after_failures: 1 },
|
||||
parameters: {
|
||||
execution_identity: rebootIdentity,
|
||||
reason: bound.reason,
|
||||
dependency_group: 'asset-' + selected[0],
|
||||
reconnect_timeout_seconds: hasWindows ? 180 : 300,
|
||||
timeout_seconds: 60,
|
||||
max_output_bytes: 4096
|
||||
}
|
||||
};
|
||||
validateInput(input);
|
||||
await validateSensitiveInput(input, auth);
|
||||
const plan = record(await request(path('/operation-plans'), { csrf: auth.csrf_token, body: input }));
|
||||
if (!Array.isArray(plan.plan_payload_bytes)) throw Error('Die gespeicherten Bytes des Neustartplans fehlen.');
|
||||
await verifyPlanIntegrity(plan);
|
||||
const planId = objectId(plan, 'plan');
|
||||
const fixed = record(plan.plan_payload);
|
||||
const jobs = Array.isArray(fixed.jobs) ? fixed.jobs : [];
|
||||
const job = record(record(jobs[0]).payload);
|
||||
const action = record(job.action);
|
||||
if (
|
||||
fixed.plan_id !== planId || fixed.tenant_id !== tenantId || fixed.principal !== auth.principal.id ||
|
||||
fixed.reason !== bound.reason || fixed.max_parallel !== 1 || fixed.halt_after_failures !== 1 ||
|
||||
jobs.length !== 1 || job.asset_id !== selected[0] || job.execution_identity !== rebootIdentity ||
|
||||
action.action !== 'reboot' || action.reason !== bound.reason ||
|
||||
action.dependency_group !== input.parameters.dependency_group ||
|
||||
action.reconnect_timeout_seconds !== input.parameters.reconnect_timeout_seconds ||
|
||||
job.max_runtime_seconds !== input.parameters.timeout_seconds ||
|
||||
job.max_output_bytes !== input.parameters.max_output_bytes ||
|
||||
Date.parse(String(job.not_before)) !== Date.parse(schedule.not_before) ||
|
||||
Date.parse(String(job.start_before)) !== Date.parse(schedule.start_before)
|
||||
) throw Error('Der erstellte Neustartplan weicht von diesem Entwurf ab.');
|
||||
if (mounted.current) onDraft(planId);
|
||||
return;
|
||||
}
|
||||
let raw: unknown;
|
||||
if (mode === 'library') {
|
||||
if (!revision) throw Error('Wählen Sie eine Skriptversion.');
|
||||
@@ -365,7 +411,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
}
|
||||
}
|
||||
async function submit() {
|
||||
if (!ticket || !review.data || !canPlan || lock.current) return;
|
||||
if (!ticket || !review.data || !canPlanScript || lock.current) return;
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
@@ -413,7 +459,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
<h1>Neuer Auftrag</h1>
|
||||
</div>
|
||||
<ol className="order-progress" aria-label="Auftragsschritte">
|
||||
{['Geräte', 'Skript', 'Zusammenfassung'].map((name, i) => (
|
||||
{['Geräte', 'Aktion', 'Zusammenfassung'].map((name, i) => (
|
||||
<li key={name} aria-current={stepNumber === i + 1 ? 'step' : undefined}>
|
||||
{i + 1}. {name}
|
||||
</li>
|
||||
@@ -423,11 +469,11 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
{!canPlan ? (
|
||||
<section>
|
||||
<p>
|
||||
Zum Erstellen eines Skriptauftrags benötigen Sie Gerätezugriff sowie Rechte zum Planen und Einreichen von
|
||||
Skriptaufträgen.
|
||||
Zum Erstellen eines Auftrags benötigen Sie Gerätezugriff, Rechte zum Planen und Einreichen und das
|
||||
Ausführungsrecht für die gewählte Aktion.
|
||||
</p>
|
||||
</section>
|
||||
) : ticket ? (
|
||||
) : ticket && canPlanScript ? (
|
||||
<section aria-label="Auftrag prüfen">
|
||||
<h2>Zusammenfassung</h2>
|
||||
{review.data ? (
|
||||
@@ -603,7 +649,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
setError(null);
|
||||
}}
|
||||
>
|
||||
Weiter zum Skript
|
||||
{canPlanReboot ? 'Weiter zur Aktion' : 'Weiter zum Skript'}
|
||||
</button>
|
||||
</div>
|
||||
{selected.length > 100 && <p role="alert">Ein Auftrag kann bis zu 100 Geräte enthalten.</p>}
|
||||
@@ -611,18 +657,22 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
</section>
|
||||
) : (
|
||||
<section>
|
||||
<h2>Skript auswählen</h2>
|
||||
<h2>{canPlanReboot ? 'Aktion auswählen' : 'Skript auswählen'}</h2>
|
||||
<form onSubmit={prepare}>
|
||||
<fieldset disabled={busy} className="work-form">
|
||||
<div className="order-source">
|
||||
<label>
|
||||
{canPlanScript && <label>
|
||||
<input type="radio" name="quelle" checked={mode === 'library'} onChange={() => setMode('library')} />
|
||||
Aus der Bibliothek
|
||||
</label>
|
||||
<label>
|
||||
</label>}
|
||||
{canPlanScript && <label>
|
||||
<input type="radio" name="quelle" checked={mode === 'once'} onChange={() => setMode('once')} />
|
||||
Einmaliges Skript
|
||||
</label>
|
||||
</label>}
|
||||
{canPlanReboot && <label>
|
||||
<input type="radio" name="quelle" checked={mode === 'reboot'} onChange={() => setMode('reboot')} />
|
||||
Gerät neu starten
|
||||
</label>}
|
||||
</div>
|
||||
{mode === 'library' ? (
|
||||
<>
|
||||
@@ -680,7 +730,7 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
) : mode === 'once' ? (
|
||||
<>
|
||||
{hasLinux && <ScriptFieldsForPlatform script={linux} change={setLinux} auth={auth} windows={false} />}
|
||||
{hasWindows && <ScriptFieldsForPlatform script={windows} change={setWindows} auth={auth} windows />}
|
||||
@@ -691,6 +741,11 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
</label>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<p className="warning">
|
||||
Der Auftrag startet das ausgewählte Gerät nach Genehmigung neu. Ausführung als {identityNames[rebootIdentity]}.
|
||||
Der Agent muss nach dem Neustart wieder Kontakt aufnehmen.
|
||||
</p>
|
||||
)}
|
||||
<label>
|
||||
Begründung
|
||||
@@ -707,49 +762,51 @@ export function OrderComposer({ tenantId, auth, initialAssetIds, onSubmitted, cu
|
||||
Startfrist
|
||||
<input required type="datetime-local" value={end} onChange={(e) => setEnd(e.target.value)} />
|
||||
</label>
|
||||
<label>
|
||||
Laufzeit je Gerät in Sekunden
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
max={maxRuntime}
|
||||
value={runtime}
|
||||
onChange={(e) => setRuntime(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Ausgabelimit in Byte
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
max={identity === 'agent_service' ? 262144 : 65536}
|
||||
value={limit}
|
||||
onChange={(e) => setLimit(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Geräte gleichzeitig
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
max={10}
|
||||
value={parallel}
|
||||
onChange={(e) => setParallel(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Stopp nach Fehlern
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
value={halt}
|
||||
onChange={(e) => setHalt(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
{mode !== 'reboot' && <>
|
||||
<label>
|
||||
Laufzeit je Gerät in Sekunden
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
max={maxRuntime}
|
||||
value={runtime}
|
||||
onChange={(e) => setRuntime(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Ausgabelimit in Byte
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
max={identity === 'agent_service' ? 262144 : 65536}
|
||||
value={limit}
|
||||
onChange={(e) => setLimit(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Geräte gleichzeitig
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
max={10}
|
||||
value={parallel}
|
||||
onChange={(e) => setParallel(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Stopp nach Fehlern
|
||||
<input
|
||||
required
|
||||
type="number"
|
||||
min={1}
|
||||
value={halt}
|
||||
onChange={(e) => setHalt(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
</>}
|
||||
</div>
|
||||
{mode === 'once' && (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user