mcp-ssh-manager 3.0.0 → 3.1.2
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/.claude/settings.local.json +10 -1
- package/CHANGELOG.md +63 -0
- package/CLAUDE.md +16 -0
- package/README.md +117 -4
- package/cli/commands/server.sh +27 -5
- package/cli/commands/tools.sh +603 -0
- package/cli/lib/config.sh +104 -14
- package/cli/lib/menu.sh +124 -0
- package/cli/ssh-manager +17 -7
- package/context-test.txt +1 -0
- package/docs/SOCIAL_MEDIA_ANNOUNCEMENT.md +385 -0
- package/docs/TOOL_MANAGEMENT.md +473 -0
- package/docs/TROUBLESHOOTING.md +143 -0
- package/package.json +5 -4
- package/scripts/validate.sh +12 -0
- package/src/backup-manager.js +12 -12
- package/src/command-aliases.js +16 -16
- package/src/config-loader.js +1 -1
- package/src/config.js +70 -0
- package/src/database-manager.js +38 -40
- package/src/deploy-helper.js +12 -13
- package/src/health-monitor.js +26 -26
- package/src/hooks-system.js +43 -43
- package/src/index.js +899 -841
- package/src/logger.js +53 -53
- package/src/profile-loader.js +14 -14
- package/src/server-aliases.js +11 -11
- package/src/server-groups.js +98 -97
- package/src/session-manager.js +59 -58
- package/src/ssh-key-manager.js +4 -3
- package/src/ssh-manager.js +46 -24
- package/src/tool-config-manager.js +434 -0
- package/src/tool-registry.js +196 -0
- package/src/tunnel-manager.js +98 -98
package/src/command-aliases.js
CHANGED
|
@@ -29,13 +29,13 @@ export function loadCommandAliases() {
|
|
|
29
29
|
try {
|
|
30
30
|
// Start with profile aliases
|
|
31
31
|
let aliases = { ...profileAliases };
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
// Merge with custom aliases from file
|
|
34
34
|
if (fs.existsSync(ALIASES_FILE)) {
|
|
35
35
|
const data = fs.readFileSync(ALIASES_FILE, 'utf8');
|
|
36
36
|
aliases = { ...aliases, ...JSON.parse(data) };
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
return aliases;
|
|
40
40
|
} catch (error) {
|
|
41
41
|
console.error(`Error loading command aliases: ${error.message}`);
|
|
@@ -55,7 +55,7 @@ export function saveCommandAliases(aliases) {
|
|
|
55
55
|
customAliases[key] = value;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
fs.writeFileSync(ALIASES_FILE, JSON.stringify(customAliases, null, 2));
|
|
60
60
|
return true;
|
|
61
61
|
} catch (error) {
|
|
@@ -69,21 +69,21 @@ export function saveCommandAliases(aliases) {
|
|
|
69
69
|
*/
|
|
70
70
|
export function expandCommandAlias(command) {
|
|
71
71
|
const aliases = loadCommandAliases();
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
// Check if the entire command is an alias
|
|
74
74
|
if (aliases[command]) {
|
|
75
75
|
return aliases[command];
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
// Check if the command starts with an alias
|
|
79
79
|
const parts = command.split(' ');
|
|
80
80
|
const firstPart = parts[0];
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
if (aliases[firstPart]) {
|
|
83
83
|
parts[0] = aliases[firstPart];
|
|
84
84
|
return parts.join(' ');
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
return command;
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -101,14 +101,14 @@ export function addCommandAlias(alias, command) {
|
|
|
101
101
|
*/
|
|
102
102
|
export function removeCommandAlias(alias) {
|
|
103
103
|
const aliases = loadCommandAliases();
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
// Don't remove profile aliases, just reset them
|
|
106
106
|
if (profileAliases[alias]) {
|
|
107
107
|
aliases[alias] = profileAliases[alias];
|
|
108
108
|
} else {
|
|
109
109
|
delete aliases[alias];
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
return saveCommandAliases(aliases);
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -118,7 +118,7 @@ export function removeCommandAlias(alias) {
|
|
|
118
118
|
export function listCommandAliases() {
|
|
119
119
|
const aliases = loadCommandAliases();
|
|
120
120
|
const result = [];
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
for (const [alias, command] of Object.entries(aliases)) {
|
|
123
123
|
result.push({
|
|
124
124
|
alias,
|
|
@@ -127,7 +127,7 @@ export function listCommandAliases() {
|
|
|
127
127
|
isCustom: profileAliases[alias] !== command
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
|
|
131
131
|
return result.sort((a, b) => a.alias.localeCompare(b.alias));
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -137,15 +137,15 @@ export function listCommandAliases() {
|
|
|
137
137
|
export function suggestAliases(command) {
|
|
138
138
|
const suggestions = [];
|
|
139
139
|
const aliases = loadCommandAliases();
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
const commandLower = command.toLowerCase();
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
for (const [alias, aliasCommand] of Object.entries(aliases)) {
|
|
144
|
-
if (aliasCommand.toLowerCase().includes(commandLower) ||
|
|
144
|
+
if (aliasCommand.toLowerCase().includes(commandLower) ||
|
|
145
145
|
alias.toLowerCase().includes(commandLower)) {
|
|
146
146
|
suggestions.push({ alias, command: aliasCommand });
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
return suggestions;
|
|
151
|
-
}
|
|
151
|
+
}
|
package/src/config-loader.js
CHANGED
package/src/config.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Configuration constants for MCP SSH Manager
|
|
2
|
+
|
|
3
|
+
// Output limits to prevent Claude Code crashes
|
|
4
|
+
export const OUTPUT_LIMITS = {
|
|
5
|
+
// Maximum length of stdout/stderr in responses (characters)
|
|
6
|
+
MAX_OUTPUT_LENGTH: process.env.MCP_SSH_MAX_OUTPUT_LENGTH
|
|
7
|
+
? parseInt(process.env.MCP_SSH_MAX_OUTPUT_LENGTH)
|
|
8
|
+
: 10000,
|
|
9
|
+
|
|
10
|
+
// Maximum length for log file tailing
|
|
11
|
+
MAX_TAIL_LINES: process.env.MCP_SSH_MAX_TAIL_LINES
|
|
12
|
+
? parseInt(process.env.MCP_SSH_MAX_TAIL_LINES)
|
|
13
|
+
: 100,
|
|
14
|
+
|
|
15
|
+
// Maximum length for rsync verbose output
|
|
16
|
+
MAX_RSYNC_OUTPUT: process.env.MCP_SSH_MAX_RSYNC_OUTPUT
|
|
17
|
+
? parseInt(process.env.MCP_SSH_MAX_RSYNC_OUTPUT)
|
|
18
|
+
: 5000,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Timeout configuration
|
|
22
|
+
export const TIMEOUTS = {
|
|
23
|
+
// Default command execution timeout (milliseconds)
|
|
24
|
+
DEFAULT_COMMAND_TIMEOUT: process.env.MCP_SSH_DEFAULT_TIMEOUT
|
|
25
|
+
? parseInt(process.env.MCP_SSH_DEFAULT_TIMEOUT)
|
|
26
|
+
: 120000, // 2 minutes
|
|
27
|
+
|
|
28
|
+
// Maximum allowed command timeout (milliseconds)
|
|
29
|
+
MAX_COMMAND_TIMEOUT: process.env.MCP_SSH_MAX_TIMEOUT
|
|
30
|
+
? parseInt(process.env.MCP_SSH_MAX_TIMEOUT)
|
|
31
|
+
: 300000, // 5 minutes
|
|
32
|
+
|
|
33
|
+
// Connection timeout (milliseconds)
|
|
34
|
+
CONNECTION_TIMEOUT: process.env.MCP_SSH_CONNECTION_TIMEOUT
|
|
35
|
+
? parseInt(process.env.MCP_SSH_CONNECTION_TIMEOUT)
|
|
36
|
+
: 1800000, // 30 minutes
|
|
37
|
+
|
|
38
|
+
// Keepalive interval (milliseconds)
|
|
39
|
+
KEEPALIVE_INTERVAL: process.env.MCP_SSH_KEEPALIVE_INTERVAL
|
|
40
|
+
? parseInt(process.env.MCP_SSH_KEEPALIVE_INTERVAL)
|
|
41
|
+
: 60000, // 1 minute
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Response formatting
|
|
45
|
+
export const RESPONSE_FORMAT = {
|
|
46
|
+
// Whether to use compact JSON (no formatting)
|
|
47
|
+
COMPACT_JSON: process.env.MCP_SSH_COMPACT_JSON === 'true',
|
|
48
|
+
|
|
49
|
+
// Whether to include debug information in responses
|
|
50
|
+
INCLUDE_DEBUG_INFO: process.env.MCP_SSH_DEBUG === 'true',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Helper function to truncate output
|
|
54
|
+
export function truncateOutput(text, maxLength = OUTPUT_LIMITS.MAX_OUTPUT_LENGTH) {
|
|
55
|
+
if (!text) return '';
|
|
56
|
+
|
|
57
|
+
if (text.length <= maxLength) return text;
|
|
58
|
+
|
|
59
|
+
const truncated = text.length - maxLength;
|
|
60
|
+
return text.substring(0, maxLength) + `\n\n... [${truncated} characters truncated]`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Helper function to format JSON response
|
|
64
|
+
export function formatJSONResponse(data) {
|
|
65
|
+
return JSON.stringify(
|
|
66
|
+
data,
|
|
67
|
+
null,
|
|
68
|
+
RESPONSE_FORMAT.COMPACT_JSON ? 0 : 2
|
|
69
|
+
);
|
|
70
|
+
}
|
package/src/database-manager.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* Provides database operations for MySQL, PostgreSQL, and MongoDB
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { logger } from './logger.js';
|
|
7
|
-
|
|
8
6
|
// Supported database types
|
|
9
7
|
export const DB_TYPES = {
|
|
10
8
|
MYSQL: 'mysql',
|
|
@@ -254,7 +252,7 @@ export function buildMySQLListDatabasesCommand(options) {
|
|
|
254
252
|
if (password) command += ` -p'${password}'`;
|
|
255
253
|
if (host) command += ` -h ${host}`;
|
|
256
254
|
if (port) command += ` -P ${port}`;
|
|
257
|
-
command +=
|
|
255
|
+
command += ' -e "SHOW DATABASES;" | tail -n +2';
|
|
258
256
|
|
|
259
257
|
return command;
|
|
260
258
|
}
|
|
@@ -290,7 +288,7 @@ export function buildPostgreSQLListDatabasesCommand(options) {
|
|
|
290
288
|
if (user) command += ` -U ${user}`;
|
|
291
289
|
if (host) command += ` -h ${host}`;
|
|
292
290
|
if (port) command += ` -p ${port}`;
|
|
293
|
-
command +=
|
|
291
|
+
command += ' -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;" | sed \'/^$/d\' | sed \'s/^[ \\t]*//\'';
|
|
294
292
|
|
|
295
293
|
return command;
|
|
296
294
|
}
|
|
@@ -311,7 +309,7 @@ export function buildPostgreSQLListTablesCommand(options) {
|
|
|
311
309
|
if (host) command += ` -h ${host}`;
|
|
312
310
|
if (port) command += ` -p ${port}`;
|
|
313
311
|
command += ` -d ${database}`;
|
|
314
|
-
command +=
|
|
312
|
+
command += ' -t -c "SELECT tablename FROM pg_tables WHERE schemaname = \'public\';" | sed \'/^$/d\' | sed \'s/^[ \\t]*//\'';
|
|
315
313
|
|
|
316
314
|
return command;
|
|
317
315
|
}
|
|
@@ -327,7 +325,7 @@ export function buildMongoDBListDatabasesCommand(options) {
|
|
|
327
325
|
if (port) command += ` --port ${port}`;
|
|
328
326
|
if (user) command += ` --username ${user}`;
|
|
329
327
|
if (password) command += ` --password '${password}'`;
|
|
330
|
-
command +=
|
|
328
|
+
command += ' --quiet --eval "db.adminCommand(\'listDatabases\').databases.forEach(function(d){print(d.name)})"';
|
|
331
329
|
|
|
332
330
|
return command;
|
|
333
331
|
}
|
|
@@ -344,7 +342,7 @@ export function buildMongoDBListCollectionsCommand(options) {
|
|
|
344
342
|
if (user) command += ` --username ${user}`;
|
|
345
343
|
if (password) command += ` --password '${password}'`;
|
|
346
344
|
command += ` ${database}`;
|
|
347
|
-
command +=
|
|
345
|
+
command += ' --quiet --eval "db.getCollectionNames().forEach(function(c){print(c)})"';
|
|
348
346
|
|
|
349
347
|
return command;
|
|
350
348
|
}
|
|
@@ -479,43 +477,43 @@ export function buildEstimateSizeCommand(type, database, options = {}) {
|
|
|
479
477
|
const { user, password, host = 'localhost', port } = options;
|
|
480
478
|
|
|
481
479
|
switch (type) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
480
|
+
case DB_TYPES.MYSQL: {
|
|
481
|
+
let command = 'mysql';
|
|
482
|
+
if (user) command += ` -u${user}`;
|
|
483
|
+
if (password) command += ` -p'${password}'`;
|
|
484
|
+
if (host) command += ` -h ${host}`;
|
|
485
|
+
if (port) command += ` -P ${port}`;
|
|
486
|
+
command += ` -e "SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema='${database}';" | tail -n 1`;
|
|
487
|
+
return command;
|
|
488
|
+
}
|
|
491
489
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
command += 'psql';
|
|
498
|
-
if (user) command += ` -U ${user}`;
|
|
499
|
-
if (host) command += ` -h ${host}`;
|
|
500
|
-
if (port) command += ` -p ${port}`;
|
|
501
|
-
command += ` -d ${database}`;
|
|
502
|
-
command += ` -t -c "SELECT pg_database_size('${database}');" | sed 's/^[ \\t]*//'`;
|
|
503
|
-
return command;
|
|
490
|
+
case DB_TYPES.POSTGRESQL: {
|
|
491
|
+
let command = '';
|
|
492
|
+
if (password) {
|
|
493
|
+
command = `PGPASSWORD='${password}' `;
|
|
504
494
|
}
|
|
495
|
+
command += 'psql';
|
|
496
|
+
if (user) command += ` -U ${user}`;
|
|
497
|
+
if (host) command += ` -h ${host}`;
|
|
498
|
+
if (port) command += ` -p ${port}`;
|
|
499
|
+
command += ` -d ${database}`;
|
|
500
|
+
command += ` -t -c "SELECT pg_database_size('${database}');" | sed 's/^[ \\t]*//'`;
|
|
501
|
+
return command;
|
|
502
|
+
}
|
|
505
503
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
504
|
+
case DB_TYPES.MONGODB: {
|
|
505
|
+
let command = 'mongo';
|
|
506
|
+
if (host) command += ` --host ${host}`;
|
|
507
|
+
if (port) command += ` --port ${port}`;
|
|
508
|
+
if (user) command += ` --username ${user}`;
|
|
509
|
+
if (password) command += ` --password '${password}'`;
|
|
510
|
+
command += ` ${database}`;
|
|
511
|
+
command += ' --quiet --eval "db.stats().dataSize"';
|
|
512
|
+
return command;
|
|
513
|
+
}
|
|
516
514
|
|
|
517
|
-
|
|
518
|
-
|
|
515
|
+
default:
|
|
516
|
+
throw new Error(`Unknown database type: ${type}`);
|
|
519
517
|
}
|
|
520
518
|
}
|
|
521
519
|
|
package/src/deploy-helper.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import crypto from 'crypto';
|
|
4
3
|
|
|
@@ -43,8 +42,8 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
|
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
// Step 2: Determine if we need sudo
|
|
46
|
-
const needsSudo = remotePath.startsWith('/etc/') ||
|
|
47
|
-
remotePath.startsWith('/var/') ||
|
|
45
|
+
const needsSudo = remotePath.startsWith('/etc/') ||
|
|
46
|
+
remotePath.startsWith('/var/') ||
|
|
48
47
|
remotePath.startsWith('/usr/') ||
|
|
49
48
|
owner || permissions;
|
|
50
49
|
|
|
@@ -53,11 +52,11 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
// Step 3: Copy from temp to final location
|
|
56
|
-
const copyCmd = needsSudo && sudoPassword ?
|
|
55
|
+
const copyCmd = needsSudo && sudoPassword ?
|
|
57
56
|
`echo "${sudoPassword}" | sudo -S cp {{tempFile}} "${remotePath}"` :
|
|
58
57
|
needsSudo ?
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
`sudo cp {{tempFile}} "${remotePath}"` :
|
|
59
|
+
`cp {{tempFile}} "${remotePath}"`;
|
|
61
60
|
|
|
62
61
|
strategy.steps.push({
|
|
63
62
|
type: 'copy',
|
|
@@ -69,7 +68,7 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
|
|
|
69
68
|
const chownCmd = sudoPassword ?
|
|
70
69
|
`echo "${sudoPassword}" | sudo -S chown ${owner} "${remotePath}"` :
|
|
71
70
|
`sudo chown ${owner} "${remotePath}"`;
|
|
72
|
-
|
|
71
|
+
|
|
73
72
|
strategy.steps.push({
|
|
74
73
|
type: 'chown',
|
|
75
74
|
command: chownCmd
|
|
@@ -81,7 +80,7 @@ export function buildDeploymentStrategy(remotePath, options = {}) {
|
|
|
81
80
|
const chmodCmd = sudoPassword ?
|
|
82
81
|
`echo "${sudoPassword}" | sudo -S chmod ${permissions} "${remotePath}"` :
|
|
83
82
|
`sudo chmod ${permissions} "${remotePath}"`;
|
|
84
|
-
|
|
83
|
+
|
|
85
84
|
strategy.steps.push({
|
|
86
85
|
type: 'chmod',
|
|
87
86
|
command: chmodCmd
|
|
@@ -151,11 +150,11 @@ export function detectDeploymentNeeds(remotePath) {
|
|
|
151
150
|
*/
|
|
152
151
|
export function createBatchDeployScript(deployments) {
|
|
153
152
|
const script = ['#!/bin/bash', 'set -e', ''];
|
|
154
|
-
|
|
153
|
+
|
|
155
154
|
script.push('# Batch deployment script');
|
|
156
155
|
script.push(`# Generated at ${new Date().toISOString()}`);
|
|
157
156
|
script.push('');
|
|
158
|
-
|
|
157
|
+
|
|
159
158
|
deployments.forEach((deploy, index) => {
|
|
160
159
|
script.push(`# File ${index + 1}: ${deploy.localPath} -> ${deploy.remotePath}`);
|
|
161
160
|
deploy.strategy.steps.forEach(step => {
|
|
@@ -165,12 +164,12 @@ export function createBatchDeployScript(deployments) {
|
|
|
165
164
|
});
|
|
166
165
|
script.push('');
|
|
167
166
|
});
|
|
168
|
-
|
|
167
|
+
|
|
169
168
|
// Cleanup all temp files at the end
|
|
170
169
|
script.push('# Cleanup temporary files');
|
|
171
170
|
deployments.forEach(deploy => {
|
|
172
171
|
script.push(`rm -f ${deploy.tempFile}`);
|
|
173
172
|
});
|
|
174
|
-
|
|
173
|
+
|
|
175
174
|
return script.join('\n');
|
|
176
|
-
}
|
|
175
|
+
}
|
package/src/health-monitor.js
CHANGED
|
@@ -30,7 +30,7 @@ export const COMMON_SERVICES = {
|
|
|
30
30
|
*/
|
|
31
31
|
export function buildCPUCheckCommand() {
|
|
32
32
|
// Get CPU usage using top, show idle percentage, calculate used
|
|
33
|
-
return
|
|
33
|
+
return 'top -bn1 | grep "Cpu(s)" | sed "s/.*, *\\([0-9.]*\\)%* id.*/\\1/" | awk \'{print 100 - $1}\'';
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -38,7 +38,7 @@ export function buildCPUCheckCommand() {
|
|
|
38
38
|
*/
|
|
39
39
|
export function buildMemoryCheckCommand() {
|
|
40
40
|
// Returns: total, used, free, available in MB and percentage
|
|
41
|
-
return
|
|
41
|
+
return 'free -m | awk \'NR==2{printf "{\\"total\\":%s,\\"used\\":%s,\\"free\\":%s,\\"percent\\":%.2f}", $2,$3,$4,$3*100/$2}\'';
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -47,7 +47,7 @@ export function buildMemoryCheckCommand() {
|
|
|
47
47
|
export function buildDiskCheckCommand(mountPoint = '/') {
|
|
48
48
|
// Returns JSON with disk usage for specific mount point or all
|
|
49
49
|
if (mountPoint === 'all') {
|
|
50
|
-
return
|
|
50
|
+
return 'df -h | awk \'NR>1 {gsub(/%/,"",$5); printf "{\\"mount\\":\\"%s\\",\\"size\\":\\"%s\\",\\"used\\":\\"%s\\",\\"avail\\":\\"%s\\",\\"percent\\":%s}\\n", $6,$2,$3,$4,$5}\'';
|
|
51
51
|
}
|
|
52
52
|
return `df -h "${mountPoint}" | awk 'NR>1 {gsub(/%/,"",$5); printf "{\\"mount\\":\\"%s\\",\\"size\\":\\"%s\\",\\"used\\":\\"%s\\",\\"avail\\":\\"%s\\",\\"percent\\":%s}", $6,$2,$3,$4,$5}'`;
|
|
53
53
|
}
|
|
@@ -57,21 +57,21 @@ export function buildDiskCheckCommand(mountPoint = '/') {
|
|
|
57
57
|
*/
|
|
58
58
|
export function buildNetworkCheckCommand() {
|
|
59
59
|
// Get basic network stats (RX/TX bytes)
|
|
60
|
-
return
|
|
60
|
+
return 'cat /proc/net/dev | awk \'NR>2 {printf "{\\"interface\\":\\"%s\\",\\"rx_bytes\\":%s,\\"tx_bytes\\":%s}\\n", $1,$2,$10}\' | grep -v "lo:"';
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Build command to check load average
|
|
65
65
|
*/
|
|
66
66
|
export function buildLoadAverageCommand() {
|
|
67
|
-
return
|
|
67
|
+
return 'uptime | awk -F\'load average:\' \'{print $2}\' | sed \'s/^[ \\t]*//\'';
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Build command to check system uptime
|
|
72
72
|
*/
|
|
73
73
|
export function buildUptimeCommand() {
|
|
74
|
-
return
|
|
74
|
+
return 'uptime -p 2>/dev/null || uptime | awk \'{print $3,$4}\' | sed \'s/,//\'';
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -225,7 +225,7 @@ export function buildProcessListCommand(options = {}) {
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
// Format output as JSON-like structure
|
|
228
|
-
command +=
|
|
228
|
+
command += ' | awk \'NR>1 {printf "{\\"user\\":\\"%s\\",\\"pid\\":%s,\\"cpu\\":%.1f,\\"mem\\":%.1f,\\"vsz\\":%s,\\"rss\\":%s,\\"stat\\":\\"%s\\",\\"start\\":\\"%s\\",\\"time\\":\\"%s\\",\\"command\\":\\"%s\\"}\\n", $1,$2,$3,$4,$5,$6,$8,$9,$10,substr($0,index($0,$11))}\'';
|
|
229
229
|
|
|
230
230
|
return command;
|
|
231
231
|
}
|
|
@@ -296,7 +296,7 @@ export function createAlertConfig(thresholds) {
|
|
|
296
296
|
*/
|
|
297
297
|
export function buildSaveAlertConfigCommand(config, configPath = '/etc/ssh-manager-alerts.json') {
|
|
298
298
|
const jsonData = JSON.stringify(config, null, 2);
|
|
299
|
-
const escapedJson = jsonData.replace(/'/g,
|
|
299
|
+
const escapedJson = jsonData.replace(/'/g, '\'\\\'\'');
|
|
300
300
|
return `echo '${escapedJson}' > "${configPath}"`;
|
|
301
301
|
}
|
|
302
302
|
|
|
@@ -383,24 +383,24 @@ export function parseComprehensiveHealthCheck(output) {
|
|
|
383
383
|
const data = content.join('\n').trim();
|
|
384
384
|
|
|
385
385
|
switch (name.toLowerCase().trim()) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
386
|
+
case 'cpu ===':
|
|
387
|
+
result.cpu = parseCPUUsage(data);
|
|
388
|
+
break;
|
|
389
|
+
case 'memory ===':
|
|
390
|
+
result.memory = parseMemoryUsage(data);
|
|
391
|
+
break;
|
|
392
|
+
case 'disk ===':
|
|
393
|
+
result.disks = parseDiskUsage(data);
|
|
394
|
+
break;
|
|
395
|
+
case 'load ===':
|
|
396
|
+
result.load_average = data;
|
|
397
|
+
break;
|
|
398
|
+
case 'uptime ===':
|
|
399
|
+
result.uptime = data;
|
|
400
|
+
break;
|
|
401
|
+
case 'network ===':
|
|
402
|
+
result.network = parseNetworkStats(data);
|
|
403
|
+
break;
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
|