dsh-ops-kit 0.4.6 → 0.4.8
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/client.js +171 -124
- package/index.js +100 -7
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -687,6 +687,15 @@ window.__ModuleLoader__.load({
|
|
|
687
687
|
h('polyline', { points: d, fill: 'none', stroke: color, strokeWidth: 1.6 }))
|
|
688
688
|
}
|
|
689
689
|
|
|
690
|
+
const sizeText = (bytes, dir) => {
|
|
691
|
+
if (dir) return '—'
|
|
692
|
+
const n = Number(bytes) || 0
|
|
693
|
+
if (n < 1024) return `${n} B`
|
|
694
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
|
695
|
+
if (n < 1024 * 1024 * 1024) return `${(n / 1048576).toFixed(1)} MB`
|
|
696
|
+
return `${(n / 1073741824).toFixed(1)} GB`
|
|
697
|
+
}
|
|
698
|
+
|
|
690
699
|
const viewHint = (text) => h('p', { className: 'ops-sub', style: { margin: 0, fontSize: '12.5px' } }, text)
|
|
691
700
|
|
|
692
701
|
const hostPicker = (hosts, value, onChange) => h('div', { className: 'ops-chips' },
|
|
@@ -697,6 +706,80 @@ window.__ModuleLoader__.load({
|
|
|
697
706
|
}, host.name)))
|
|
698
707
|
|
|
699
708
|
/** 监控:CPU/内存/磁盘/网络/IO 曲线;自己加载采样,不牵动其它 tab。 */
|
|
709
|
+
/** 诊断卡片:概览页和主机详情页共用。 */
|
|
710
|
+
function renderDiagCard({ diag, askAi, setDiag, setNotice, cleanupHost, doAction, setTab, setCHost }) {
|
|
711
|
+
return diag ? h('div', { className: 'ops-card' },
|
|
712
|
+
h('div', { className: 'ops-card-h' },
|
|
713
|
+
h('span', null, `${T.diagnose}: ${diag.host}`),
|
|
714
|
+
h('span', { className: diag.result?.level === 'ok' ? 'ops-ok' : diag.result?.level === 'warn' ? 'ops-warn' : 'ops-bad', style: { fontSize: '12px' } },
|
|
715
|
+
diag.loading ? T.diagnosing : (diag.result?.headline || ''))),
|
|
716
|
+
h('div', { className: 'ops-card-b' },
|
|
717
|
+
h('div', { className: 'ops-chips' },
|
|
718
|
+
h('input', {
|
|
719
|
+
className: 'ops-input',
|
|
720
|
+
style: { flex: '1 1 260px' },
|
|
721
|
+
placeholder: T.askPh,
|
|
722
|
+
value: diag.question,
|
|
723
|
+
onChange: e => setDiag({ ...diag, question: e.target.value }),
|
|
724
|
+
onKeyDown: e => { if (e.key === 'Enter') void askAi(diag.host, diag.question) },
|
|
725
|
+
}),
|
|
726
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: diag.loading, onClick: () => { void askAi(diag.host, diag.question) } }, diag.loading ? T.diagnosing : T.ask),
|
|
727
|
+
h('button', {
|
|
728
|
+
className: 'ops-btn ops-btn-sm',
|
|
729
|
+
onClick: () => {
|
|
730
|
+
const text = `用运维工具排查一下 ${diag.host}:${diag.question || L('有什么问题?', 'What is the issue?')}`
|
|
731
|
+
void navigator.clipboard?.writeText(text).then(() => {
|
|
732
|
+
setNotice(L('已复制,粘贴到对话框让 AI 深入分析', 'Copied — paste it into the chat for the AI to dig in'))
|
|
733
|
+
setTimeout(() => setNotice(''), 3000)
|
|
734
|
+
}).catch(() => {})
|
|
735
|
+
},
|
|
736
|
+
}, L('复制到对话', 'Copy to chat')),
|
|
737
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDiag(null) }, T.close2)),
|
|
738
|
+
h('div', { className: 'ops-chips' },
|
|
739
|
+
...T.askPreset.map(text => h('button', { key: text, className: 'ops-btn ops-btn-sm', onClick: () => { void askAi(diag.host, text) } }, text))),
|
|
740
|
+
diag.loading ? h('p', { className: 'ops-empty' }, T.loading) : null,
|
|
741
|
+
!diag.loading && diag.result ? h('div', null,
|
|
742
|
+
diag.result.ai
|
|
743
|
+
? h('div', {
|
|
744
|
+
style: {
|
|
745
|
+
padding: '12px 14px',
|
|
746
|
+
margin: '0 0 10px',
|
|
747
|
+
borderRadius: '10px',
|
|
748
|
+
background: 'var(--dsw-alias-bg,#15181c)',
|
|
749
|
+
border: '1px solid var(--dsw-alias-border,#3a3f45)',
|
|
750
|
+
fontSize: '13px',
|
|
751
|
+
lineHeight: 1.75,
|
|
752
|
+
whiteSpace: 'pre-wrap',
|
|
753
|
+
},
|
|
754
|
+
}, diag.result.ai)
|
|
755
|
+
: (diag.result.summary ? h('p', { className: 'ops-sub', style: { margin: '0 0 10px', lineHeight: 1.7 } }, diag.result.summary) : null),
|
|
756
|
+
...((diag.result.sections || []).map((item, index) => h('div', {
|
|
757
|
+
key: index,
|
|
758
|
+
style: { display: 'flex', gap: '10px', alignItems: 'flex-start', padding: '8px 0', borderTop: index === 0 ? 'none' : '1px solid var(--dsw-alias-border,#3a3f45)' },
|
|
759
|
+
},
|
|
760
|
+
h('i', { className: 'ops-dot ' + (item.status === 'ok' ? 'ok' : item.status === 'warn' ? 'warn' : item.status === 'bad' ? 'bad' : 'unknown'), style: { marginTop: '5px' } }),
|
|
761
|
+
h('div', { style: { minWidth: 0 } },
|
|
762
|
+
h('div', { style: { fontSize: '13px', fontWeight: 600 } }, item.title),
|
|
763
|
+
h('div', { className: 'ops-sub', style: { lineHeight: 1.6 } }, item.detail),
|
|
764
|
+
item.advice ? h('div', { className: 'ops-dim', style: { lineHeight: 1.6 } }, item.advice) : null)))),
|
|
765
|
+
(diag.result.reasons || []).length && !(diag.result.sections || []).length
|
|
766
|
+
? h('div', null, ...diag.result.reasons.map((reason, index) => h('div', { key: 'r' + index, className: 'ops-sub' }, '· ' + reason)))
|
|
767
|
+
: null,
|
|
768
|
+
(diag.result.actions || []).length ? h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
769
|
+
h('span', { className: 'ops-sub' }, T.next),
|
|
770
|
+
...(diag.result.actions || []).map(action => h('button', {
|
|
771
|
+
key: action.id,
|
|
772
|
+
className: 'ops-btn ops-btn-sm',
|
|
773
|
+
onClick: () => {
|
|
774
|
+
if (action.id === 'cleanup') void cleanupHost(diag.host)
|
|
775
|
+
else if (action.id === 'goto-service') { setTab(3); setCHost(diag.host) }
|
|
776
|
+
else if (action.id.startsWith('restart:')) void doAction('service', action.id.slice(8), 'restart', diag.host)
|
|
777
|
+
},
|
|
778
|
+
}, action.label))) : null,
|
|
779
|
+
diag.result.hint ? h('p', { className: 'ops-warn', style: { fontSize: '12px', margin: '8px 0 0' } }, diag.result.hint) : null) : null))
|
|
780
|
+
: null
|
|
781
|
+
}
|
|
782
|
+
|
|
700
783
|
/** 只有这类 unit 值得推荐给普通用户;dbus/getty/gssproxy 等系统服务不提示。 */
|
|
701
784
|
const BUSINESS_SERVICE = /(nginx|apache|httpd|mysql|mariadb|postgres|redis|mongo|elasticsearch|php|java|tomcat|node|pm2|gunicorn|uwsgi|docker|containerd|supervisor|frp|traefik|caddy|haproxy|kafka|rabbit|memcached|minio|baota)/i
|
|
702
785
|
const BUSINESS_PORTS = new Set([80, 443, 3000, 3306, 5432, 6379, 8000, 8080, 8443, 9000, 9200, 27017])
|
|
@@ -1065,7 +1148,55 @@ window.__ModuleLoader__.load({
|
|
|
1065
1148
|
}
|
|
1066
1149
|
|
|
1067
1150
|
/** 文件管理:浏览/上传/下载/编辑/压缩,状态全部自带。 */
|
|
1068
|
-
|
|
1151
|
+
const CHUNK_BYTES = 4 * 1024 * 1024
|
|
1152
|
+
|
|
1153
|
+
/** 分片下载到本地(文件页与备份下载共用)。 */
|
|
1154
|
+
async function downloadFileTo({ host, path, name, setBusy, setProgress, setError }) {
|
|
1155
|
+
setBusy('dl:' + path)
|
|
1156
|
+
try {
|
|
1157
|
+
const first = await api(`download-chunk?host=${encodeURIComponent(host)}&path=${encodeURIComponent(path)}&offset=0&length=1`, {}, 60_000)
|
|
1158
|
+
const size = Number(first.size) || 0
|
|
1159
|
+
if (size > 100 * 1024 * 1024) { setError(T.fsTooBig); return }
|
|
1160
|
+
const parts = []
|
|
1161
|
+
let offset = 0
|
|
1162
|
+
const started = Date.now()
|
|
1163
|
+
setProgress({ label: T.fsDownloading, name, done: 0, total: size, eta: null, speed: 0 })
|
|
1164
|
+
while (offset < size) {
|
|
1165
|
+
let chunk = null
|
|
1166
|
+
for (let attempt = 0; attempt < 3 && !chunk; attempt += 1) {
|
|
1167
|
+
try {
|
|
1168
|
+
chunk = await api(`download-chunk?host=${encodeURIComponent(host)}&path=${encodeURIComponent(path)}&offset=${offset}&length=${CHUNK_BYTES}`, {}, 300_000)
|
|
1169
|
+
} catch (error) {
|
|
1170
|
+
if (attempt === 2) throw error
|
|
1171
|
+
await new Promise(resolve => setTimeout(resolve, 800))
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
const bytes = Uint8Array.from(atob(chunk.base64 || ''), ch => ch.charCodeAt(0))
|
|
1175
|
+
if (bytes.length === 0) break
|
|
1176
|
+
parts.push(bytes)
|
|
1177
|
+
offset += bytes.length
|
|
1178
|
+
const seconds = Math.max(0.5, (Date.now() - started) / 1000)
|
|
1179
|
+
const speed = offset / seconds
|
|
1180
|
+
setProgress({
|
|
1181
|
+
label: T.fsDownloading,
|
|
1182
|
+
name,
|
|
1183
|
+
done: offset,
|
|
1184
|
+
total: size,
|
|
1185
|
+
speed: Math.round((speed / 1048576) * 10) / 10,
|
|
1186
|
+
eta: speed > 0 ? Math.max(0, Math.round((size - offset) / speed)) : null,
|
|
1187
|
+
})
|
|
1188
|
+
}
|
|
1189
|
+
const url = URL.createObjectURL(new Blob(parts))
|
|
1190
|
+
const a = document.createElement('a')
|
|
1191
|
+
a.href = url
|
|
1192
|
+
a.download = name || 'download'
|
|
1193
|
+
a.click()
|
|
1194
|
+
setTimeout(() => URL.revokeObjectURL(url), 3000)
|
|
1195
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy(''); setProgress(null) }
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
function FilesTab({ host, picker, setError, setNotice, confirmDialog, timeoutFor }) {
|
|
1069
1200
|
const [fsPath, setFsPath] = React.useState('/')
|
|
1070
1201
|
const [fsEntries, setFsEntries] = React.useState(null)
|
|
1071
1202
|
const [fsTree, setFsTree] = React.useState({})
|
|
@@ -1108,7 +1239,6 @@ window.__ModuleLoader__.load({
|
|
|
1108
1239
|
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
1109
1240
|
}
|
|
1110
1241
|
|
|
1111
|
-
const CHUNK_BYTES = 4 * 1024 * 1024
|
|
1112
1242
|
const IMAGE_EXT = /\.(png|jpe?g|gif|webp|bmp|svg|ico)$/i
|
|
1113
1243
|
|
|
1114
1244
|
const hostFsKey = () => `ops-kit:fs:${host || 'default'}`
|
|
@@ -1142,49 +1272,7 @@ window.__ModuleLoader__.load({
|
|
|
1142
1272
|
saveFavs({ ...fsFavs, favs: has ? fsFavs.favs.filter(item => item !== path) : [path, ...fsFavs.favs].slice(0, 12) })
|
|
1143
1273
|
}
|
|
1144
1274
|
|
|
1145
|
-
const downloadFile =
|
|
1146
|
-
setFsBusy('dl:' + path)
|
|
1147
|
-
try {
|
|
1148
|
-
const first = await api(`download-chunk?host=${encodeURIComponent(host)}&path=${encodeURIComponent(path)}&offset=0&length=1`, {}, 60_000)
|
|
1149
|
-
const size = Number(first.size) || 0
|
|
1150
|
-
if (size > 100 * 1024 * 1024) { setError(T.fsTooBig); return }
|
|
1151
|
-
const parts = []
|
|
1152
|
-
let offset = 0
|
|
1153
|
-
const started = Date.now()
|
|
1154
|
-
setFsProgress({ label: T.fsDownloading, name, done: 0, total: size, eta: null, speed: 0 })
|
|
1155
|
-
while (offset < size) {
|
|
1156
|
-
let chunk = null
|
|
1157
|
-
for (let attempt = 0; attempt < 3 && !chunk; attempt += 1) {
|
|
1158
|
-
try {
|
|
1159
|
-
chunk = await api(`download-chunk?host=${encodeURIComponent(host)}&path=${encodeURIComponent(path)}&offset=${offset}&length=${CHUNK_BYTES}`, {}, 300_000)
|
|
1160
|
-
} catch (error) {
|
|
1161
|
-
if (attempt === 2) throw error
|
|
1162
|
-
await new Promise(resolve => setTimeout(resolve, 800))
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
const bytes = Uint8Array.from(atob(chunk.base64 || ''), ch => ch.charCodeAt(0))
|
|
1166
|
-
if (bytes.length === 0) break
|
|
1167
|
-
parts.push(bytes)
|
|
1168
|
-
offset += bytes.length
|
|
1169
|
-
const seconds = Math.max(0.5, (Date.now() - started) / 1000)
|
|
1170
|
-
const speed = offset / seconds
|
|
1171
|
-
setFsProgress({
|
|
1172
|
-
label: T.fsDownloading,
|
|
1173
|
-
name,
|
|
1174
|
-
done: offset,
|
|
1175
|
-
total: size,
|
|
1176
|
-
speed: Math.round((speed / 1048576) * 10) / 10,
|
|
1177
|
-
eta: speed > 0 ? Math.max(0, Math.round((size - offset) / speed)) : null,
|
|
1178
|
-
})
|
|
1179
|
-
}
|
|
1180
|
-
const url = URL.createObjectURL(new Blob(parts))
|
|
1181
|
-
const a = document.createElement('a')
|
|
1182
|
-
a.href = url
|
|
1183
|
-
a.download = name || 'download'
|
|
1184
|
-
a.click()
|
|
1185
|
-
setTimeout(() => URL.revokeObjectURL(url), 3000)
|
|
1186
|
-
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy(''); setFsProgress(null) }
|
|
1187
|
-
}
|
|
1275
|
+
const downloadFile = (path, name) => downloadFileTo({ host, path, name, setBusy: setFsBusy, setProgress: setFsProgress, setError })
|
|
1188
1276
|
|
|
1189
1277
|
const uploadFile = async (file) => {
|
|
1190
1278
|
if (!file) return
|
|
@@ -1860,7 +1948,7 @@ window.__ModuleLoader__.load({
|
|
|
1860
1948
|
|
|
1861
1949
|
const assistantView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
|
|
1862
1950
|
h('div', { className: 'ops-chips' },
|
|
1863
|
-
|
|
1951
|
+
picker,
|
|
1864
1952
|
h('span', { className: 'ops-chip' }, T.aiName),
|
|
1865
1953
|
chatNotice ? h('span', { className: 'ops-ok', style: { fontSize: '12px' } }, chatNotice) : null),
|
|
1866
1954
|
h('div', { className: 'ops-chat', id: 'ops-chat' },
|
|
@@ -1890,7 +1978,7 @@ window.__ModuleLoader__.load({
|
|
|
1890
1978
|
}
|
|
1891
1979
|
|
|
1892
1980
|
/** 终端与控制台:控制台输入/历史自带,SSH 会话由 Panel 持有。 */
|
|
1893
|
-
function TerminalTab({ host, picker, term, setTerm, openTerm, closeTerm, busy, aiMode, aiDraft, quickCommands, termKey, sendKey, focusTerm, generateCommand, runGenerated, aiResult, aiIntent, setAiIntent, aiBusy, setAiMode, setAiDraft, askLog, error, output, consoleCmd, setConsoleCmd, consoleOut, consoleHistory, runConsole }) {
|
|
1981
|
+
function TerminalTab({ host, picker, term, setTerm, openTerm, closeTerm, busy, aiMode, aiDraft, quickCommands, termKey, sendKey, focusTerm, generateCommand, runGenerated, aiResult, setAiResult, aiIntent, setAiIntent, aiBusy, setAiMode, setAiDraft, askLog, error, output, consoleCmd, setConsoleCmd, consoleOut, consoleHistory, runConsole }) {
|
|
1894
1982
|
|
|
1895
1983
|
const terminalView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
|
|
1896
1984
|
viewHint(T.hintTerminal),
|
|
@@ -2190,7 +2278,21 @@ window.__ModuleLoader__.load({
|
|
|
2190
2278
|
}
|
|
2191
2279
|
|
|
2192
2280
|
/** 应用:服务/容器/Java 进程的日志与操作,配置编辑。 */
|
|
2193
|
-
function AppsTab({ addSuggestions, busy, cHost, config, detailHost, doAction, fileState, hosts, inv, loadInv, monBusy, monitorSuggestions, openFile, output, saveFile, setCHost, setDetailTab, setFileState, setLogRequest }) {
|
|
2281
|
+
function AppsTab({ addSuggestions, busy, cHost, config, confirmDialog, detailHost, doAction, fileState, hosts, inv, loadInv, monBusy, monitorSuggestions, openFile, output, saveFile, setError, setCHost, setDetailTab, setFileState, setLogRequest }) {
|
|
2282
|
+
const renameApp = async (app) => {
|
|
2283
|
+
const answer = await confirmDialog({
|
|
2284
|
+
title: L('设置别名', 'Set alias'),
|
|
2285
|
+
message: L('起个好记的名字,列表里优先显示;留空恢复默认。', 'A friendly name shown first; leave it blank to reset.'),
|
|
2286
|
+
details: [{ k: L('程序', 'App'), v: app.name }],
|
|
2287
|
+
prompt: L('别名', 'Alias'),
|
|
2288
|
+
})
|
|
2289
|
+
if (answer === false) return
|
|
2290
|
+
try {
|
|
2291
|
+
await api('aliases', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, key: app.key, alias: String(answer || '') }) }, 20_000)
|
|
2292
|
+
await loadInv(cHost || hosts[0]?.name, true)
|
|
2293
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2194
2296
|
const appsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
2195
2297
|
viewHint(T.hintApps),
|
|
2196
2298
|
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(hosts, cHost, setCHost)),
|
|
@@ -2228,10 +2330,16 @@ window.__ModuleLoader__.load({
|
|
|
2228
2330
|
'Logs shows recent output; Restart briefly interrupts the service. System units are not listed.')),
|
|
2229
2331
|
(inv?.apps || []).length === 0 ? h('p', { className: 'ops-empty' }, T.empty)
|
|
2230
2332
|
: h('div', { className: 'ops-list' }, ...(inv.apps || []).map(app => h('div', { key: app.kind + app.name, className: 'ops-row' },
|
|
2231
|
-
h('span', null,
|
|
2333
|
+
h('span', null,
|
|
2334
|
+
h('span', { className: 'ops-chip', style: { marginRight: '6px' } }, app.kind),
|
|
2335
|
+
h('span', { className: 'ops-name' }, app.alias || app.display || app.name),
|
|
2336
|
+
(app.alias || app.display) && (app.alias || app.display) !== app.name
|
|
2337
|
+
? h('span', { className: 'ops-dim', style: { marginLeft: '8px', fontSize: '11px' } }, app.name)
|
|
2338
|
+
: null),
|
|
2232
2339
|
h('span', { className: 'ops-dim' }, app.ports || app.status || ''),
|
|
2233
2340
|
h('span', { className: app.status ? 'ops-ok' : 'ops-dim', style: { fontSize: '12px' } }, app.status || ''),
|
|
2234
2341
|
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
2342
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void renameApp(app) } }, L('别名', 'Alias')),
|
|
2235
2343
|
app.config ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void openFile(app.config, app.name) } }, T.configFile) : null,
|
|
2236
2344
|
h('button', {
|
|
2237
2345
|
className: 'ops-btn ops-btn-sm',
|
|
@@ -2330,76 +2438,7 @@ window.__ModuleLoader__.load({
|
|
|
2330
2438
|
h('div', { className: 'ops-num' }, h('b', { className: 'ops-warn' }, String(countOf('warn'))), h('span', null, T.needLook)),
|
|
2331
2439
|
h('div', { className: 'ops-num' }, h('b', { className: 'ops-bad' }, String(countOf('bad'))), h('span', null, T.offline)))
|
|
2332
2440
|
|
|
2333
|
-
const diagView = diag
|
|
2334
|
-
h('div', { className: 'ops-card-h' },
|
|
2335
|
-
h('span', null, `${T.diagnose}: ${diag.host}`),
|
|
2336
|
-
h('span', { className: diag.result?.level === 'ok' ? 'ops-ok' : diag.result?.level === 'warn' ? 'ops-warn' : 'ops-bad', style: { fontSize: '12px' } },
|
|
2337
|
-
diag.loading ? T.diagnosing : (diag.result?.headline || ''))),
|
|
2338
|
-
h('div', { className: 'ops-card-b' },
|
|
2339
|
-
h('div', { className: 'ops-chips' },
|
|
2340
|
-
h('input', {
|
|
2341
|
-
className: 'ops-input',
|
|
2342
|
-
style: { flex: '1 1 260px' },
|
|
2343
|
-
placeholder: T.askPh,
|
|
2344
|
-
value: diag.question,
|
|
2345
|
-
onChange: e => setDiag({ ...diag, question: e.target.value }),
|
|
2346
|
-
onKeyDown: e => { if (e.key === 'Enter') void askAi(diag.host, diag.question) },
|
|
2347
|
-
}),
|
|
2348
|
-
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: diag.loading, onClick: () => { void askAi(diag.host, diag.question) } }, diag.loading ? T.diagnosing : T.ask),
|
|
2349
|
-
h('button', {
|
|
2350
|
-
className: 'ops-btn ops-btn-sm',
|
|
2351
|
-
onClick: () => {
|
|
2352
|
-
const text = `用运维工具排查一下 ${diag.host}:${diag.question || L('有什么问题?', 'What is the issue?')}`
|
|
2353
|
-
void navigator.clipboard?.writeText(text).then(() => {
|
|
2354
|
-
setNotice(L('已复制,粘贴到对话框让 AI 深入分析', 'Copied — paste it into the chat for the AI to dig in'))
|
|
2355
|
-
setTimeout(() => setNotice(''), 3000)
|
|
2356
|
-
}).catch(() => {})
|
|
2357
|
-
},
|
|
2358
|
-
}, L('复制到对话', 'Copy to chat')),
|
|
2359
|
-
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDiag(null) }, T.close2)),
|
|
2360
|
-
h('div', { className: 'ops-chips' },
|
|
2361
|
-
...T.askPreset.map(text => h('button', { key: text, className: 'ops-btn ops-btn-sm', onClick: () => { void askAi(diag.host, text) } }, text))),
|
|
2362
|
-
diag.loading ? h('p', { className: 'ops-empty' }, T.loading) : null,
|
|
2363
|
-
!diag.loading && diag.result ? h('div', null,
|
|
2364
|
-
diag.result.ai
|
|
2365
|
-
? h('div', {
|
|
2366
|
-
style: {
|
|
2367
|
-
padding: '12px 14px',
|
|
2368
|
-
margin: '0 0 10px',
|
|
2369
|
-
borderRadius: '10px',
|
|
2370
|
-
background: 'var(--dsw-alias-bg,#15181c)',
|
|
2371
|
-
border: '1px solid var(--dsw-alias-border,#3a3f45)',
|
|
2372
|
-
fontSize: '13px',
|
|
2373
|
-
lineHeight: 1.75,
|
|
2374
|
-
whiteSpace: 'pre-wrap',
|
|
2375
|
-
},
|
|
2376
|
-
}, diag.result.ai)
|
|
2377
|
-
: (diag.result.summary ? h('p', { className: 'ops-sub', style: { margin: '0 0 10px', lineHeight: 1.7 } }, diag.result.summary) : null),
|
|
2378
|
-
...((diag.result.sections || []).map((item, index) => h('div', {
|
|
2379
|
-
key: index,
|
|
2380
|
-
style: { display: 'flex', gap: '10px', alignItems: 'flex-start', padding: '8px 0', borderTop: index === 0 ? 'none' : '1px solid var(--dsw-alias-border,#3a3f45)' },
|
|
2381
|
-
},
|
|
2382
|
-
h('i', { className: 'ops-dot ' + (item.status === 'ok' ? 'ok' : item.status === 'warn' ? 'warn' : item.status === 'bad' ? 'bad' : 'unknown'), style: { marginTop: '5px' } }),
|
|
2383
|
-
h('div', { style: { minWidth: 0 } },
|
|
2384
|
-
h('div', { style: { fontSize: '13px', fontWeight: 600 } }, item.title),
|
|
2385
|
-
h('div', { className: 'ops-sub', style: { lineHeight: 1.6 } }, item.detail),
|
|
2386
|
-
item.advice ? h('div', { className: 'ops-dim', style: { lineHeight: 1.6 } }, item.advice) : null)))),
|
|
2387
|
-
(diag.result.reasons || []).length && !(diag.result.sections || []).length
|
|
2388
|
-
? h('div', null, ...diag.result.reasons.map((reason, index) => h('div', { key: 'r' + index, className: 'ops-sub' }, '· ' + reason)))
|
|
2389
|
-
: null,
|
|
2390
|
-
(diag.result.actions || []).length ? h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
2391
|
-
h('span', { className: 'ops-sub' }, T.next),
|
|
2392
|
-
...(diag.result.actions || []).map(action => h('button', {
|
|
2393
|
-
key: action.id,
|
|
2394
|
-
className: 'ops-btn ops-btn-sm',
|
|
2395
|
-
onClick: () => {
|
|
2396
|
-
if (action.id === 'cleanup') void cleanupHost(diag.host)
|
|
2397
|
-
else if (action.id === 'goto-service') { setTab(3); setCHost(diag.host) }
|
|
2398
|
-
else if (action.id.startsWith('restart:')) void doAction('service', action.id.slice(8), 'restart', diag.host)
|
|
2399
|
-
},
|
|
2400
|
-
}, action.label))) : null,
|
|
2401
|
-
diag.result.hint ? h('p', { className: 'ops-warn', style: { fontSize: '12px', margin: '8px 0 0' } }, diag.result.hint) : null) : null))
|
|
2402
|
-
: null
|
|
2441
|
+
const diagView = renderDiagCard({ diag, askAi, setDiag, setNotice, cleanupHost, doAction, setTab, setCHost })
|
|
2403
2442
|
|
|
2404
2443
|
const onboardingView = h('div', { className: 'ops-card' },
|
|
2405
2444
|
h('div', { className: 'ops-card-h' },
|
|
@@ -2752,7 +2791,7 @@ window.__ModuleLoader__.load({
|
|
|
2752
2791
|
certsCard,
|
|
2753
2792
|
monitorsCard,
|
|
2754
2793
|
servicesCard,
|
|
2755
|
-
diag && diag.host === host.name ?
|
|
2794
|
+
diag && diag.host === host.name ? renderDiagCard({ diag, askAi, setDiag, setNotice, cleanupHost, doAction, setTab, setCHost }) : null)
|
|
2756
2795
|
})()
|
|
2757
2796
|
|
|
2758
2797
|
return hostDetailView
|
|
@@ -2980,7 +3019,7 @@ window.__ModuleLoader__.load({
|
|
|
2980
3019
|
if (!command) return
|
|
2981
3020
|
setBusy('console')
|
|
2982
3021
|
try {
|
|
2983
|
-
const payload = { command, hosts: [
|
|
3022
|
+
const payload = { command, hosts: [cHost || hosts[0]?.name] }
|
|
2984
3023
|
if (options.confirm) payload.confirm = true
|
|
2985
3024
|
const data = await api('exec', { method: 'POST', body: JSON.stringify(payload) }, timeoutFor('action'))
|
|
2986
3025
|
if (data?.needsConfirm) {
|
|
@@ -3276,7 +3315,8 @@ window.__ModuleLoader__.load({
|
|
|
3276
3315
|
for (const row of inv.services || []) {
|
|
3277
3316
|
const unit = String(row).trim().split(/\s+/)[0]
|
|
3278
3317
|
if (!unit || !isBusinessService(unit)) continue
|
|
3279
|
-
|
|
3318
|
+
const known = (inv.apps || []).find(app => app.kind === 'service' && app.name === unit)
|
|
3319
|
+
items.push({ type: 'service', target: unit, label: known?.alias || known?.display || serviceLabel(row) || unit })
|
|
3280
3320
|
}
|
|
3281
3321
|
for (const port of inv.portsParsed || []) {
|
|
3282
3322
|
if (!port?.port) continue
|
|
@@ -3619,7 +3659,14 @@ window.__ModuleLoader__.load({
|
|
|
3619
3659
|
|
|
3620
3660
|
const downloadBackup = async () => {
|
|
3621
3661
|
if (!cleanBackupFile) return
|
|
3622
|
-
await
|
|
3662
|
+
await downloadFileTo({
|
|
3663
|
+
host: cHost || hosts[0]?.name,
|
|
3664
|
+
path: cleanBackupFile.path,
|
|
3665
|
+
name: cleanBackupFile.path.split('/').pop(),
|
|
3666
|
+
setBusy: setBackupBusy,
|
|
3667
|
+
setProgress: () => {},
|
|
3668
|
+
setError,
|
|
3669
|
+
})
|
|
3623
3670
|
}
|
|
3624
3671
|
|
|
3625
3672
|
const confirmClean = async () => {
|
|
@@ -3808,7 +3855,7 @@ window.__ModuleLoader__.load({
|
|
|
3808
3855
|
: ['df -h', 'free -h', 'uptime', 'systemctl --failed', 'docker ps', 'tail -n 30 /var/log/messages']
|
|
3809
3856
|
|
|
3810
3857
|
const subBody = detailHost
|
|
3811
|
-
? ({ monitor: h(MonitorTab, { hosts, detailHost, detailTab, loadingMap, markLoading, setError }), config: h(ConfigTab, { busy, cHost, detailHost, histDiff, histList, histPath, hosts, inv, loadHistory, loadInv, monitorSuggestions, monitors, opBusy, restoreVersion, sectionList, services, setCHost, setHistPath, showDiff }), apps: h(AppsTab, { addSuggestions, busy, cHost, config, detailHost, doAction, fileState, hosts, inv, loadInv, monBusy, monitorSuggestions, openFile, output, saveFile, setCHost, setDetailTab, setFileState, setLogRequest }), logs: h(LogsTab, { host: cHost || hosts[0]?.name, notice, logRequest, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), setError, setNotice, timeoutFor, onInventoryRefresh: loadInv, config, logUsageData, loadLogUsage, openCleanPreview, cleanBusyHost, cleanRunBusy, backupBusy }), files: h(FilesTab, { host: cHost || hosts[0]?.name, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), setError, setNotice, confirmDialog }), terminal: h(TerminalTab, { host: cHost || hosts[0]?.name, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), term, setTerm, openTerm, closeTerm, busy, aiMode, aiDraft, quickCommands, termKey, sendKey, focusTerm, generateCommand, runGenerated, aiResult, aiIntent, setAiIntent, aiBusy, setAiMode, setAiDraft, askLog, error, output, consoleCmd, setConsoleCmd, consoleOut, consoleHistory, runConsole }), backups: h(BackupsTab, { host: dhost(), confirmDialog, trackJob, setError, refreshTick }), cron: h(CronTab, { host: dhost(), setError, loadingMap, markLoading, refreshTick }), deploy: h(DeployTab, { host: dhost(), trackJob, setError, loadingMap, refreshTick }) }[detailTab] || h(HostDetailTab, { ackAlert: ackAlert, ackMonitorUi: ackMonitorUi, addHost: addHost, addSuggestions: addSuggestions, adding: adding, aiBusy: aiBusy, aiDraft: aiDraft, aiIntent: aiIntent, aiMode: aiMode, aiModels: aiModels, aiResult: aiResult, alerts: alerts, applyTemplateUi: applyTemplateUi, askAi: askAi, askBusy: askBusy, askHost: askHost, askLog: askLog, askQuestion: askQuestion, audit: audit, backupBusy: backupBusy, backupSelected: backupSelected, busy: busy, cHost: cHost, certs: certs, chBusy: chBusy, channelForm: channelForm, channels: channels, chatNotice: chatNotice, cleanBackupFile: cleanBackupFile, cleanBusyHost: cleanBusyHost, cleanPreview: cleanPreview, cleanRunBusy: cleanRunBusy, cleanSel: cleanSel, cleanupHost: cleanupHost, closeTerm: closeTerm, config: config, confirmClean: confirmClean, confirmDialog: confirmDialog, conns: conns, consoleCmd: consoleCmd, consoleHistory: consoleHistory, consoleOut: consoleOut, copyDiagnostics: copyDiagnostics, copyReport: copyReport, copyText: copyText, countOf: countOf, createServiceUi: createServiceUi, detailHost: detailHost, detailTab: detailTab, dhost: dhost, diag: diag, diagnoseMonitorUi: diagnoseMonitorUi, diagnosticsText: diagnosticsText, doAction: doAction, downloadBackup: downloadBackup, editMonitor: editMonitor, editName: editName, error: error, fileState: fileState, focusTerm: focusTerm, form: form, generateCommand: generateCommand, health: health, histDiff: histDiff, histList: histList, histPath: histPath, hosts: hosts, info: info, installKeyOn: installKeyOn, inv: inv, loadBase: loadBase, loadCerts: loadCerts, loadChannels: loadChannels, loadHealth: loadHealth, loadHistory: loadHistory, loadInv: loadInv, loadLogUsage: loadLogUsage, loadMaintenance: loadMaintenance, loadMonitors: loadMonitors, loadServicesUi: loadServicesUi, loadTemplatesUi: loadTemplatesUi, loadingMap: loadingMap, logRequest: logRequest, logUsageData: logUsageData, maintenanceUntil: maintenanceUntil, markLoading: markLoading, metricBox: metricBox, monBusy: monBusy, monEditId: monEditId, monForm: monForm, monitorSuggestions: monitorSuggestions, monitors: monitors, notice: notice, opBusy: opBusy, opOut: opOut, openCleanPreview: openCleanPreview, openFile: openFile, openHost: openHost, openTerm: openTerm, output: output, overview: overview, p2Busy: p2Busy, quickText: quickText, recheckHost: recheckHost, recheckOne: recheckOne, refreshTick: refreshTick, removeChannelUi: removeChannelUi, removeHost: removeHost, removeMonitor: removeMonitor, removeServiceUi: removeServiceUi, removeTemplateUi: removeTemplateUi, renewCertsNow: renewCertsNow, restartWebFor: restartWebFor, restoreVersion: restoreVersion, runConsole: runConsole, runGenerated: runGenerated, runNeedsConfirm: runNeedsConfirm, saveAsTemplate: saveAsTemplate, saveChannel: saveChannel, saveConfig: saveConfig, saveFile: saveFile, saveMonitor: saveMonitor, sectionList: sectionList, selectedLogPaths: selectedLogPaths, sendKey: sendKey, services: services, setAdding: setAdding, setAiDraft: setAiDraft, setAiIntent: setAiIntent, setAiMode: setAiMode, setAiModels: setAiModels, setAlerts: setAlerts, setAskQuestion: setAskQuestion, setBackupBusy: setBackupBusy, setCHost: setCHost, setCerts: setCerts, setChBusy: setChBusy, setChannelForm: setChannelForm, setChannels: setChannels, setChatNotice: setChatNotice, setCleanBackupFile: setCleanBackupFile, setCleanBusyHost: setCleanBusyHost, setCleanPreview: setCleanPreview, setCleanRunBusy: setCleanRunBusy, setCleanSel: setCleanSel, setConfig: setConfig, setConsoleCmd: setConsoleCmd, setDetailHost: setDetailHost, setDetailTab: setDetailTab, setDiag: setDiag, setEditName: setEditName, setError: setError, setFileState: setFileState, setForm: setForm, setHealth: setHealth, setHistDiff: setHistDiff, setHistList: setHistList, setHistPath: setHistPath, setHostCtx: setHostCtx, setLogRequest: setLogRequest, setLogUsageData: setLogUsageData, setMaintenanceUi: setMaintenanceUi, setMaintenanceUntil: setMaintenanceUntil, setMonBusy: setMonBusy, setMonDialog: setMonDialog, setMonEditId: setMonEditId, setMonForm: setMonForm, setMonitors: setMonitors, setNotice: setNotice, setOpBusy: setOpBusy, setOpOut: setOpOut, setP2Busy: setP2Busy, setQuickText: setQuickText, setServices: setServices, setSimpleCtx: setSimpleCtx, setSimpleMonitors: setSimpleMonitors, setSimpleNotice: setSimpleNotice, setTab: setTab, setTemplateId: setTemplateId, setTemplates: setTemplates, setTerm: setTerm, setUiMode: setUiMode, showDiff: showDiff, simpleCtx: simpleCtx, simpleHostState: simpleHostState, simpleMonitors: simpleMonitors, simpleNotice: simpleNotice, startEdit: startEdit, statusOf: statusOf, suggestionFor: suggestionFor, switchMode: switchMode, tab: tab, templateId: templateId, templates: templates, term: term, testChannelUi: testChannelUi, testHost: testHost, testMonitor: testMonitor, timeoutFor: timeoutFor, trackJob: trackJob, uiMode: uiMode }))
|
|
3858
|
+
? ({ monitor: h(MonitorTab, { hosts, detailHost, detailTab, loadingMap, markLoading, setError }), config: h(ConfigTab, { busy, cHost, detailHost, histDiff, histList, histPath, hosts, inv, loadHistory, loadInv, monitorSuggestions, monitors, opBusy, restoreVersion, sectionList, services, setCHost, setHistPath, showDiff }), apps: h(AppsTab, { addSuggestions, busy, cHost, config, confirmDialog, detailHost, doAction, fileState, hosts, inv, loadInv, monBusy, monitorSuggestions, openFile, output, saveFile, setError, setCHost, setDetailTab, setFileState, setLogRequest }), logs: h(LogsTab, { host: cHost || hosts[0]?.name, notice, logRequest, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), setError, setNotice, timeoutFor, onInventoryRefresh: loadInv, config, logUsageData, loadLogUsage, openCleanPreview, cleanBusyHost, cleanRunBusy, backupBusy }), files: h(FilesTab, { host: cHost || hosts[0]?.name, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), setError, setNotice, confirmDialog, timeoutFor }), terminal: h(TerminalTab, { host: cHost || hosts[0]?.name, picker: detailHost ? null : hostPicker(hosts, cHost, setCHost), term, setTerm, openTerm, closeTerm, busy, aiMode, aiDraft, quickCommands, termKey, sendKey, focusTerm, generateCommand, runGenerated, aiResult, setAiResult, aiIntent, setAiIntent, aiBusy, setAiMode, setAiDraft, askLog, error, output, consoleCmd, setConsoleCmd, consoleOut, consoleHistory, runConsole }), backups: h(BackupsTab, { host: dhost(), confirmDialog, trackJob, setError, refreshTick }), cron: h(CronTab, { host: dhost(), setError, loadingMap, markLoading, refreshTick }), deploy: h(DeployTab, { host: dhost(), trackJob, setError, loadingMap, refreshTick }) }[detailTab] || h(HostDetailTab, { ackAlert: ackAlert, ackMonitorUi: ackMonitorUi, addHost: addHost, addSuggestions: addSuggestions, adding: adding, aiBusy: aiBusy, aiDraft: aiDraft, aiIntent: aiIntent, aiMode: aiMode, aiModels: aiModels, aiResult: aiResult, alerts: alerts, applyTemplateUi: applyTemplateUi, askAi: askAi, askBusy: askBusy, askHost: askHost, askLog: askLog, askQuestion: askQuestion, audit: audit, backupBusy: backupBusy, backupSelected: backupSelected, busy: busy, cHost: cHost, certs: certs, chBusy: chBusy, channelForm: channelForm, channels: channels, chatNotice: chatNotice, cleanBackupFile: cleanBackupFile, cleanBusyHost: cleanBusyHost, cleanPreview: cleanPreview, cleanRunBusy: cleanRunBusy, cleanSel: cleanSel, cleanupHost: cleanupHost, closeTerm: closeTerm, config: config, confirmClean: confirmClean, confirmDialog: confirmDialog, conns: conns, consoleCmd: consoleCmd, consoleHistory: consoleHistory, consoleOut: consoleOut, copyDiagnostics: copyDiagnostics, copyReport: copyReport, copyText: copyText, countOf: countOf, createServiceUi: createServiceUi, detailHost: detailHost, detailTab: detailTab, dhost: dhost, diag: diag, diagnoseMonitorUi: diagnoseMonitorUi, diagnosticsText: diagnosticsText, doAction: doAction, downloadBackup: downloadBackup, editMonitor: editMonitor, editName: editName, error: error, fileState: fileState, focusTerm: focusTerm, form: form, generateCommand: generateCommand, health: health, histDiff: histDiff, histList: histList, histPath: histPath, hosts: hosts, info: info, installKeyOn: installKeyOn, inv: inv, loadBase: loadBase, loadCerts: loadCerts, loadChannels: loadChannels, loadHealth: loadHealth, loadHistory: loadHistory, loadInv: loadInv, loadLogUsage: loadLogUsage, loadMaintenance: loadMaintenance, loadMonitors: loadMonitors, loadServicesUi: loadServicesUi, loadTemplatesUi: loadTemplatesUi, loadingMap: loadingMap, logRequest: logRequest, logUsageData: logUsageData, maintenanceUntil: maintenanceUntil, markLoading: markLoading, metricBox: metricBox, monBusy: monBusy, monEditId: monEditId, monForm: monForm, monitorSuggestions: monitorSuggestions, monitors: monitors, notice: notice, opBusy: opBusy, opOut: opOut, openCleanPreview: openCleanPreview, openFile: openFile, openHost: openHost, openTerm: openTerm, output: output, overview: overview, p2Busy: p2Busy, quickText: quickText, recheckHost: recheckHost, recheckOne: recheckOne, refreshTick: refreshTick, removeChannelUi: removeChannelUi, removeHost: removeHost, removeMonitor: removeMonitor, removeServiceUi: removeServiceUi, removeTemplateUi: removeTemplateUi, renewCertsNow: renewCertsNow, restartWebFor: restartWebFor, restoreVersion: restoreVersion, runConsole: runConsole, runGenerated: runGenerated, runNeedsConfirm: runNeedsConfirm, saveAsTemplate: saveAsTemplate, saveChannel: saveChannel, saveConfig: saveConfig, saveFile: saveFile, saveMonitor: saveMonitor, sectionList: sectionList, selectedLogPaths: selectedLogPaths, sendKey: sendKey, services: services, setAdding: setAdding, setAiDraft: setAiDraft, setAiIntent: setAiIntent, setAiMode: setAiMode, setAiModels: setAiModels, setAlerts: setAlerts, setAskQuestion: setAskQuestion, setBackupBusy: setBackupBusy, setCHost: setCHost, setCerts: setCerts, setChBusy: setChBusy, setChannelForm: setChannelForm, setChannels: setChannels, setChatNotice: setChatNotice, setCleanBackupFile: setCleanBackupFile, setCleanBusyHost: setCleanBusyHost, setCleanPreview: setCleanPreview, setCleanRunBusy: setCleanRunBusy, setCleanSel: setCleanSel, setConfig: setConfig, setConsoleCmd: setConsoleCmd, setDetailHost: setDetailHost, setDetailTab: setDetailTab, setDiag: setDiag, setEditName: setEditName, setError: setError, setFileState: setFileState, setForm: setForm, setHealth: setHealth, setHistDiff: setHistDiff, setHistList: setHistList, setHistPath: setHistPath, setHostCtx: setHostCtx, setLogRequest: setLogRequest, setLogUsageData: setLogUsageData, setMaintenanceUi: setMaintenanceUi, setMaintenanceUntil: setMaintenanceUntil, setMonBusy: setMonBusy, setMonDialog: setMonDialog, setMonEditId: setMonEditId, setMonForm: setMonForm, setMonitors: setMonitors, setNotice: setNotice, setOpBusy: setOpBusy, setOpOut: setOpOut, setP2Busy: setP2Busy, setQuickText: setQuickText, setServices: setServices, setSimpleCtx: setSimpleCtx, setSimpleMonitors: setSimpleMonitors, setSimpleNotice: setSimpleNotice, setTab: setTab, setTemplateId: setTemplateId, setTemplates: setTemplates, setTerm: setTerm, setUiMode: setUiMode, showDiff: showDiff, simpleCtx: simpleCtx, simpleHostState: simpleHostState, simpleMonitors: simpleMonitors, simpleNotice: simpleNotice, startEdit: startEdit, statusOf: statusOf, suggestionFor: suggestionFor, switchMode: switchMode, tab: tab, templateId: templateId, templates: templates, term: term, testChannelUi: testChannelUi, testHost: testHost, testMonitor: testMonitor, timeoutFor: timeoutFor, trackJob: trackJob, uiMode: uiMode }))
|
|
3812
3859
|
: null
|
|
3813
3860
|
|
|
3814
3861
|
const topTabs = [[0, T.tabs[0]], [1, T.tabs[8]], [2, T.tabs[9]]]
|
package/index.js
CHANGED
|
@@ -798,6 +798,26 @@ function createApiHandler({ connection } = {}) {
|
|
|
798
798
|
return
|
|
799
799
|
}
|
|
800
800
|
|
|
801
|
+
if (route === 'aliases' && method === 'GET') {
|
|
802
|
+
const cfg = pickHost(await loadHosts(), url.searchParams.get('host') ?? undefined)
|
|
803
|
+
sendJson(res, 200, { host: cfg.name, aliases: await loadAliases(cfg.name) })
|
|
804
|
+
return
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
if (route === 'aliases' && method === 'POST') {
|
|
808
|
+
const body = (await readBody(req)) || {}
|
|
809
|
+
const cfg = pickHost(await loadHosts(), body.host)
|
|
810
|
+
const key = String(body.key ?? '').trim()
|
|
811
|
+
if (!key) { sendJson(res, 400, { error: 'key is required' }); return }
|
|
812
|
+
const aliases = { ...(await loadAliases(cfg.name)) }
|
|
813
|
+
const value = String(body.alias ?? '').trim().slice(0, 40)
|
|
814
|
+
if (value) aliases[key] = value
|
|
815
|
+
else delete aliases[key]
|
|
816
|
+
await saveAliases(cfg.name, aliases)
|
|
817
|
+
sendJson(res, 200, { host: cfg.name, aliases })
|
|
818
|
+
return
|
|
819
|
+
}
|
|
820
|
+
|
|
801
821
|
if (route === 'discover' && method === 'POST') {
|
|
802
822
|
const body = (await readBody(req)) || {}
|
|
803
823
|
const cfg = pickHost(await loadHosts(), body.host)
|
|
@@ -1790,7 +1810,7 @@ async function sampleAllMetrics() {
|
|
|
1790
1810
|
|
|
1791
1811
|
const INVENTORY_COMMAND = [
|
|
1792
1812
|
'echo "## ports"; (ss -lntp 2>/dev/null || netstat -lnt 2>/dev/null) | head -40',
|
|
1793
|
-
'echo "## services"; systemctl list-units --type=service --state=running --no-legend --no-pager 2>/dev/null | awk \'{print $1}\' | head -40',
|
|
1813
|
+
'echo "## services"; for u in $(systemctl list-units --type=service --state=running --no-legend --no-pager 2>/dev/null | awk \'{print $1}\' | head -40); do echo "$u|$(systemctl show -p Description --value "$u" 2>/dev/null | head -1)"; done',
|
|
1794
1814
|
'echo "## docker"; docker ps -a --format "{{.Names}}\\t{{.Status}}\\t{{.Ports}}" 2>/dev/null | head -30',
|
|
1795
1815
|
'echo "## nginx"; (nginx -T 2>/dev/null | grep -E "^\\s*(server_name|listen|root)" | head -40)',
|
|
1796
1816
|
'echo "## java"; ps -eo pid,etime,cmd 2>/dev/null | grep -E "[j]ava" | head -12',
|
|
@@ -1811,6 +1831,56 @@ function sectionsOf(text) {
|
|
|
1811
1831
|
}
|
|
1812
1832
|
|
|
1813
1833
|
/** Read-only inventory: ports, services, containers, nginx sites, java, cron, mounts. */
|
|
1834
|
+
|
|
1835
|
+
const FRIENDLY_UNIT = {
|
|
1836
|
+
'nginx.service': '网站服务(Nginx)',
|
|
1837
|
+
'mysqld.service': '数据库(MySQL)',
|
|
1838
|
+
'mysql.service': '数据库(MySQL)',
|
|
1839
|
+
'redis.service': '缓存(Redis)',
|
|
1840
|
+
'docker.service': '容器引擎(Docker)',
|
|
1841
|
+
'postgresql.service': '数据库(PostgreSQL)',
|
|
1842
|
+
'php-fpm.service': 'PHP 服务',
|
|
1843
|
+
'sshd.service': '远程登录',
|
|
1844
|
+
'crond.service': '定时任务',
|
|
1845
|
+
'firewalld.service': '防火墙',
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
/** systemd Description 通常很友好;没有就用 unit 名清洗一下。 */
|
|
1849
|
+
function friendlyUnit(unit, description) {
|
|
1850
|
+
const key = String(unit || '')
|
|
1851
|
+
if (FRIENDLY_UNIT[key]) return FRIENDLY_UNIT[key]
|
|
1852
|
+
const text = String(description || '').trim()
|
|
1853
|
+
if (text && !/^(LSB:|systemd|Systemd|D-Bus|dconf)/i.test(text)) return text
|
|
1854
|
+
const base = key.replace(/\.service$/i, '').replace(/@.*$/, '').replace(/[_-]+/g, ' ')
|
|
1855
|
+
return base.trim() || key
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
function appKey(kind, name) {
|
|
1859
|
+
return `${kind}:${name}`
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
function aliasesFile() {
|
|
1863
|
+
return join(kitDir(), 'aliases.json')
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
async function loadAliases(host) {
|
|
1867
|
+
try {
|
|
1868
|
+
const all = JSON.parse(await readFile(aliasesFile(), 'utf8'))
|
|
1869
|
+
return (all && all[host] && typeof all[host] === 'object') ? all[host] : {}
|
|
1870
|
+
} catch {
|
|
1871
|
+
return {}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
async function saveAliases(host, aliases) {
|
|
1876
|
+
let all = {}
|
|
1877
|
+
try { all = JSON.parse(await readFile(aliasesFile(), 'utf8')) || {} } catch { all = {} }
|
|
1878
|
+
all[host] = aliases && typeof aliases === 'object' ? aliases : {}
|
|
1879
|
+
await mkdir(kitDir(), { recursive: true })
|
|
1880
|
+
await writeFile(aliasesFile(), JSON.stringify(all, null, 2) + '\n', 'utf8')
|
|
1881
|
+
return all[host]
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1814
1884
|
async function discover(cfg) {
|
|
1815
1885
|
const result = await ssh(cfg, INVENTORY_COMMAND, 30_000)
|
|
1816
1886
|
const text = result.ok ? result.stdout : ''
|
|
@@ -1820,10 +1890,19 @@ async function discover(cfg) {
|
|
|
1820
1890
|
const [name, status, ports] = line.split('\t')
|
|
1821
1891
|
return { name, status: status || '', ports: ports || '' }
|
|
1822
1892
|
})
|
|
1823
|
-
const
|
|
1893
|
+
const serviceRows = lines('services').map(line => {
|
|
1894
|
+
const [unit, ...rest] = line.split('|')
|
|
1895
|
+
return { unit: String(unit || '').trim(), description: rest.join('|').trim() }
|
|
1896
|
+
}).filter(row => row.unit)
|
|
1897
|
+
const services = serviceRows.map(row => row.unit)
|
|
1898
|
+
const serviceDesc = Object.fromEntries(serviceRows.filter(row => row.description).map(row => [row.unit, row.description]))
|
|
1824
1899
|
const java = lines('java').map(line => {
|
|
1825
1900
|
const match = line.match(/^(\d+)\s+(\S+)\s+(.*)$/)
|
|
1826
|
-
|
|
1901
|
+
const row = match ? { pid: match[1], uptime: match[2], cmd: match[3].slice(0, 240) } : { pid: '', uptime: '', cmd: line.slice(0, 240) }
|
|
1902
|
+
const jarMatch = String(row.cmd).match(/-jar\s+(\S+)/)
|
|
1903
|
+
const jar = jarMatch ? jarMatch[1].split('/').pop().replace(/\.jar$/i, '') : ''
|
|
1904
|
+
const main = jar ? '' : String(row.cmd).split(/\s+/).filter(Boolean).pop() || ''
|
|
1905
|
+
return { ...row, jar, main: main && /\./.test(main) ? main.split('.').pop() : '' }
|
|
1827
1906
|
})
|
|
1828
1907
|
const nginx = lines('nginx')
|
|
1829
1908
|
const unitPaths = Object.fromEntries(lines('units').map(line => {
|
|
@@ -1837,12 +1916,24 @@ async function discover(cfg) {
|
|
|
1837
1916
|
return unitPaths[unit] || null
|
|
1838
1917
|
}
|
|
1839
1918
|
const apps = [
|
|
1840
|
-
...docker.map(row => ({ kind: 'docker', name: row.name, status: row.status, ports: row.ports, config: null })),
|
|
1919
|
+
...docker.map(row => ({ kind: 'docker', name: row.name, display: row.name, key: appKey('docker', row.name), status: row.status, ports: row.ports, config: null })),
|
|
1841
1920
|
...services.filter(name => !/^(systemd-|dbus|cron|crond|sshd|rsyslog|polkit|NetworkManager|auditd|tuned|chronyd|irqbalance|atd|rngd|rpcbind|gssproxy|firewalld|BT-FirewallServices|aegis|aliyun|cloudmonitor|getty|serial-getty|user@|postfix)/.test(name))
|
|
1842
|
-
.map(name => ({
|
|
1843
|
-
|
|
1844
|
-
|
|
1921
|
+
.map(name => ({
|
|
1922
|
+
kind: 'service', name, key: appKey('service', name), status: 'running', ports: '', config: configFor(name),
|
|
1923
|
+
description: serviceDesc[name] || '', display: friendlyUnit(name, serviceDesc[name]),
|
|
1924
|
+
})),
|
|
1925
|
+
...java.map(row => {
|
|
1926
|
+
const label = row.jar ? row.jar.replace(/\.jar$/i, '') : (row.main || `java ${row.pid}`)
|
|
1927
|
+
return {
|
|
1928
|
+
kind: 'java', name: `java pid ${row.pid}`, key: appKey('java', row.jar || row.main || `pid${row.pid}`),
|
|
1929
|
+
display: label, status: row.uptime, ports: '', config: null, pid: row.pid, jar: row.jar || '', main: row.main || '',
|
|
1930
|
+
}
|
|
1931
|
+
}),
|
|
1845
1932
|
]
|
|
1933
|
+
const aliases = await loadAliases(cfg.name)
|
|
1934
|
+
for (const app of apps) {
|
|
1935
|
+
if (aliases[app.key]) app.alias = aliases[app.key]
|
|
1936
|
+
}
|
|
1846
1937
|
const portRows = lines('ports').filter(line => /^LISTEN/.test(line)).map(line => {
|
|
1847
1938
|
const portMatch = line.match(/(?:\d{1,3}\.){3}\d{1,3}:(\d+)|\*:(\d+)|:(\d+)\s/)
|
|
1848
1939
|
const port = portMatch ? Number(portMatch[1] || portMatch[2] || portMatch[3]) : null
|
|
@@ -5169,6 +5260,8 @@ export function apply(ctx) {
|
|
|
5169
5260
|
/** Internals for the test suite; not part of the plugin API. */
|
|
5170
5261
|
export const __test = {
|
|
5171
5262
|
q,
|
|
5263
|
+
friendlyUnit,
|
|
5264
|
+
appKey,
|
|
5172
5265
|
clip,
|
|
5173
5266
|
pickHost,
|
|
5174
5267
|
safeUnit,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ops-kit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"description": "OPC-运维工作台 (dsh-ops-kit) — Server operations kit for DeepSeek Harness: server cards, health charts, config browser, app manager and plain-language AI diagnosis — over SSH, no agent install.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|