dsh-ops-kit 0.3.7 → 0.3.9
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 +85 -12
- package/index.js +119 -3
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -45,7 +45,8 @@ window.__ModuleLoader__.load({
|
|
|
45
45
|
test: '测试连接', testing: '测试中…', installKey: '安装公钥', installing: '安装中…',
|
|
46
46
|
connected: '已连接', disconnected: '连不上', latency: '延迟', failures: '连续失败',
|
|
47
47
|
console: '命令控制台', runCmd: '执行', cmdPh: '输入命令,例如 df -h 或 systemctl status nginx',
|
|
48
|
-
terminal: '终端', openTerm: '打开终端', closeTerm: '断开',
|
|
48
|
+
terminal: '终端', openTerm: '打开终端', closeTerm: '断开', reconnect: '重新连接',
|
|
49
|
+
termClosed: '会话已断开(服务器或网络关闭了这次连接)。点「重新连接」恢复。', termHint: '步骤:① 点「打开终端」 ② 点一下黑框 ③ 敲命令,回车执行。支持 Tab 补全、Ctrl+C、方向键。', termNeedPwd: '这个主机没有保存密码,终端需要密码登录;请到设置里编辑主机并填入密码。',
|
|
49
50
|
connecting: '正在连接…', clickConnect: '点这里连接', quickCmds: '常用命令', tip: '连上后黑框里会出现服务器提示符,像用 FinalShell 一样敲命令。',
|
|
50
51
|
aiBar: '用一句话说你想做什么', aiPh: '例如:看看磁盘还剩多少 / 重启 nginx / 查最近 50 行错误日志',
|
|
51
52
|
aiMode: 'AI 模式', aiModeHint: '输入意图后回车:命令会填进终端但不会自动执行;Esc 取消',
|
|
@@ -81,9 +82,12 @@ window.__ModuleLoader__.load({
|
|
|
81
82
|
monInterval: '间隔(分钟)', monAdd: '添加并检查', monCheck: '检查', monRemove: '删除', monEmpty: '还没有监控项,可以加一个心跳检查',
|
|
82
83
|
monHttpHint: 'http:填 URL,如 https://example.com;port:填 host:port;process:填进程关键字;service:填 systemd 单元名',
|
|
83
84
|
monLast: '最近', monNever: '未检查', monEdit: '编辑', monSave: '保存修改', monCancel: '取消',
|
|
85
|
+
monOk: '服务正常', monBad: '检查失败', monHint: '排查方向', monDiag: '一键排查', monDiaging: '排查中…',
|
|
86
|
+
monResult: '这次检查结果', monClose: '关闭', monDiagTitle: '排查结果', monChecked: '检查于',
|
|
84
87
|
monPreset: '一键模板', monScript: '脚本(退出码 0 = 正常)', monLanguage: '语言',
|
|
85
88
|
monScriptHint: '脚本在服务器上用对应解释器执行,退出码 0 视为正常;python 需要 python3,js 需要 node。',
|
|
86
89
|
monTypes: [['http', '网站能不能打开'], ['port', '端口通不通'], ['process', '程序还在不在'], ['service', '系统服务在不在'], ['script', '自己写检查脚本']],
|
|
90
|
+
monTypeShort: { http: '网站', port: '端口', process: '进程', service: '服务', script: '脚本' },
|
|
87
91
|
monTypeHint: {
|
|
88
92
|
http: '填网址,例如 https://example.com 或 http://127.0.0.1:8080/health',
|
|
89
93
|
port: '填 地址:端口,例如 127.0.0.1:3306(数据库)、127.0.0.1:6379(缓存)',
|
|
@@ -128,7 +132,8 @@ window.__ModuleLoader__.load({
|
|
|
128
132
|
test: 'Test', testing: 'Testing…', installKey: 'Install key', installing: 'Installing…',
|
|
129
133
|
connected: 'Connected', disconnected: 'Unreachable', latency: 'latency', failures: 'failures',
|
|
130
134
|
console: 'Command console', runCmd: 'Run', cmdPh: 'Type a command, e.g. df -h',
|
|
131
|
-
terminal: 'Terminal', openTerm: 'Open terminal', closeTerm: 'Disconnect',
|
|
135
|
+
terminal: 'Terminal', openTerm: 'Open terminal', closeTerm: 'Disconnect', reconnect: 'Reconnect',
|
|
136
|
+
termClosed: 'The session closed (server or network dropped it). Use Reconnect.', termHint: 'Steps: 1) Open terminal 2) click the dark box 3) type a command and press Enter. Tab, Ctrl+C and arrows work.', termNeedPwd: 'This host has no stored password; the terminal needs password auth. Edit the host and add one.',
|
|
132
137
|
connecting: 'Connecting…', clickConnect: 'Click to connect', quickCmds: 'Quick commands', tip: 'Once connected the prompt appears; type commands like in a normal SSH client.',
|
|
133
138
|
aiBar: 'Describe what you want to do', aiPh: 'e.g. how much disk is left / restart nginx / last 50 error lines',
|
|
134
139
|
aiMode: 'AI mode', aiModeHint: 'Type the intent and press Enter: the command is filled but not run; Esc cancels',
|
|
@@ -164,9 +169,12 @@ window.__ModuleLoader__.load({
|
|
|
164
169
|
monInterval: 'Interval (min)', monAdd: 'Add and check', monCheck: 'Check', monRemove: 'Remove', monEmpty: 'No monitors yet — add a heartbeat check',
|
|
165
170
|
monHttpHint: 'http: URL like https://example.com; port: host:port; process: pattern; service: systemd unit',
|
|
166
171
|
monLast: 'last', monNever: 'never', monEdit: 'Edit', monSave: 'Save', monCancel: 'Cancel',
|
|
172
|
+
monOk: 'Healthy', monBad: 'Check failed', monHint: 'Where to look', monDiag: 'Diagnose', monDiaging: 'Diagnosing…',
|
|
173
|
+
monResult: 'Result', monClose: 'Close', monDiagTitle: 'Diagnosis', monChecked: 'checked at',
|
|
167
174
|
monPreset: 'Presets', monScript: 'Script (exit 0 = healthy)', monLanguage: 'Language',
|
|
168
175
|
monScriptHint: 'Runs on the host with the chosen interpreter; exit code 0 means healthy. python needs python3, js needs node.',
|
|
169
176
|
monTypes: [['http', 'Website reachable'], ['port', 'Port open'], ['process', 'Process alive'], ['service', 'System service active'], ['script', 'Custom script']],
|
|
177
|
+
monTypeShort: { http: 'HTTP', port: 'Port', process: 'Process', service: 'Service', script: 'Script' },
|
|
170
178
|
monTypeHint: {
|
|
171
179
|
http: 'URL, e.g. https://example.com',
|
|
172
180
|
port: 'host:port, e.g. 127.0.0.1:3306',
|
|
@@ -250,6 +258,15 @@ window.__ModuleLoader__.load({
|
|
|
250
258
|
.ops-meta{display:flex;gap:8px;align-items:center;font-size:11px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
251
259
|
.ops-copy{border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:11px;cursor:pointer;padding:0}
|
|
252
260
|
.ops-copy:hover{color:var(--dsw-alias-text-primary,#e6e6e6)}
|
|
261
|
+
.ops-modal-mask{position:fixed;inset:0;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;z-index:60;padding:20px}
|
|
262
|
+
.ops-modal{width:min(720px,100%);max-height:82vh;overflow:auto;background:var(--dsw-alias-bg,#16191d);border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:12px;padding:18px 20px}
|
|
263
|
+
.ops-modal-h{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px}
|
|
264
|
+
.ops-modal-title{font-size:15px;font-weight:600}
|
|
265
|
+
.ops-modal-x{border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:18px;cursor:pointer;line-height:1}
|
|
266
|
+
.ops-modal-row{display:flex;gap:10px;font-size:13px;line-height:1.7;padding:3px 0}
|
|
267
|
+
.ops-modal-row b{min-width:64px;color:var(--dsw-alias-text-secondary,#9aa0a6);font-weight:500}
|
|
268
|
+
.ops-result-ok{color:#3fbf7f;font-weight:600}
|
|
269
|
+
.ops-result-bad{color:#ff6b6b;font-weight:600}
|
|
253
270
|
.ops-composer{display:flex;gap:8px;align-items:flex-end;padding:10px 14px;border-top:1px solid var(--dsw-alias-border,#3a3f45)}
|
|
254
271
|
`
|
|
255
272
|
|
|
@@ -429,6 +446,7 @@ window.__ModuleLoader__.load({
|
|
|
429
446
|
const [monitors, setMonitors] = React.useState([])
|
|
430
447
|
const [monForm, setMonForm] = React.useState({ type: 'http', target: '', label: '', intervalMinutes: 5, language: 'shell', script: '' })
|
|
431
448
|
const [monEditId, setMonEditId] = React.useState('')
|
|
449
|
+
const [monDialog, setMonDialog] = React.useState(null)
|
|
432
450
|
const [monBusy, setMonBusy] = React.useState('')
|
|
433
451
|
const [health, setHealth] = React.useState(null)
|
|
434
452
|
const [certs, setCerts] = React.useState([])
|
|
@@ -1460,13 +1478,23 @@ window.__ModuleLoader__.load({
|
|
|
1460
1478
|
}
|
|
1461
1479
|
|
|
1462
1480
|
const testMonitor = async (id) => {
|
|
1481
|
+
const monitor = monitors.find(item => item.id === id) || { id }
|
|
1463
1482
|
setMonBusy('test:' + id)
|
|
1464
1483
|
try {
|
|
1465
|
-
await api('monitors', { method: 'POST', body: JSON.stringify({ host: detailHost || cHost, action: 'test', id }) },
|
|
1484
|
+
const data = await api('monitors', { method: 'POST', body: JSON.stringify({ host: detailHost || cHost, action: 'test', id }) }, 45_000)
|
|
1485
|
+
setMonDialog({ monitor, result: data.result, hints: data.hints || [], diag: null })
|
|
1466
1486
|
await loadMonitors(detailHost || cHost)
|
|
1467
1487
|
} catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
|
|
1468
1488
|
}
|
|
1469
1489
|
|
|
1490
|
+
const diagnoseMonitorUi = async (id) => {
|
|
1491
|
+
setMonBusy('diag:' + id)
|
|
1492
|
+
try {
|
|
1493
|
+
const data = await api('monitors', { method: 'POST', body: JSON.stringify({ host: detailHost || cHost, action: 'diagnose', id }) }, 60_000)
|
|
1494
|
+
setMonDialog(current => (current ? { ...current, diag: data } : current))
|
|
1495
|
+
} catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1470
1498
|
const removeMonitor = async (id) => {
|
|
1471
1499
|
if (!window.confirm(T.monRemove + '?')) return
|
|
1472
1500
|
try {
|
|
@@ -1565,9 +1593,12 @@ window.__ModuleLoader__.load({
|
|
|
1565
1593
|
term?.id
|
|
1566
1594
|
? h('span', { className: term.closed ? 'ops-chip' : 'ops-chip ops-ok' }, term.closed ? '已断开' : '已连接')
|
|
1567
1595
|
: (busy === 'term' ? h('span', { className: 'ops-chip' }, T.connecting) : null),
|
|
1568
|
-
term?.id
|
|
1569
|
-
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void
|
|
1570
|
-
:
|
|
1596
|
+
term?.id && term.closed
|
|
1597
|
+
? h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'term', onClick: () => { setTerm(null); setTimeout(() => { void openTerm() }, 50) } }, busy === 'term' ? T.connecting : T.reconnect)
|
|
1598
|
+
: term?.id
|
|
1599
|
+
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void closeTerm() } }, T.closeTerm)
|
|
1600
|
+
: h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'term', onClick: () => { void openTerm() } }, busy === 'term' ? T.connecting : T.openTerm)),
|
|
1601
|
+
term?.id && term.closed ? h('p', { className: 'ops-sub', style: { margin: 0 } }, T.termClosed) : null,
|
|
1571
1602
|
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.termHint),
|
|
1572
1603
|
aiMode
|
|
1573
1604
|
? h('div', { className: 'ops-card', style: { borderColor: 'var(--dsw-alias-accent,#4c8dff)' } },
|
|
@@ -1944,12 +1975,12 @@ window.__ModuleLoader__.load({
|
|
|
1944
1975
|
monitors.length === 0
|
|
1945
1976
|
? h('p', { className: 'ops-empty' }, T.monEmpty)
|
|
1946
1977
|
: h('div', null, ...monitors.map(monitor => h('div', { key: monitor.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.1fr auto' } },
|
|
1947
|
-
h('span', { style: { display: 'flex', alignItems: 'center', gap: '
|
|
1978
|
+
h('span', { style: { display: 'flex', alignItems: 'center', gap: '8px', minWidth: 0 } },
|
|
1948
1979
|
h('i', { className: 'ops-dot ' + (monitor.lastOk === true ? 'ok' : monitor.lastOk === false ? 'bad' : '') }),
|
|
1949
|
-
h('span', { className: 'ops-name' }, monitor.label ||
|
|
1950
|
-
h('span', { className: 'ops-
|
|
1951
|
-
|
|
1952
|
-
|
|
1980
|
+
h('span', { className: 'ops-name' }, monitor.label || monitor.target || monitor.type),
|
|
1981
|
+
monitor.target && monitor.label ? h('span', { className: 'ops-mono ops-dim', style: { fontSize: '11.5px' } }, monitor.target) : null,
|
|
1982
|
+
h('span', { className: 'ops-chip' }, (T.monTypeShort || {})[monitor.type] || monitor.type)
|
|
1983
|
+
, monitor.type === 'script' ? h('span', { className: 'ops-chip' }, monitor.language || 'shell') : null),
|
|
1953
1984
|
h('span', { className: 'ops-dim' }, monitor.last ? `${monitor.last.detail} · ${fmt(monitor.last.at)}` : T.monNever),
|
|
1954
1985
|
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1955
1986
|
h('button', { className: 'ops-btn ops-btn-sm', disabled: monBusy === 'test:' + monitor.id, onClick: () => { void testMonitor(monitor.id) } }, T.monCheck),
|
|
@@ -2090,12 +2121,54 @@ window.__ModuleLoader__.load({
|
|
|
2090
2121
|
: h('div', { className: 'ops-tabs' }, ...topTabs.map(([index, label]) =>
|
|
2091
2122
|
h('button', { key: label, className: `ops-tab${tab === index ? ' on' : ''}`, onClick: () => setTab(index) }, label)))
|
|
2092
2123
|
|
|
2124
|
+
const monitorDialogView = monDialog ? h('div', {
|
|
2125
|
+
className: 'ops-modal-mask',
|
|
2126
|
+
onClick: () => setMonDialog(null),
|
|
2127
|
+
},
|
|
2128
|
+
h('div', { className: 'ops-modal', onClick: event => event.stopPropagation() },
|
|
2129
|
+
h('div', { className: 'ops-modal-h' },
|
|
2130
|
+
h('span', { className: 'ops-modal-title' }, `${monDialog.monitor.label || monDialog.monitor.target || monDialog.monitor.type}`),
|
|
2131
|
+
h('button', { className: 'ops-modal-x', onClick: () => setMonDialog(null) }, '✕')),
|
|
2132
|
+
h('div', {
|
|
2133
|
+
className: monDialog.result?.ok ? 'ops-result-ok' : 'ops-result-bad',
|
|
2134
|
+
style: { fontSize: '15px', marginBottom: '10px' },
|
|
2135
|
+
}, monDialog.result?.ok ? `✓ ${T.monOk}` : `✕ ${T.monBad}`),
|
|
2136
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, '类型'), h('span', null,
|
|
2137
|
+
`${(T.monTypeShort || {})[monDialog.monitor.type] || monDialog.monitor.type}${monDialog.monitor.language ? ' · ' + monDialog.monitor.language : ''}`)),
|
|
2138
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, '目标'), h('span', { className: 'ops-mono' }, monDialog.monitor.target || (monDialog.monitor.script ? '(脚本)' : '—'))),
|
|
2139
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, '详情'), h('span', null, monDialog.result?.detail || '—')),
|
|
2140
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, T.monResult), h('span', null,
|
|
2141
|
+
`${monDialog.result?.ms ?? '—'}ms · ${T.monChecked} ${monDialog.result?.at ? fmt(monDialog.result.at) : '—'}`)),
|
|
2142
|
+
!monDialog.result?.ok && monDialog.hints.length
|
|
2143
|
+
? h('div', { style: { marginTop: '12px' } },
|
|
2144
|
+
h('div', { className: 'ops-sub', style: { marginBottom: '6px' } }, T.monHint),
|
|
2145
|
+
...monDialog.hints.map((hint, index) => h('div', { key: index, style: { fontSize: '13px', lineHeight: 1.8 } }, `· ${hint}`)))
|
|
2146
|
+
: null,
|
|
2147
|
+
!monDialog.result?.ok
|
|
2148
|
+
? h('div', { className: 'ops-chips', style: { marginTop: '12px' } },
|
|
2149
|
+
h('button', {
|
|
2150
|
+
className: 'ops-btn ops-btn-primary ops-btn-sm',
|
|
2151
|
+
disabled: monBusy === 'diag:' + monDialog.monitor.id,
|
|
2152
|
+
onClick: () => { void diagnoseMonitorUi(monDialog.monitor.id) },
|
|
2153
|
+
}, monBusy === 'diag:' + monDialog.monitor.id ? T.monDiaging : T.monDiag))
|
|
2154
|
+
: null,
|
|
2155
|
+
monDialog.diag
|
|
2156
|
+
? h('div', { style: { marginTop: '14px' } },
|
|
2157
|
+
h('div', { className: 'ops-sub', style: { marginBottom: '6px' } }, T.monDiagTitle),
|
|
2158
|
+
...monDialog.diag.checks.map((check, index) => h('div', { key: index, style: { marginBottom: '10px' } },
|
|
2159
|
+
h('div', { className: check.ok ? 'ops-ok' : 'ops-warn', style: { fontSize: '12.5px' } }, `${check.ok ? '✓' : '·'} ${check.label}`),
|
|
2160
|
+
h('pre', { className: 'ops-pre', style: { maxHeight: '180px', marginTop: '4px' } }, check.output))))
|
|
2161
|
+
: null,
|
|
2162
|
+
h('div', { className: 'ops-chips', style: { marginTop: '14px', justifyContent: 'flex-end' } },
|
|
2163
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setMonDialog(null) }, T.monClose)))) : null
|
|
2164
|
+
|
|
2093
2165
|
return h('div', { className: 'ops-page' },
|
|
2094
2166
|
h('style', null, CSS),
|
|
2095
2167
|
header,
|
|
2096
2168
|
nav,
|
|
2097
2169
|
error ? h('p', { className: 'ops-err' }, error) : null,
|
|
2098
|
-
body
|
|
2170
|
+
body,
|
|
2171
|
+
monitorDialogView)
|
|
2099
2172
|
}
|
|
2100
2173
|
|
|
2101
2174
|
/** Keeps a render error visible instead of leaving an empty page. */
|
package/index.js
CHANGED
|
@@ -816,7 +816,16 @@ function createApiHandler({ connection } = {}) {
|
|
|
816
816
|
monitor.last = result
|
|
817
817
|
monitor.lastOk = result.ok
|
|
818
818
|
await saveMonitors(all)
|
|
819
|
-
sendJson(res, 200, {
|
|
819
|
+
sendJson(res, 200, {
|
|
820
|
+
host: cfg.name, id: monitor.id, label: monitor.label, type: monitor.type, target: monitor.target,
|
|
821
|
+
result, hints: result.ok ? [] : monitorHints(monitor, result),
|
|
822
|
+
})
|
|
823
|
+
return
|
|
824
|
+
}
|
|
825
|
+
if (body.action === 'diagnose' && body.id) {
|
|
826
|
+
const monitor = list.find(item => item.id === body.id)
|
|
827
|
+
if (!monitor) { sendJson(res, 404, { error: 'monitor not found' }); return }
|
|
828
|
+
sendJson(res, 200, await diagnoseMonitor(cfg, monitor))
|
|
820
829
|
return
|
|
821
830
|
}
|
|
822
831
|
const monitor = {
|
|
@@ -1951,6 +1960,12 @@ async function openTerminal(cfg, cols = 120, rows = 30) {
|
|
|
1951
1960
|
'-o', 'StrictHostKeyChecking=accept-new',
|
|
1952
1961
|
'-o', 'ServerAliveInterval=15',
|
|
1953
1962
|
'-o', 'ServerAliveCountMax=3',
|
|
1963
|
+
// A terminal must own its connection: sharing the ControlMaster socket with
|
|
1964
|
+
// the panel's short commands means the session dies when that master closes
|
|
1965
|
+
// ("Shared connection to ... closed").
|
|
1966
|
+
'-o', 'ControlMaster=no',
|
|
1967
|
+
'-o', 'ControlPath=none',
|
|
1968
|
+
'-o', 'TCPKeepAlive=yes',
|
|
1954
1969
|
]
|
|
1955
1970
|
if (cfg.port) args.push('-p', String(cfg.port))
|
|
1956
1971
|
if (cfg.key) args.push('-i', cfg.key)
|
|
@@ -2820,6 +2835,102 @@ async function releaseLock(name) {
|
|
|
2820
2835
|
try { await rm(join(kitDir(), name), { recursive: true, force: true }) } catch { /* ignore */ }
|
|
2821
2836
|
}
|
|
2822
2837
|
|
|
2838
|
+
|
|
2839
|
+
/** Plain-language hints for a failing monitor, per type. */
|
|
2840
|
+
function monitorHints(monitor, result) {
|
|
2841
|
+
const type = monitor.type
|
|
2842
|
+
if (type === 'http') {
|
|
2843
|
+
return [
|
|
2844
|
+
'先在浏览器或 curl 打开这个地址,确认返回码',
|
|
2845
|
+
'检查证书是否过期(本面板「证书」卡片会显示剩余天数)',
|
|
2846
|
+
'确认 nginx/应用本身在跑(「应用」页看服务状态)',
|
|
2847
|
+
'如果是 127.0.0.1 地址,说明只有本机能访问,检查端口是否监听',
|
|
2848
|
+
]
|
|
2849
|
+
}
|
|
2850
|
+
if (type === 'port') {
|
|
2851
|
+
return [
|
|
2852
|
+
'确认对应服务在运行(systemctl status 服务名)',
|
|
2853
|
+
'检查端口是否在监听(ss -ltnp | grep 端口号)',
|
|
2854
|
+
'如果服务在跑但端口不通,看是不是只绑定了 127.0.0.1',
|
|
2855
|
+
'云服务器还要确认安全组/防火墙放行了该端口',
|
|
2856
|
+
]
|
|
2857
|
+
}
|
|
2858
|
+
if (type === 'process') {
|
|
2859
|
+
return [
|
|
2860
|
+
'进程可能已退出或被杀,先看日志和 dmesg 有没有 OOM',
|
|
2861
|
+
'确认启动命令和用户是否正确(有的进程只能以特定用户启动)',
|
|
2862
|
+
'如果是 Java 进程,检查堆内存是否不足',
|
|
2863
|
+
]
|
|
2864
|
+
}
|
|
2865
|
+
if (type === 'service') {
|
|
2866
|
+
return [
|
|
2867
|
+
'systemctl status 看具体报错',
|
|
2868
|
+
'journalctl -u 服务名 -n 50 看最近日志',
|
|
2869
|
+
'常见原因:配置写错、端口被占用、依赖服务未启动',
|
|
2870
|
+
]
|
|
2871
|
+
}
|
|
2872
|
+
if (type === 'script') {
|
|
2873
|
+
return [
|
|
2874
|
+
'看脚本的退出码和输出(面板会显示最后一行输出)',
|
|
2875
|
+
'确认解释器存在:python 需要 python3,js 需要 node',
|
|
2876
|
+
'脚本里不要依赖交互式命令,非 0 退出即视为异常',
|
|
2877
|
+
]
|
|
2878
|
+
}
|
|
2879
|
+
return ['检查目标配置是否正确']
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
/** Targeted checks when a monitor fails, so the user has somewhere to look. */
|
|
2883
|
+
async function diagnoseMonitor(cfg, monitor) {
|
|
2884
|
+
const type = monitor.type
|
|
2885
|
+
const target = String(monitor.target || '')
|
|
2886
|
+
const checks = []
|
|
2887
|
+
const run = async (label, command, options = {}) => {
|
|
2888
|
+
const result = await ssh(cfg, command, options.timeoutMs || 25_000)
|
|
2889
|
+
const output = clip(`${result.stdout || ''}${cleanStderr(result.stderr)}`.trim(), 1200) || '(无输出)'
|
|
2890
|
+
const ok = typeof options.judge === 'function' ? options.judge(output, result) : result.ok
|
|
2891
|
+
checks.push({ label, ok, output })
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
if (type === 'port') {
|
|
2895
|
+
const [host, port] = target.split(':')
|
|
2896
|
+
await run('端口是否监听', `ss -ltnp 2>/dev/null | grep -E ':${Number(port) || port}\\b' || echo '没有进程监听该端口'`,
|
|
2897
|
+
{ judge: output => !/没有进程监听/.test(output) })
|
|
2898
|
+
await run('本机连通性', `timeout 4 bash -c '</dev/tcp/${String(host).replace(/[^A-Za-z0-9.-]/g, '')}/${Number(port)}' 2>/dev/null && echo 可连接 || echo 连接失败`,
|
|
2899
|
+
{ judge: output => /可连接/.test(output) })
|
|
2900
|
+
await run('防火墙状态', `systemctl is-active firewalld 2>/dev/null; iptables -S 2>/dev/null | head -15 || true`,
|
|
2901
|
+
{ judge: () => true })
|
|
2902
|
+
} else if (type === 'process') {
|
|
2903
|
+
await run('匹配的进程', `pgrep -af ${q(target)} || echo '没有匹配的进程'`,
|
|
2904
|
+
{ judge: output => !/没有匹配的进程/.test(output) })
|
|
2905
|
+
await run('最近的核心报错', `dmesg 2>/dev/null | grep -iE 'oom|killed process' | tail -5 || echo '(无)'`,
|
|
2906
|
+
{ judge: output => /^\(无\)$/.test(output.trim()) })
|
|
2907
|
+
} else if (type === 'service') {
|
|
2908
|
+
const unit = target.replace(/[^A-Za-z0-9@._-]/g, '')
|
|
2909
|
+
await run('服务状态', `systemctl status ${unit} --no-pager 2>&1 | head -20`,
|
|
2910
|
+
{ judge: output => /Active:\s*active/.test(output) })
|
|
2911
|
+
await run('最近日志', `journalctl -u ${unit} -n 30 --no-pager 2>&1 | tail -30`,
|
|
2912
|
+
{ judge: () => true })
|
|
2913
|
+
} else if (type === 'http') {
|
|
2914
|
+
await run('HTTP 响应头', `curl -sS -I --max-time 10 ${q(target)} 2>&1 | head -20`,
|
|
2915
|
+
{ judge: output => /HTTP\/\d\.\d 2\d\d|HTTP\/\d\.\d 3\d\d/.test(output) })
|
|
2916
|
+
await run('本机到目标', `curl -sS -o /dev/null -w 'code=%{http_code} time=%{time_total}s\\n' --max-time 10 ${q(target)} 2>&1`,
|
|
2917
|
+
{ judge: output => /code=(2|3)\d\d/.test(output) })
|
|
2918
|
+
await run('监听端口', `nginx -T 2>/dev/null | grep -E 'listen|server_name' | head -10 || echo '(未检测到 nginx 配置)'`,
|
|
2919
|
+
{ judge: () => true })
|
|
2920
|
+
} else {
|
|
2921
|
+
await run('脚本解释器', `command -v bash; command -v python3; command -v node; true`)
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
return {
|
|
2925
|
+
host: cfg.name,
|
|
2926
|
+
id: monitor.id,
|
|
2927
|
+
target,
|
|
2928
|
+
type,
|
|
2929
|
+
checks,
|
|
2930
|
+
hints: monitorHints(monitor, { ok: false }),
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
|
|
2823
2934
|
export function apply(ctx) {
|
|
2824
2935
|
hostCtx = ctx
|
|
2825
2936
|
const tools = [
|
|
@@ -3202,7 +3313,7 @@ export function apply(ctx) {
|
|
|
3202
3313
|
+ 'process (command pattern), service (systemd unit).',
|
|
3203
3314
|
parameters: {
|
|
3204
3315
|
host: { type: 'string', description: 'host name from ops_hosts' },
|
|
3205
|
-
action: { type: 'string', enum: ['list', 'add', 'remove', 'test'], description: 'defaults to list' },
|
|
3316
|
+
action: { type: 'string', enum: ['list', 'add', 'remove', 'test', 'diagnose'], description: 'defaults to list' },
|
|
3206
3317
|
type: { type: 'string', enum: ['http', 'port', 'process', 'service', 'script'], description: 'with action=add' },
|
|
3207
3318
|
language: { type: 'string', enum: ['shell', 'python', 'js'], description: 'with type=script' },
|
|
3208
3319
|
script: { type: 'string', description: 'with type=script: the script body' },
|
|
@@ -3225,7 +3336,12 @@ export function apply(ctx) {
|
|
|
3225
3336
|
const monitor = list.find(item => item.id === args.id)
|
|
3226
3337
|
if (!monitor) throw new Error('monitor not found')
|
|
3227
3338
|
const result = await runMonitor(cfg, monitor)
|
|
3228
|
-
return { host: cfg.name, id: monitor.id, result }
|
|
3339
|
+
return { host: cfg.name, id: monitor.id, result, hints: result.ok ? [] : monitorHints(monitor, result) }
|
|
3340
|
+
}
|
|
3341
|
+
if (args.action === 'diagnose') {
|
|
3342
|
+
const monitor = list.find(item => item.id === args.id)
|
|
3343
|
+
if (!monitor) throw new Error('monitor not found')
|
|
3344
|
+
return diagnoseMonitor(cfg, monitor)
|
|
3229
3345
|
}
|
|
3230
3346
|
const monitor = {
|
|
3231
3347
|
id: `m${Date.now().toString(36)}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ops-kit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "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",
|