dsh-ssh-hub 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +271 -2
- package/cordis.patch.yml +16 -0
- package/icon.svg +3 -0
- package/lib/client.js +13975 -0
- package/lib/index.js +6908 -0
- package/lib/types/activity/history.d.ts +50 -0
- package/lib/types/alerting/notify.d.ts +89 -0
- package/lib/types/alerting/prompt-summary.d.ts +28 -0
- package/lib/types/alerting/rules.d.ts +135 -0
- package/lib/types/alerting/tools.d.ts +30 -0
- package/lib/types/audit/audit-log.d.ts +84 -0
- package/lib/types/audit/recorder.d.ts +50 -0
- package/lib/types/client/api.d.ts +222 -0
- package/lib/types/client/index.d.ts +45 -0
- package/lib/types/client/locales.d.ts +319 -0
- package/lib/types/client/native-panel.d.ts +70 -0
- package/lib/types/client/panel/ClusterTab.d.ts +7 -0
- package/lib/types/client/panel/DeployTab.d.ts +10 -0
- package/lib/types/client/panel/FleetTab.d.ts +10 -0
- package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
- package/lib/types/client/panel/HostsTab.d.ts +25 -0
- package/lib/types/client/panel/LogsTab.d.ts +10 -0
- package/lib/types/client/panel/SshPanel.d.ts +14 -0
- package/lib/types/client/panel/TerminalTab.d.ts +27 -0
- package/lib/types/client/panel/TransferTab.d.ts +7 -0
- package/lib/types/client/panel/TunnelEditDialog.d.ts +15 -0
- package/lib/types/client/panel/TunnelsTab.d.ts +27 -0
- package/lib/types/client/panel/controller.d.ts +253 -0
- package/lib/types/client/panel/helpers.d.ts +45 -0
- package/lib/types/client/panel/tabs.d.ts +62 -0
- package/lib/types/client/panel/xterm.css.d.ts +2 -0
- package/lib/types/client/settings-binding.d.ts +71 -0
- package/lib/types/deploy/orchestrator.d.ts +158 -0
- package/lib/types/deploy/tools.d.ts +14 -0
- package/lib/types/dsh-home.d.ts +16 -0
- package/lib/types/engine/cluster.d.ts +19 -0
- package/lib/types/engine/connection-pool.d.ts +183 -0
- package/lib/types/engine/proxy-command.d.ts +36 -0
- package/lib/types/engine/pty.d.ts +32 -0
- package/lib/types/engine/sftp.d.ts +20 -0
- package/lib/types/engine/terminal-sessions.d.ts +67 -0
- package/lib/types/engine/tunnel-discovery.d.ts +89 -0
- package/lib/types/engine/tunnel-remarks.d.ts +49 -0
- package/lib/types/engine/tunnel.d.ts +76 -0
- package/lib/types/engine.d.ts +103 -0
- package/lib/types/http.d.ts +59 -0
- package/lib/types/index.d.ts +128 -0
- package/lib/types/inspect/checks.d.ts +118 -0
- package/lib/types/inspect/inspection.d.ts +111 -0
- package/lib/types/inspect/tools.d.ts +50 -0
- package/lib/types/logs/search.d.ts +131 -0
- package/lib/types/logs/tools.d.ts +6 -0
- package/lib/types/loopback.d.ts +64 -0
- package/lib/types/monitor/loop.d.ts +133 -0
- package/lib/types/monitor/metrics.d.ts +151 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/lib/types/protocol.d.ts +524 -0
- package/lib/types/routes.d.ts +82 -0
- package/lib/types/security/known-hosts.d.ts +153 -0
- package/lib/types/security/master-secret.d.ts +157 -0
- package/lib/types/security/redact.d.ts +44 -0
- package/lib/types/security/secrets.d.ts +70 -0
- package/lib/types/ssh-config.d.ts +42 -0
- package/lib/types/store.d.ts +183 -0
- package/lib/types/tool-surface.d.ts +72 -0
- package/lib/types/tools.d.ts +56 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +126 -6
- package/src/activity/history.ts +117 -0
- package/src/alerting/notify.ts +212 -0
- package/src/alerting/prompt-summary.ts +71 -0
- package/src/alerting/rules.ts +281 -0
- package/src/alerting/tools.ts +263 -0
- package/src/audit/audit-log.ts +199 -0
- package/src/audit/recorder.ts +73 -0
- package/src/client/api.ts +782 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +150 -0
- package/src/client/locales.ts +654 -0
- package/src/client/native-panel.tsx +141 -0
- package/src/client/panel/ClusterTab.tsx +141 -0
- package/src/client/panel/DeployTab.tsx +314 -0
- package/src/client/panel/FleetTab.tsx +494 -0
- package/src/client/panel/HostFormDialog.tsx +289 -0
- package/src/client/panel/HostsTab.tsx +395 -0
- package/src/client/panel/LogsTab.tsx +208 -0
- package/src/client/panel/SshPanel.tsx +105 -0
- package/src/client/panel/TerminalTab.tsx +550 -0
- package/src/client/panel/TransferTab.tsx +238 -0
- package/src/client/panel/TunnelEditDialog.tsx +174 -0
- package/src/client/panel/TunnelsTab.tsx +328 -0
- package/src/client/panel/controller.ts +507 -0
- package/src/client/panel/helpers.ts +84 -0
- package/src/client/panel/panel.module.css +1734 -0
- package/src/client/panel/tabs.ts +52 -0
- package/src/client/panel/xterm.css.ts +2 -0
- package/src/client/settings-binding.ts +184 -0
- package/src/deploy/orchestrator.ts +326 -0
- package/src/deploy/tools.ts +225 -0
- package/src/dsh-home.ts +42 -0
- package/src/engine/cluster.ts +60 -0
- package/src/engine/connection-pool.ts +721 -0
- package/src/engine/proxy-command.ts +248 -0
- package/src/engine/pty.ts +78 -0
- package/src/engine/sftp.ts +229 -0
- package/src/engine/terminal-sessions.ts +280 -0
- package/src/engine/tunnel-discovery.ts +353 -0
- package/src/engine/tunnel-remarks.ts +120 -0
- package/src/engine/tunnel.ts +300 -0
- package/src/engine.ts +195 -0
- package/src/http.ts +127 -0
- package/src/index.ts +690 -0
- package/src/inspect/checks.ts +251 -0
- package/src/inspect/inspection.ts +321 -0
- package/src/inspect/tools.ts +366 -0
- package/src/logs/search.ts +251 -0
- package/src/logs/tools.ts +160 -0
- package/src/loopback.ts +119 -0
- package/src/monitor/loop.ts +265 -0
- package/src/monitor/metrics.ts +333 -0
- package/src/mount-once.ts +142 -0
- package/src/protocol.ts +534 -0
- package/src/routes.ts +998 -0
- package/src/security/known-hosts.ts +342 -0
- package/src/security/master-secret.ts +334 -0
- package/src/security/redact.ts +119 -0
- package/src/security/secrets.ts +152 -0
- package/src/ssh-config.ts +182 -0
- package/src/store.ts +757 -0
- package/src/tool-surface.ts +96 -0
- package/src/tools.ts +550 -0
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fleet tab: one screen that answers "is anything watching the fleet,
|
|
3
|
+
* and what does it see?".
|
|
4
|
+
*
|
|
5
|
+
* The order is deliberate. Whether the monitor is armed comes first, because
|
|
6
|
+
* an operator looking at a quiet alert list needs to know whether that means
|
|
7
|
+
* "all healthy" or "nothing is checking" — those look identical and mean
|
|
8
|
+
* opposite things. The last round and the change set come next, then the
|
|
9
|
+
* alert states, then the metric trend.
|
|
10
|
+
*
|
|
11
|
+
* Nothing here starts or stops the monitor: that is a config decision with
|
|
12
|
+
* an audit trail, and a button in a panel is the wrong place to make it.
|
|
13
|
+
* The one action is "check now", which runs the same path the timer runs.
|
|
14
|
+
*
|
|
15
|
+
* Styling reuses the panel's existing vocabulary (`badge` with `data-status`,
|
|
16
|
+
* `banner` with `data-kind`, `cellMuted`, `hint`) rather than inventing a
|
|
17
|
+
* parallel set — a second set of status colours would drift from the first.
|
|
18
|
+
*/
|
|
19
|
+
import { useCallback, useEffect, useState } from 'react'
|
|
20
|
+
import type { SshApi } from '../api.ts'
|
|
21
|
+
import type {
|
|
22
|
+
AlertEventRow,
|
|
23
|
+
AlertStateRow,
|
|
24
|
+
HostChange,
|
|
25
|
+
InspectionRound,
|
|
26
|
+
MetricBucketRow,
|
|
27
|
+
MonitorStatus,
|
|
28
|
+
SecurityStatus,
|
|
29
|
+
} from '../../protocol.ts'
|
|
30
|
+
import { errorMessage, tt } from './helpers.ts'
|
|
31
|
+
import css from './panel.module.css'
|
|
32
|
+
|
|
33
|
+
/** Fleet tab props. */
|
|
34
|
+
export interface FleetTabProps {
|
|
35
|
+
/** The SSH API client. */
|
|
36
|
+
api: SshApi
|
|
37
|
+
/** Whether the panel is open, so refreshes only run while visible. */
|
|
38
|
+
active: boolean
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Format an epoch millisecond value as a short local time. */
|
|
42
|
+
function at(ms: number | undefined): string {
|
|
43
|
+
if (ms === undefined) return '—'
|
|
44
|
+
return new Date(ms).toLocaleTimeString(undefined, { hour12: false })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Format a value, keeping "unreadable" visibly distinct from zero. */
|
|
48
|
+
function value(raw: number | boolean | string | null): string {
|
|
49
|
+
if (raw === null) return '—'
|
|
50
|
+
if (typeof raw === 'boolean') return raw ? '是' : '否'
|
|
51
|
+
return String(raw)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A tiny sparkline of the trend, drawn as text so it needs no chart library. */
|
|
55
|
+
function sparkline(series: MetricBucketRow[]): string {
|
|
56
|
+
const bars = '▁▂▃▄▅▆▇█'
|
|
57
|
+
const numeric = series.filter(bucket => bucket.value !== null).map(bucket => bucket.value as number)
|
|
58
|
+
if (numeric.length < 2) return ''
|
|
59
|
+
const min = Math.min(...numeric)
|
|
60
|
+
const max = Math.max(...numeric)
|
|
61
|
+
const span = max - min
|
|
62
|
+
return numeric
|
|
63
|
+
.map(item => {
|
|
64
|
+
if (span === 0) return bars[0]
|
|
65
|
+
const index = Math.min(bars.length - 1, Math.round(((item - min) / span) * (bars.length - 1)))
|
|
66
|
+
return bars[index]
|
|
67
|
+
})
|
|
68
|
+
.join('')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The fleet monitoring tab. */
|
|
72
|
+
export function FleetTab({ api, active }: FleetTabProps) {
|
|
73
|
+
const [status, setStatus] = useState<MonitorStatus | null>(null)
|
|
74
|
+
const [rounds, setRounds] = useState<InspectionRound[]>([])
|
|
75
|
+
const [changes, setChanges] = useState<HostChange[]>([])
|
|
76
|
+
const [states, setStates] = useState<AlertStateRow[]>([])
|
|
77
|
+
const [events, setEvents] = useState<AlertEventRow[]>([])
|
|
78
|
+
const [security, setSecurity] = useState<SecurityStatus | null>(null)
|
|
79
|
+
const [series, setSeries] = useState<MetricBucketRow[]>([])
|
|
80
|
+
const [seriesHost, setSeriesHost] = useState('')
|
|
81
|
+
const [busy, setBusy] = useState(false)
|
|
82
|
+
const [error, setError] = useState<string | null>(null)
|
|
83
|
+
const [secretDraft, setSecretDraft] = useState('')
|
|
84
|
+
const [secretBusy, setSecretBusy] = useState(false)
|
|
85
|
+
const [secretNotice, setSecretNotice] = useState<string | null>(null)
|
|
86
|
+
|
|
87
|
+
const refresh = useCallback(async (): Promise<void> => {
|
|
88
|
+
try {
|
|
89
|
+
setError(null)
|
|
90
|
+
const [nextStatus, nextRounds, nextChanges, nextAlerts, nextSecurity] = await Promise.all([
|
|
91
|
+
api.monitorStatus(),
|
|
92
|
+
api.inspectionRounds(5),
|
|
93
|
+
api.inspectionDiff(),
|
|
94
|
+
api.alerts(),
|
|
95
|
+
api.security(),
|
|
96
|
+
])
|
|
97
|
+
setStatus(nextStatus)
|
|
98
|
+
setRounds(nextRounds)
|
|
99
|
+
setChanges(nextChanges)
|
|
100
|
+
setStates(nextAlerts.states)
|
|
101
|
+
setEvents(nextAlerts.events)
|
|
102
|
+
setSecurity(nextSecurity)
|
|
103
|
+
} catch (cause) {
|
|
104
|
+
setError(errorMessage(cause))
|
|
105
|
+
}
|
|
106
|
+
}, [api])
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!active) return
|
|
110
|
+
void refresh()
|
|
111
|
+
}, [active, refresh])
|
|
112
|
+
|
|
113
|
+
const tick = async (): Promise<void> => {
|
|
114
|
+
if (busy) return
|
|
115
|
+
setBusy(true)
|
|
116
|
+
setError(null)
|
|
117
|
+
try {
|
|
118
|
+
await api.monitorTick()
|
|
119
|
+
await refresh()
|
|
120
|
+
} catch (cause) {
|
|
121
|
+
setError(errorMessage(cause))
|
|
122
|
+
} finally {
|
|
123
|
+
setBusy(false)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Generate a candidate secret in the browser.
|
|
129
|
+
*
|
|
130
|
+
* The host can generate one too, but filling the field means the operator
|
|
131
|
+
* has a chance to copy it somewhere durable first — a generated key they
|
|
132
|
+
* never saw is a key they cannot restore from.
|
|
133
|
+
*/
|
|
134
|
+
const generateSecretDraft = (): string => {
|
|
135
|
+
const bytes = new Uint8Array(32)
|
|
136
|
+
crypto.getRandomValues(bytes)
|
|
137
|
+
return [...bytes].map(byte => byte.toString(16).padStart(2, '0')).join('')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const applySecret = async (): Promise<void> => {
|
|
141
|
+
if (secretBusy) return
|
|
142
|
+
setSecretBusy(true)
|
|
143
|
+
setError(null)
|
|
144
|
+
setSecretNotice(null)
|
|
145
|
+
try {
|
|
146
|
+
const outcome = await api.setSecret({
|
|
147
|
+
action: 'set',
|
|
148
|
+
...(secretDraft.trim() === '' ? {} : { secret: secretDraft.trim() }),
|
|
149
|
+
})
|
|
150
|
+
if (!outcome.ok) {
|
|
151
|
+
setError(outcome.error ?? tt('fleet.secretFailed'))
|
|
152
|
+
} else {
|
|
153
|
+
setSecretNotice(
|
|
154
|
+
tt('fleet.secretSaved')
|
|
155
|
+
.replace('{source}', outcome.source)
|
|
156
|
+
.replace('{rotated}', String(outcome.rotated)),
|
|
157
|
+
)
|
|
158
|
+
setSecretDraft('')
|
|
159
|
+
}
|
|
160
|
+
await refresh()
|
|
161
|
+
} catch (cause) {
|
|
162
|
+
setError(errorMessage(cause))
|
|
163
|
+
} finally {
|
|
164
|
+
setSecretBusy(false)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const clearSecret = async (): Promise<void> => {
|
|
169
|
+
if (secretBusy) return
|
|
170
|
+
setSecretBusy(true)
|
|
171
|
+
setError(null)
|
|
172
|
+
setSecretNotice(null)
|
|
173
|
+
try {
|
|
174
|
+
// confirmPlaintext is deliberately not sent: the host refuses to delete
|
|
175
|
+
// a key while anything still depends on it, and reports why. Passing the
|
|
176
|
+
// flag here would defeat that guard for the operator's most destructive
|
|
177
|
+
// click.
|
|
178
|
+
const outcome = await api.setSecret({ action: 'clear' })
|
|
179
|
+
if (!outcome.ok) setError(outcome.error ?? tt('fleet.secretFailed'))
|
|
180
|
+
else setSecretNotice(tt('fleet.secretCleared'))
|
|
181
|
+
await refresh()
|
|
182
|
+
} catch (cause) {
|
|
183
|
+
setError(errorMessage(cause))
|
|
184
|
+
} finally {
|
|
185
|
+
setSecretBusy(false)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const loadSeries = async (alias: string): Promise<void> => { setSeriesHost(alias)
|
|
190
|
+
if (alias === '') { setSeries([]); return }
|
|
191
|
+
try {
|
|
192
|
+
setSeries(await api.metrics(alias, '1m', 'disk-usage', 60))
|
|
193
|
+
} catch (cause) {
|
|
194
|
+
setError(errorMessage(cause))
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const lastRound = rounds[0]
|
|
199
|
+
const breached = lastRound?.results.filter(result => result.breached) ?? []
|
|
200
|
+
const blind = lastRound?.results.filter(result => result.value === null) ?? []
|
|
201
|
+
const hosts = lastRound?.targets ?? []
|
|
202
|
+
const trend = sparkline(series)
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<div className={css.fillBody}>
|
|
206
|
+
{error !== null && <div className={css.banner} data-kind="error" role="alert">{tt('common.error', { error })}</div>}
|
|
207
|
+
{secretNotice !== null && <div className={css.banner} data-kind="ok" role="status">{secretNotice}</div>}
|
|
208
|
+
|
|
209
|
+
{/* Whether anything is watching comes first: a quiet alert list and an
|
|
210
|
+
armed monitor look the same until you ask. */}
|
|
211
|
+
<div className={css.formCard}>
|
|
212
|
+
<div className={css.toolbar}>
|
|
213
|
+
<span className={css.fieldLabel}>{tt('fleet.monitor')}</span>
|
|
214
|
+
<span className={css.toolbarSpacer} />
|
|
215
|
+
<button type="button" className={css.primaryButton} onClick={() => { void tick() }} disabled={busy}>
|
|
216
|
+
{busy ? tt('fleet.checking') : tt('fleet.checkNow')}
|
|
217
|
+
</button>
|
|
218
|
+
</div>
|
|
219
|
+
{status === null ? (
|
|
220
|
+
<div className={css.empty}>{tt('fleet.loading')}</div>
|
|
221
|
+
) : status.running ? (
|
|
222
|
+
<div className={css.hint}>
|
|
223
|
+
<span className={css.badge} data-status="ok">{tt('fleet.armed')}</span>
|
|
224
|
+
{' '}{tt('fleet.interval')} {Math.round((status.intervalMs ?? 0) / 1000)}s
|
|
225
|
+
{' · '}{status.hosts ?? 0} {tt('fleet.hosts')}
|
|
226
|
+
{status.nextTickAt !== undefined && <> {' · '}{tt('fleet.nextAt')} {at(status.nextTickAt)}</>}
|
|
227
|
+
</div>
|
|
228
|
+
) : (
|
|
229
|
+
<div className={css.hint}>
|
|
230
|
+
<span className={css.badge} data-status="pending">{tt('fleet.notArmed')}</span>
|
|
231
|
+
{status.reason !== undefined && <> {status.reason}</>}
|
|
232
|
+
</div>
|
|
233
|
+
)}
|
|
234
|
+
{security !== null && (
|
|
235
|
+
<div className={css.hint}>
|
|
236
|
+
{tt('fleet.security')}:
|
|
237
|
+
{security.encryptConfigured && security.secret.available ? (
|
|
238
|
+
<span className={css.badge} data-status="ok">{tt('fleet.encrypted')} ({security.secret.source})</span>
|
|
239
|
+
) : (
|
|
240
|
+
<span className={css.badge} data-status="warn">
|
|
241
|
+
{tt('fleet.plaintext')}({security.secret.available ? tt('fleet.switchOff') : tt('fleet.noSecret')})
|
|
242
|
+
</span>
|
|
243
|
+
)}
|
|
244
|
+
{' · '}{tt('fleet.hostKey')} {security.hostKeyPolicy ?? '—'}
|
|
245
|
+
{' · '}{tt('fleet.audit')} {security.auditEnabled === true ? tt('fleet.on') : tt('fleet.off')}
|
|
246
|
+
</div>
|
|
247
|
+
)}
|
|
248
|
+
|
|
249
|
+
{/* Secret management. A master key that can only be configured by
|
|
250
|
+
setting an environment variable and restarting DSH is a key most
|
|
251
|
+
operators never set, so the panel offers the file-based path here.
|
|
252
|
+
Rotation is stated as a consequence, not an option: changing the
|
|
253
|
+
key re-encrypts every stored credential, and if that does not
|
|
254
|
+
happen the credentials are lost. */}
|
|
255
|
+
{security !== null && (
|
|
256
|
+
<div className={css.secretCard}>
|
|
257
|
+
<div className={css.toolbar}>
|
|
258
|
+
<span className={css.fieldLabel}>{tt('fleet.secretTitle')}</span>
|
|
259
|
+
<span className={css.toolbarSpacer} />
|
|
260
|
+
<span className={css.cellMuted}>{tt('fleet.secretSource')} {security.secret.source}</span>
|
|
261
|
+
</div>
|
|
262
|
+
{(security.plaintextAliases ?? []).length > 0 && (
|
|
263
|
+
<div className={css.banner} data-kind="warn">
|
|
264
|
+
{tt('fleet.plaintextList')} {(security.plaintextAliases ?? []).join('、')}
|
|
265
|
+
</div>
|
|
266
|
+
)}
|
|
267
|
+
{security.keyPath !== undefined && (
|
|
268
|
+
<p className={css.hint}>{tt('fleet.keyPath')} <code className={css.mono}>{security.keyPath}</code></p>
|
|
269
|
+
)}
|
|
270
|
+
<p className={css.hint}>{tt('fleet.secretHint')}</p>
|
|
271
|
+
<div className={css.inlineRow}>
|
|
272
|
+
<label className={css.field}>
|
|
273
|
+
<span className={css.fieldLabel}>{tt('fleet.secretInput')}</span>
|
|
274
|
+
<input
|
|
275
|
+
className={css.input}
|
|
276
|
+
type="password"
|
|
277
|
+
value={secretDraft}
|
|
278
|
+
autoComplete="new-password"
|
|
279
|
+
placeholder={tt('fleet.secretPlaceholder')}
|
|
280
|
+
onChange={event => { setSecretDraft(event.target.value) }}
|
|
281
|
+
/>
|
|
282
|
+
</label>
|
|
283
|
+
<button
|
|
284
|
+
type="button"
|
|
285
|
+
className={css.primaryButton}
|
|
286
|
+
disabled={secretBusy}
|
|
287
|
+
onClick={() => { void applySecret() }}
|
|
288
|
+
>
|
|
289
|
+
{secretBusy ? tt('fleet.secretWorking') : tt('fleet.secretApply')}
|
|
290
|
+
</button>
|
|
291
|
+
<button
|
|
292
|
+
type="button"
|
|
293
|
+
className={css.linkButton}
|
|
294
|
+
disabled={secretBusy}
|
|
295
|
+
onClick={() => { setSecretDraft(generateSecretDraft()) }}
|
|
296
|
+
>
|
|
297
|
+
{tt('fleet.secretGenerate')}
|
|
298
|
+
</button>
|
|
299
|
+
</div>
|
|
300
|
+
{security.secret.source === 'file' && (
|
|
301
|
+
<button
|
|
302
|
+
type="button"
|
|
303
|
+
className={css.linkButton}
|
|
304
|
+
data-danger=""
|
|
305
|
+
disabled={secretBusy}
|
|
306
|
+
onClick={() => { void clearSecret() }}
|
|
307
|
+
>
|
|
308
|
+
{tt('fleet.secretClear')}
|
|
309
|
+
</button>
|
|
310
|
+
)}
|
|
311
|
+
{security.encryptConfigured && !security.secret.available && (
|
|
312
|
+
<div className={css.banner} data-kind="error" role="alert">{tt('fleet.switchWithoutKey')}</div>
|
|
313
|
+
)}
|
|
314
|
+
</div>
|
|
315
|
+
)}
|
|
316
|
+
</div>
|
|
317
|
+
|
|
318
|
+
{/* The last round: what it saw, with breaches and blind probes counted
|
|
319
|
+
apart so "0 breaches" cannot hide a probe that saw nothing. */}
|
|
320
|
+
<div className={css.formCard}>
|
|
321
|
+
<div className={css.toolbar}>
|
|
322
|
+
<span className={css.fieldLabel}>{tt('fleet.lastRound')}</span>
|
|
323
|
+
<span className={css.toolbarSpacer} />
|
|
324
|
+
{lastRound !== undefined && (
|
|
325
|
+
<span className={css.hint}>
|
|
326
|
+
{at(lastRound.startedAt)} · {lastRound.durationMs}ms · {hosts.length} {tt('fleet.hosts')}
|
|
327
|
+
</span>
|
|
328
|
+
)}
|
|
329
|
+
</div>
|
|
330
|
+
{lastRound === undefined ? (
|
|
331
|
+
<div className={css.empty}>{tt('fleet.noRound')}</div>
|
|
332
|
+
) : (
|
|
333
|
+
<>
|
|
334
|
+
<div className={css.hint}>
|
|
335
|
+
{tt('fleet.breaches')} {breached.length} · {tt('fleet.blind')} {blind.length}
|
|
336
|
+
</div>
|
|
337
|
+
{breached.length > 0 && (
|
|
338
|
+
<div className={css.tableWrap}>
|
|
339
|
+
<table className={css.table}>
|
|
340
|
+
<thead>
|
|
341
|
+
<tr>
|
|
342
|
+
<th>{tt('fleet.host')}</th>
|
|
343
|
+
<th>{tt('fleet.check')}</th>
|
|
344
|
+
<th>{tt('fleet.value')}</th>
|
|
345
|
+
</tr>
|
|
346
|
+
</thead>
|
|
347
|
+
<tbody>
|
|
348
|
+
{breached.map(result => (
|
|
349
|
+
<tr key={result.alias + result.checkId}>
|
|
350
|
+
<td>{result.alias}</td>
|
|
351
|
+
<td>{result.checkId}</td>
|
|
352
|
+
<td><span className={css.badge} data-status="error">{value(result.value)}</span></td>
|
|
353
|
+
</tr>
|
|
354
|
+
))}
|
|
355
|
+
</tbody>
|
|
356
|
+
</table>
|
|
357
|
+
</div>
|
|
358
|
+
)}
|
|
359
|
+
</>
|
|
360
|
+
)}
|
|
361
|
+
</div>
|
|
362
|
+
|
|
363
|
+
{/* Changes: only what moved since the previous round, so a stable fleet
|
|
364
|
+
produces no rows instead of the same wall of green every time. */}
|
|
365
|
+
<div className={css.formCard}>
|
|
366
|
+
<div className={css.toolbar}>
|
|
367
|
+
<span className={css.fieldLabel}>{tt('fleet.changes')}</span>
|
|
368
|
+
</div>
|
|
369
|
+
{changes.length === 0 ? (
|
|
370
|
+
<div className={css.empty}>{tt('fleet.noChanges')}</div>
|
|
371
|
+
) : (
|
|
372
|
+
<div className={css.tableWrap}>
|
|
373
|
+
<table className={css.table}>
|
|
374
|
+
<thead>
|
|
375
|
+
<tr>
|
|
376
|
+
<th>{tt('fleet.host')}</th>
|
|
377
|
+
<th>{tt('fleet.check')}</th>
|
|
378
|
+
<th>{tt('fleet.before')}</th>
|
|
379
|
+
<th>{tt('fleet.after')}</th>
|
|
380
|
+
</tr>
|
|
381
|
+
</thead>
|
|
382
|
+
<tbody>
|
|
383
|
+
{changes.map((change, index) => (
|
|
384
|
+
<tr key={change.alias + change.checkId + String(index)}>
|
|
385
|
+
<td>{change.alias}</td>
|
|
386
|
+
<td>{change.title}</td>
|
|
387
|
+
<td className={css.cellMuted}>{change.before ?? '—'}</td>
|
|
388
|
+
<td>
|
|
389
|
+
{change.stateChange === undefined
|
|
390
|
+
? change.after
|
|
391
|
+
: (
|
|
392
|
+
<span className={css.badge} data-status={change.stateChange === 'new-breach' ? 'error' : 'ok'}>
|
|
393
|
+
{change.after}
|
|
394
|
+
</span>
|
|
395
|
+
)}
|
|
396
|
+
</td>
|
|
397
|
+
</tr>
|
|
398
|
+
))}
|
|
399
|
+
</tbody>
|
|
400
|
+
</table>
|
|
401
|
+
</div>
|
|
402
|
+
)}
|
|
403
|
+
</div>
|
|
404
|
+
|
|
405
|
+
{/* Alert states. A frozen row is called out explicitly: it means the
|
|
406
|
+
probe went blind, which is not the same as healthy. */}
|
|
407
|
+
<div className={css.formCard}>
|
|
408
|
+
<div className={css.toolbar}>
|
|
409
|
+
<span className={css.fieldLabel}>{tt('fleet.alerts')}</span>
|
|
410
|
+
</div>
|
|
411
|
+
{states.length === 0 ? (
|
|
412
|
+
<div className={css.empty}>{tt('fleet.noAlerts')}</div>
|
|
413
|
+
) : (
|
|
414
|
+
<div className={css.tableWrap}>
|
|
415
|
+
<table className={css.table}>
|
|
416
|
+
<thead>
|
|
417
|
+
<tr>
|
|
418
|
+
<th>{tt('fleet.host')}</th>
|
|
419
|
+
<th>{tt('fleet.rule')}</th>
|
|
420
|
+
<th>{tt('fleet.state')}</th>
|
|
421
|
+
<th>{tt('fleet.value')}</th>
|
|
422
|
+
</tr>
|
|
423
|
+
</thead>
|
|
424
|
+
<tbody>
|
|
425
|
+
{states.map(row => (
|
|
426
|
+
<tr key={row.ruleId + row.alias}>
|
|
427
|
+
<td>{row.alias}</td>
|
|
428
|
+
<td>{row.ruleId}</td>
|
|
429
|
+
<td>
|
|
430
|
+
<span
|
|
431
|
+
className={css.badge}
|
|
432
|
+
data-status={row.state === 'firing' ? 'error' : row.state === 'pending' ? 'warn' : row.state === 'frozen' ? 'pending' : 'ok'}
|
|
433
|
+
>
|
|
434
|
+
{row.state}
|
|
435
|
+
</span>
|
|
436
|
+
</td>
|
|
437
|
+
<td>{row.lastValue ?? '—'}</td>
|
|
438
|
+
</tr>
|
|
439
|
+
))}
|
|
440
|
+
</tbody>
|
|
441
|
+
</table>
|
|
442
|
+
</div>
|
|
443
|
+
)}
|
|
444
|
+
{events.length > 0 && (
|
|
445
|
+
<details className={css.cellDetails}>
|
|
446
|
+
<summary>{tt('fleet.events')} ({events.length})</summary>
|
|
447
|
+
<table className={css.table}>
|
|
448
|
+
<tbody>
|
|
449
|
+
{events.map((event, index) => (
|
|
450
|
+
<tr key={event.ruleId + event.alias + String(event.at) + String(index)}>
|
|
451
|
+
<td className={css.cellMuted}>{at(event.at)}</td>
|
|
452
|
+
<td>{event.alias}</td>
|
|
453
|
+
<td>{event.ruleId}</td>
|
|
454
|
+
<td>
|
|
455
|
+
<span className={css.badge} data-status={event.kind === 'trigger' ? 'error' : 'ok'}>
|
|
456
|
+
{event.kind === 'trigger' ? tt('fleet.trigger') : tt('fleet.recover')}
|
|
457
|
+
</span>
|
|
458
|
+
</td>
|
|
459
|
+
<td>{event.value}</td>
|
|
460
|
+
</tr>
|
|
461
|
+
))}
|
|
462
|
+
</tbody>
|
|
463
|
+
</table>
|
|
464
|
+
</details>
|
|
465
|
+
)}
|
|
466
|
+
</div>
|
|
467
|
+
|
|
468
|
+
{/* Trend: a text sparkline, because a chart library is a dependency
|
|
469
|
+
this panel does not need to answer "is this going up?". */}
|
|
470
|
+
<div className={css.formCard}>
|
|
471
|
+
<div className={css.toolbar}>
|
|
472
|
+
<span className={css.fieldLabel}>{tt('fleet.trend')}</span>
|
|
473
|
+
</div>
|
|
474
|
+
{hosts.length === 0 ? (
|
|
475
|
+
<div className={css.empty}>{tt('fleet.noRound')}</div>
|
|
476
|
+
) : (
|
|
477
|
+
<label className={css.field}>
|
|
478
|
+
<span className={css.fieldLabel}>{tt('fleet.host')}</span>
|
|
479
|
+
<select className={css.input} value={seriesHost} onChange={event => { void loadSeries(event.target.value) }}>
|
|
480
|
+
<option value="">{tt('fleet.pickHost')}</option>
|
|
481
|
+
{hosts.map(host => <option key={host} value={host}>{host}</option>)}
|
|
482
|
+
</select>
|
|
483
|
+
</label>
|
|
484
|
+
)}
|
|
485
|
+
{trend !== '' && (
|
|
486
|
+
<div className={css.hint}>
|
|
487
|
+
{tt('fleet.diskTrend')} <code className={css.mono}>{trend}</code>
|
|
488
|
+
{' '}({series.length} {tt('fleet.buckets')})
|
|
489
|
+
</div>
|
|
490
|
+
)}
|
|
491
|
+
</div>
|
|
492
|
+
</div>
|
|
493
|
+
)
|
|
494
|
+
}
|