@opscompass/opscompass-cli 1.3.2 → 1.3.3
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/lib/dataGathering/events.js +146 -0
- package/lib/dataGathering/moduleDiscovery.js +62 -0
- package/lib/dataGathering/olmDataParms.js +140 -0
- package/lib/dataGathering/sendDg.js +971 -0
- package/lib/dataGathering/setupWizard.js +826 -0
- package/lib/dataGathering/ui.js +83 -0
- package/lib/dataGathering/validateInstall.js +210 -0
- package/lib/homeInteraction.js +84 -19
- package/lib/maskValues.js +305 -71
- package/lib/pgpTools.js +156 -92
- package/lib/utils.js +122 -39
- package/modules/data-gathering-scripts.js +6 -35
- package/modules/data-gathering.js +732 -0
- package/modules/defaults.js +68 -15
- package/modules/license-manager/importMonitoringConfiguration.js +369 -0
- package/modules/license-manager/microsoft.js +11 -4
- package/modules/license-manager/nutanix.js +10 -4
- package/modules/license-manager/resolveMonitoringConfigId.js +28 -0
- package/modules/license-manager/vcenter.js +10 -4
- package/modules/license-manager.js +89 -9
- package/modules.js +2 -0
- package/package.json +34 -6
- package/updates.js +409 -57
- package/environment/demo.js +0 -30
- package/environment/dev.js +0 -30
- package/environment/local.js +0 -31
- package/environment/production.js +0 -30
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
|
|
4
|
+
import { ScriptType, cliCommand } from "../environment/current.js";
|
|
5
|
+
import {
|
|
6
|
+
assertScriptBundleVerified,
|
|
7
|
+
BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
|
|
8
|
+
findOrCreateScriptTypeFolder,
|
|
9
|
+
previousScriptsDownloaded,
|
|
10
|
+
SRC_FOLDER_NAME,
|
|
11
|
+
} from "../lib/homeInteraction.js";
|
|
12
|
+
import { canReadFile } from "../lib/cliHelpers.js";
|
|
13
|
+
import {
|
|
14
|
+
DATA_GATHERING_EXIT_CODES,
|
|
15
|
+
DataGatheringError,
|
|
16
|
+
createEventLogger,
|
|
17
|
+
normalizeDataGatheringExitCode,
|
|
18
|
+
redactString,
|
|
19
|
+
} from "../lib/dataGathering/events.js";
|
|
20
|
+
import { runSetupWizard } from "../lib/dataGathering/setupWizard.js";
|
|
21
|
+
import { listInstalledModules } from "../lib/dataGathering/moduleDiscovery.js";
|
|
22
|
+
import { createDataGatheringUi } from "../lib/dataGathering/ui.js";
|
|
23
|
+
import { runValidateInstallCommand } from "../lib/dataGathering/validateInstall.js";
|
|
24
|
+
|
|
25
|
+
const DEFAULT_RUN_TIMEOUT_MS = 60 * 60 * 1000;
|
|
26
|
+
const RUN_TARGET_ALL = "all";
|
|
27
|
+
const DATA_GATHERING_OUTPUT_EVENT_TYPE = Object.freeze({
|
|
28
|
+
stdout: "process.stdout",
|
|
29
|
+
stderr: "process.stderr",
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function parseDataGatheringGlobalArgs(args) {
|
|
33
|
+
const options = {
|
|
34
|
+
redact: true,
|
|
35
|
+
verbose: false,
|
|
36
|
+
};
|
|
37
|
+
const remainingArgs = [];
|
|
38
|
+
|
|
39
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
40
|
+
const arg = args[index];
|
|
41
|
+
switch (arg) {
|
|
42
|
+
case "--no-redact":
|
|
43
|
+
options.redact = false;
|
|
44
|
+
break;
|
|
45
|
+
case "--verbose":
|
|
46
|
+
options.verbose = true;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
remainingArgs.push(arg);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
options,
|
|
56
|
+
remainingArgs,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function readRequiredFlagValue(args, index, flagName) {
|
|
61
|
+
const value = args[index + 1];
|
|
62
|
+
if (value === undefined || value.startsWith("--")) {
|
|
63
|
+
throw new DataGatheringError(`${flagName} requires a value`, {
|
|
64
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
65
|
+
type: "run.invalid-input",
|
|
66
|
+
data: {
|
|
67
|
+
flag: flagName,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function parsePositiveInteger(rawValue, flagName) {
|
|
76
|
+
const parsed = Number.parseInt(rawValue, 10);
|
|
77
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
78
|
+
throw new DataGatheringError(`${flagName} must be a positive integer`, {
|
|
79
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
80
|
+
type: "run.invalid-input",
|
|
81
|
+
data: {
|
|
82
|
+
flag: flagName,
|
|
83
|
+
value: rawValue,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return parsed;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function parseRunArgs(args) {
|
|
92
|
+
let scriptType = ScriptType.baseScripts;
|
|
93
|
+
let allowUnverified = false;
|
|
94
|
+
let dryRun = false;
|
|
95
|
+
let failFast = false;
|
|
96
|
+
let timeoutMs;
|
|
97
|
+
let noTimeout = false;
|
|
98
|
+
let transfer = "auto";
|
|
99
|
+
let parallel;
|
|
100
|
+
const modules = [];
|
|
101
|
+
let configPath;
|
|
102
|
+
const passthroughArgs = [];
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
105
|
+
const arg = args[i];
|
|
106
|
+
switch (arg) {
|
|
107
|
+
case "--script-type":
|
|
108
|
+
scriptType = readRequiredFlagValue(args, i, "--script-type");
|
|
109
|
+
i += 1;
|
|
110
|
+
break;
|
|
111
|
+
case "--allow-unverified":
|
|
112
|
+
allowUnverified = true;
|
|
113
|
+
break;
|
|
114
|
+
case "--dry-run":
|
|
115
|
+
dryRun = true;
|
|
116
|
+
break;
|
|
117
|
+
case "--fail-fast":
|
|
118
|
+
failFast = true;
|
|
119
|
+
break;
|
|
120
|
+
case "--timeout-ms": {
|
|
121
|
+
const value = readRequiredFlagValue(args, i, "--timeout-ms");
|
|
122
|
+
timeoutMs = parsePositiveInteger(value, "--timeout-ms");
|
|
123
|
+
i += 1;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case "--no-timeout":
|
|
127
|
+
noTimeout = true;
|
|
128
|
+
break;
|
|
129
|
+
case "--transfer":
|
|
130
|
+
transfer = readRequiredFlagValue(args, i, "--transfer");
|
|
131
|
+
i += 1;
|
|
132
|
+
break;
|
|
133
|
+
case "--parallel": {
|
|
134
|
+
const value = readRequiredFlagValue(args, i, "--parallel");
|
|
135
|
+
parallel = parsePositiveInteger(value, "--parallel");
|
|
136
|
+
i += 1;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case "--module": {
|
|
140
|
+
const moduleName = readRequiredFlagValue(args, i, "--module");
|
|
141
|
+
modules.push(moduleName);
|
|
142
|
+
i += 1;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case "--config":
|
|
146
|
+
configPath = readRequiredFlagValue(args, i, "--config");
|
|
147
|
+
passthroughArgs.push("--config", configPath);
|
|
148
|
+
i += 1;
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
if (arg.startsWith("--")) {
|
|
152
|
+
throw new DataGatheringError(`Unknown run flag: ${arg}`, {
|
|
153
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
154
|
+
type: "run.invalid-input",
|
|
155
|
+
data: {
|
|
156
|
+
flag: arg,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
passthroughArgs.push(arg);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (!Object.values(ScriptType).includes(scriptType)) {
|
|
166
|
+
throw new DataGatheringError(
|
|
167
|
+
`Unknown script type: ${scriptType}. Expected one of ${JSON.stringify(Object.values(ScriptType))}`,
|
|
168
|
+
{
|
|
169
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
170
|
+
type: "run.invalid-input",
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (![
|
|
176
|
+
"auto",
|
|
177
|
+
"always",
|
|
178
|
+
"never",
|
|
179
|
+
].includes(transfer)) {
|
|
180
|
+
throw new DataGatheringError(
|
|
181
|
+
`Unsupported transfer mode '${transfer}'. Expected auto|always|never.`,
|
|
182
|
+
{
|
|
183
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
184
|
+
type: "run.invalid-input",
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (parallel !== undefined && parallel > 1) {
|
|
190
|
+
throw new DataGatheringError(
|
|
191
|
+
"--parallel is part of the command surface but is not available yet",
|
|
192
|
+
{
|
|
193
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
194
|
+
type: "run.parallel-disabled",
|
|
195
|
+
},
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
scriptType,
|
|
201
|
+
allowUnverified,
|
|
202
|
+
dryRun,
|
|
203
|
+
failFast,
|
|
204
|
+
timeoutMs,
|
|
205
|
+
noTimeout,
|
|
206
|
+
transfer,
|
|
207
|
+
parallel,
|
|
208
|
+
modules,
|
|
209
|
+
configPath,
|
|
210
|
+
passthroughArgs,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function getConfiguredTimeoutMs(runOptions) {
|
|
215
|
+
if (runOptions.noTimeout) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (Number.isFinite(runOptions.timeoutMs)) {
|
|
220
|
+
return Math.max(1000, runOptions.timeoutMs);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const configuredTimeout = Number.parseInt(
|
|
224
|
+
process.env.OPSCOMPASS_DATA_GATHERING_TIMEOUT_MS || `${DEFAULT_RUN_TIMEOUT_MS}`,
|
|
225
|
+
10,
|
|
226
|
+
);
|
|
227
|
+
return Number.isFinite(configuredTimeout)
|
|
228
|
+
? Math.max(1000, configuredTimeout)
|
|
229
|
+
: DEFAULT_RUN_TIMEOUT_MS;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function createRunStartedPayload(runOptions) {
|
|
233
|
+
return {
|
|
234
|
+
modules: runOptions.modules,
|
|
235
|
+
transfer: runOptions.transfer,
|
|
236
|
+
dryRun: runOptions.dryRun,
|
|
237
|
+
failFast: runOptions.failFast,
|
|
238
|
+
timeoutMs: runOptions.noTimeout ? null : getConfiguredTimeoutMs(runOptions),
|
|
239
|
+
scriptType: runOptions.scriptType,
|
|
240
|
+
config: runOptions.configPath,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function createDryRunPlan(runOptions) {
|
|
245
|
+
return {
|
|
246
|
+
modules: runOptions.modules,
|
|
247
|
+
transfer: runOptions.transfer,
|
|
248
|
+
config: runOptions.configPath,
|
|
249
|
+
scriptType: runOptions.scriptType,
|
|
250
|
+
parallelRequested: runOptions.parallel,
|
|
251
|
+
status: "planned",
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function buildRunnerArgs(runOptions) {
|
|
256
|
+
const runnerArgs = [...runOptions.passthroughArgs];
|
|
257
|
+
|
|
258
|
+
for (const moduleName of runOptions.modules) {
|
|
259
|
+
runnerArgs.push("-m", moduleName);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return runnerArgs;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function resolveTargetModules(runOptions) {
|
|
266
|
+
return runOptions.modules.length > 0 ? runOptions.modules : [RUN_TARGET_ALL];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function isTransferAllowed(runOptions) {
|
|
270
|
+
if (runOptions.transfer === "auto") {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function emitCapturedOutput(logger, eventType, chunk) {
|
|
278
|
+
const output = chunk.toString();
|
|
279
|
+
const lines = output.split(/\r?\n/).filter(Boolean);
|
|
280
|
+
for (const line of lines) {
|
|
281
|
+
logger.emit(eventType, {
|
|
282
|
+
line: redactString(line),
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async function runScriptFile(scriptPath, args = [], options = {}) {
|
|
288
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_RUN_TIMEOUT_MS;
|
|
289
|
+
|
|
290
|
+
return new Promise((resolve, reject) => {
|
|
291
|
+
const child = spawn(scriptPath, args, {
|
|
292
|
+
shell: false,
|
|
293
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
294
|
+
windowsHide: true,
|
|
295
|
+
env: process.env,
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
let settled = false;
|
|
299
|
+
let timedOut = false;
|
|
300
|
+
let interrupted = false;
|
|
301
|
+
let timeoutHandle;
|
|
302
|
+
|
|
303
|
+
const finish = (callback) => (value) => {
|
|
304
|
+
if (settled) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
settled = true;
|
|
308
|
+
if (timeoutHandle) {
|
|
309
|
+
clearTimeout(timeoutHandle);
|
|
310
|
+
}
|
|
311
|
+
if (interruptHandler) {
|
|
312
|
+
process.off("SIGINT", interruptHandler);
|
|
313
|
+
}
|
|
314
|
+
callback(value);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const resolveOnce = finish(resolve);
|
|
318
|
+
const rejectOnce = finish(reject);
|
|
319
|
+
|
|
320
|
+
const interruptHandler = () => {
|
|
321
|
+
interrupted = true;
|
|
322
|
+
child.kill("SIGINT");
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
process.on("SIGINT", interruptHandler);
|
|
326
|
+
|
|
327
|
+
child.stdout?.on("data", (chunk) => {
|
|
328
|
+
options.onStdout?.(chunk);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
child.stderr?.on("data", (chunk) => {
|
|
332
|
+
options.onStderr?.(chunk);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
if (timeoutMs !== null) {
|
|
336
|
+
timeoutHandle = setTimeout(() => {
|
|
337
|
+
timedOut = true;
|
|
338
|
+
child.kill("SIGTERM");
|
|
339
|
+
}, timeoutMs);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
child.on("error", (error) => {
|
|
343
|
+
rejectOnce(error);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
child.on("close", (code, signal) => {
|
|
347
|
+
if (timedOut) {
|
|
348
|
+
resolveOnce({
|
|
349
|
+
exitCode: DATA_GATHERING_EXIT_CODES.internalError,
|
|
350
|
+
signal: signal || "SIGTERM",
|
|
351
|
+
timedOut: true,
|
|
352
|
+
interrupted: false,
|
|
353
|
+
});
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (interrupted || signal === "SIGINT") {
|
|
358
|
+
resolveOnce({
|
|
359
|
+
exitCode: DATA_GATHERING_EXIT_CODES.interrupted,
|
|
360
|
+
signal: signal || "SIGINT",
|
|
361
|
+
timedOut: false,
|
|
362
|
+
interrupted: true,
|
|
363
|
+
});
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
resolveOnce({
|
|
368
|
+
exitCode: code ?? DATA_GATHERING_EXIT_CODES.internalError,
|
|
369
|
+
signal: signal ?? null,
|
|
370
|
+
timedOut: false,
|
|
371
|
+
interrupted: false,
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function createModuleCompletionEvent(result) {
|
|
378
|
+
return {
|
|
379
|
+
status: result.exitCode === 0 ? "success" : "failed",
|
|
380
|
+
exitCode: normalizeDataGatheringExitCode(result.exitCode),
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function createCompletedPayload(targetModules, result) {
|
|
385
|
+
if (result.interrupted) {
|
|
386
|
+
return {
|
|
387
|
+
status: "failed",
|
|
388
|
+
exitCode: DATA_GATHERING_EXIT_CODES.interrupted,
|
|
389
|
+
targetsTotal: targetModules.length,
|
|
390
|
+
targetsFailed: targetModules.length,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (result.timedOut) {
|
|
395
|
+
return {
|
|
396
|
+
status: "failed",
|
|
397
|
+
exitCode: DATA_GATHERING_EXIT_CODES.internalError,
|
|
398
|
+
targetsTotal: targetModules.length,
|
|
399
|
+
targetsFailed: targetModules.length,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const normalizedExitCode = normalizeDataGatheringExitCode(result.exitCode);
|
|
404
|
+
if (normalizedExitCode === DATA_GATHERING_EXIT_CODES.success) {
|
|
405
|
+
return {
|
|
406
|
+
status: "success",
|
|
407
|
+
exitCode: DATA_GATHERING_EXIT_CODES.success,
|
|
408
|
+
targetsTotal: targetModules.length,
|
|
409
|
+
targetsFailed: 0,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
status: "failed",
|
|
415
|
+
exitCode:
|
|
416
|
+
normalizedExitCode === DATA_GATHERING_EXIT_CODES.internalError
|
|
417
|
+
? DATA_GATHERING_EXIT_CODES.partialFailure
|
|
418
|
+
: normalizedExitCode,
|
|
419
|
+
targetsTotal: targetModules.length,
|
|
420
|
+
targetsFailed: targetModules.length,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function validateTransferMode(runOptions, logger) {
|
|
425
|
+
if (runOptions.dryRun) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (runOptions.transfer === "auto") {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
logger.emit("artifact.transfer_skipped", {
|
|
434
|
+
reason:
|
|
435
|
+
`Transfer mode '${runOptions.transfer}' is planned for a future update and is not yet supported for live runs.`,
|
|
436
|
+
transfer: runOptions.transfer,
|
|
437
|
+
});
|
|
438
|
+
throw new DataGatheringError(
|
|
439
|
+
`Transfer mode '${runOptions.transfer}' is not supported for execution yet. Use --transfer auto or --dry-run.`,
|
|
440
|
+
{
|
|
441
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
442
|
+
type: "run.transfer-unsupported",
|
|
443
|
+
data: {
|
|
444
|
+
transfer: runOptions.transfer,
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async function runDataGathering(args, logger = createEventLogger()) {
|
|
451
|
+
const runOptions = parseRunArgs(args);
|
|
452
|
+
|
|
453
|
+
if (!previousScriptsDownloaded(runOptions.scriptType)) {
|
|
454
|
+
throw new DataGatheringError(
|
|
455
|
+
`No scripts installed for ${runOptions.scriptType}. Download scripts first using \`${cliCommand} data-gathering-scripts download-scripts --script-type ${runOptions.scriptType}\``,
|
|
456
|
+
{
|
|
457
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
458
|
+
type: "run.scripts-missing",
|
|
459
|
+
},
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
logger.emit("run.started", createRunStartedPayload(runOptions));
|
|
464
|
+
if (!logger.redact) {
|
|
465
|
+
logger.emit("warning", {
|
|
466
|
+
message: "Secret redaction disabled via --no-redact. Dev troubleshooting only.",
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (runOptions.dryRun) {
|
|
471
|
+
const plan = createDryRunPlan(runOptions);
|
|
472
|
+
if (runOptions.transfer === "never") {
|
|
473
|
+
logger.emit("artifact.transfer_skipped", {
|
|
474
|
+
transfer: runOptions.transfer,
|
|
475
|
+
reason: "Transfer disabled by operator request during dry-run.",
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
logger.emit("run.planned", plan);
|
|
479
|
+
logger.emit("run.completed", {
|
|
480
|
+
status: "success",
|
|
481
|
+
exitCode: DATA_GATHERING_EXIT_CODES.success,
|
|
482
|
+
targetsTotal: resolveTargetModules(runOptions).length,
|
|
483
|
+
targetsFailed: 0,
|
|
484
|
+
});
|
|
485
|
+
return {
|
|
486
|
+
exitCode: DATA_GATHERING_EXIT_CODES.success,
|
|
487
|
+
plan,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
validateTransferMode(runOptions, logger);
|
|
492
|
+
|
|
493
|
+
await assertScriptBundleVerified(runOptions.scriptType, {
|
|
494
|
+
allowUnverified: runOptions.allowUnverified,
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
const scriptTypePath = findOrCreateScriptTypeFolder(runOptions.scriptType);
|
|
498
|
+
const runScriptPath = path.join(
|
|
499
|
+
scriptTypePath,
|
|
500
|
+
SRC_FOLDER_NAME,
|
|
501
|
+
BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
|
|
502
|
+
);
|
|
503
|
+
if (!canReadFile(runScriptPath)) {
|
|
504
|
+
throw new DataGatheringError(
|
|
505
|
+
`Cannot run scripts for ${runOptions.scriptType}. Missing ${BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH} in downloaded bundle.`,
|
|
506
|
+
{
|
|
507
|
+
exitCode: DATA_GATHERING_EXIT_CODES.internalError,
|
|
508
|
+
type: "run.missing-entrypoint",
|
|
509
|
+
},
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const targetModules = resolveTargetModules(runOptions);
|
|
514
|
+
for (const moduleName of targetModules) {
|
|
515
|
+
logger.emit("module.started", {
|
|
516
|
+
module: moduleName,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const result = await runScriptFile(runScriptPath, buildRunnerArgs(runOptions), {
|
|
521
|
+
timeoutMs: getConfiguredTimeoutMs(runOptions),
|
|
522
|
+
onStdout: (chunk) => emitCapturedOutput(logger, DATA_GATHERING_OUTPUT_EVENT_TYPE.stdout, chunk),
|
|
523
|
+
onStderr: (chunk) => emitCapturedOutput(logger, DATA_GATHERING_OUTPUT_EVENT_TYPE.stderr, chunk),
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
for (const moduleName of targetModules) {
|
|
527
|
+
logger.emit("module.completed", {
|
|
528
|
+
module: moduleName,
|
|
529
|
+
...createModuleCompletionEvent(result),
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const completedPayload = createCompletedPayload(targetModules, result);
|
|
534
|
+
logger.emit("run.completed", completedPayload);
|
|
535
|
+
|
|
536
|
+
return {
|
|
537
|
+
exitCode: completedPayload.exitCode,
|
|
538
|
+
result,
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
async function listModules(logger = createEventLogger()) {
|
|
543
|
+
const modules = listInstalledModules();
|
|
544
|
+
logger.emit("list-modules.completed", {
|
|
545
|
+
modules,
|
|
546
|
+
});
|
|
547
|
+
return {
|
|
548
|
+
exitCode: DATA_GATHERING_EXIT_CODES.success,
|
|
549
|
+
modules,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
async function printDataGatheringHelp(ui = createDataGatheringUi()) {
|
|
554
|
+
ui.title("OpsCompass Data Gathering");
|
|
555
|
+
ui.blank();
|
|
556
|
+
ui.section("Actions");
|
|
557
|
+
ui.item("run", "Run downloaded data-gathering scripts or emit a dry-run plan.");
|
|
558
|
+
ui.item("list-modules", "List installed script modules visible to the CLI.");
|
|
559
|
+
ui.item("validate-install", "Check required data-gathering dependencies.");
|
|
560
|
+
ui.item("setup", "Run the data-gathering setup wizard.");
|
|
561
|
+
ui.item("send-dg", "Package, encrypt, and transfer DG artifacts. Plain-file batches reject duplicate basenames.");
|
|
562
|
+
ui.item("monitor", "Directory monitoring commands are not available yet.");
|
|
563
|
+
ui.item("compat", "Compatibility harness commands are not available yet.");
|
|
564
|
+
|
|
565
|
+
ui.blank();
|
|
566
|
+
ui.section("Global Parameters");
|
|
567
|
+
ui.item("--no-redact", "Disable event redaction (dev troubleshooting only).");
|
|
568
|
+
ui.item("--verbose", "Emit additional debug-oriented events.");
|
|
569
|
+
|
|
570
|
+
ui.blank();
|
|
571
|
+
ui.section("Run Parameters");
|
|
572
|
+
ui.item("--script-type", `${JSON.stringify(Object.values(ScriptType))} (default: base-scripts)`);
|
|
573
|
+
ui.item("--module <name>", "Limit output or plan to one or more modules.");
|
|
574
|
+
ui.item("--config <path>", "Config file path used for dry-run and execution events.");
|
|
575
|
+
ui.item("--dry-run", "Emit a plan without executing collectors.");
|
|
576
|
+
ui.item("--transfer auto|always|never", "Transfer mode surface for Studio.");
|
|
577
|
+
ui.item("--timeout-ms <ms>", "Per-run timeout.");
|
|
578
|
+
ui.item("--no-timeout", "Disable runner timeout.");
|
|
579
|
+
ui.item("--fail-fast", "Stop after the first failure.");
|
|
580
|
+
ui.item("--parallel <n>", "Surface reserved for future parallel execution.");
|
|
581
|
+
ui.item("--allow-unverified", "Break-glass: allow execution of unverified bundles.");
|
|
582
|
+
|
|
583
|
+
ui.blank();
|
|
584
|
+
ui.section("Examples");
|
|
585
|
+
ui.command(
|
|
586
|
+
`${cliCommand} data-gathering setup`,
|
|
587
|
+
"Interactive setup for an operator at the terminal.",
|
|
588
|
+
);
|
|
589
|
+
ui.command(
|
|
590
|
+
`${cliCommand} data-gathering setup --non-interactive --company <slug> --account <token> --monitoring-configuration-id <id>`,
|
|
591
|
+
"Studio-safe or automation-friendly setup.",
|
|
592
|
+
);
|
|
593
|
+
ui.command(
|
|
594
|
+
`${cliCommand} data-gathering run --dry-run --config /path/to/dgConfig.json --module msql-license`,
|
|
595
|
+
"Preview the execution plan without running collectors.",
|
|
596
|
+
);
|
|
597
|
+
ui.blank();
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function getCompletionEventType(action) {
|
|
601
|
+
return action?.toLowerCase() === "setup" ? "setup.completed" : "run.completed";
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
async function runDataGatheringAction(action, args) {
|
|
605
|
+
const { options, remainingArgs } = parseDataGatheringGlobalArgs(args);
|
|
606
|
+
const logger = createEventLogger({
|
|
607
|
+
redact: options.redact,
|
|
608
|
+
});
|
|
609
|
+
const ui = createDataGatheringUi();
|
|
610
|
+
const completionEventType = getCompletionEventType(action);
|
|
611
|
+
|
|
612
|
+
try {
|
|
613
|
+
switch (action?.toLowerCase() ?? "") {
|
|
614
|
+
case "run":
|
|
615
|
+
return await runDataGathering(remainingArgs, logger);
|
|
616
|
+
case "list-modules":
|
|
617
|
+
return await listModules(logger);
|
|
618
|
+
case "validate-install":
|
|
619
|
+
return await runValidateInstallCommand(remainingArgs, logger, { ui });
|
|
620
|
+
case "setup":
|
|
621
|
+
return await runSetupWizard(remainingArgs, logger);
|
|
622
|
+
case "send-dg":
|
|
623
|
+
{
|
|
624
|
+
const { sendDgAction } = await import("../lib/dataGathering/sendDg.js");
|
|
625
|
+
return await sendDgAction(remainingArgs, logger);
|
|
626
|
+
}
|
|
627
|
+
case "compat":
|
|
628
|
+
case "monitor":
|
|
629
|
+
throw new DataGatheringError(
|
|
630
|
+
`${action} is part of the command surface but is not implemented yet. Coming in a future update.`,
|
|
631
|
+
{
|
|
632
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
633
|
+
type: "command.not-implemented",
|
|
634
|
+
data: { action },
|
|
635
|
+
},
|
|
636
|
+
);
|
|
637
|
+
case "help":
|
|
638
|
+
case "":
|
|
639
|
+
return printDataGatheringHelp(ui);
|
|
640
|
+
default:
|
|
641
|
+
throw new DataGatheringError(`Unknown command: ${action}`, {
|
|
642
|
+
exitCode: DATA_GATHERING_EXIT_CODES.invalidInput,
|
|
643
|
+
type: "command.unknown",
|
|
644
|
+
data: { action },
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
} catch (error) {
|
|
648
|
+
if (error instanceof DataGatheringError) {
|
|
649
|
+
if (!error.humanOutputHandled) {
|
|
650
|
+
ui.error(error.message);
|
|
651
|
+
}
|
|
652
|
+
logger.emit(error.type, {
|
|
653
|
+
message: error.message,
|
|
654
|
+
...error.data,
|
|
655
|
+
});
|
|
656
|
+
logger.emit(completionEventType, {
|
|
657
|
+
status: "failed",
|
|
658
|
+
exitCode: error.exitCode,
|
|
659
|
+
targetsTotal: 0,
|
|
660
|
+
targetsFailed: 0,
|
|
661
|
+
});
|
|
662
|
+
process.exitCode = error.exitCode;
|
|
663
|
+
return {
|
|
664
|
+
exitCode: error.exitCode,
|
|
665
|
+
error,
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
if (error instanceof Error) {
|
|
670
|
+
ui.error(error.message);
|
|
671
|
+
logger.emit("run.failed", {
|
|
672
|
+
message: error.message,
|
|
673
|
+
});
|
|
674
|
+
logger.emit(completionEventType, {
|
|
675
|
+
status: "failed",
|
|
676
|
+
exitCode: DATA_GATHERING_EXIT_CODES.internalError,
|
|
677
|
+
targetsTotal: 0,
|
|
678
|
+
targetsFailed: 0,
|
|
679
|
+
});
|
|
680
|
+
process.exitCode = DATA_GATHERING_EXIT_CODES.internalError;
|
|
681
|
+
return {
|
|
682
|
+
exitCode: DATA_GATHERING_EXIT_CODES.internalError,
|
|
683
|
+
error,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
ui.error(`${error}`);
|
|
688
|
+
logger.emit("run.failed", {
|
|
689
|
+
message: `${error}`,
|
|
690
|
+
});
|
|
691
|
+
logger.emit("run.completed", {
|
|
692
|
+
status: "failed",
|
|
693
|
+
exitCode: DATA_GATHERING_EXIT_CODES.internalError,
|
|
694
|
+
targetsTotal: 0,
|
|
695
|
+
targetsFailed: 0,
|
|
696
|
+
});
|
|
697
|
+
process.exitCode = DATA_GATHERING_EXIT_CODES.internalError;
|
|
698
|
+
throw error;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const dataGatheringModule = (action, ...args) => runDataGatheringAction(action, args);
|
|
703
|
+
|
|
704
|
+
dataGatheringModule.requiresLogin = false;
|
|
705
|
+
dataGatheringModule.description =
|
|
706
|
+
"Execution/orchestration surface for Studio-first data gathering flows.";
|
|
707
|
+
|
|
708
|
+
export {
|
|
709
|
+
DATA_GATHERING_OUTPUT_EVENT_TYPE,
|
|
710
|
+
DEFAULT_RUN_TIMEOUT_MS,
|
|
711
|
+
buildRunnerArgs,
|
|
712
|
+
createCompletedPayload,
|
|
713
|
+
createDryRunPlan,
|
|
714
|
+
createModuleCompletionEvent,
|
|
715
|
+
createRunStartedPayload,
|
|
716
|
+
emitCapturedOutput,
|
|
717
|
+
getConfiguredTimeoutMs,
|
|
718
|
+
isTransferAllowed,
|
|
719
|
+
listModules,
|
|
720
|
+
parseDataGatheringGlobalArgs,
|
|
721
|
+
parsePositiveInteger,
|
|
722
|
+
parseRunArgs,
|
|
723
|
+
printDataGatheringHelp,
|
|
724
|
+
readRequiredFlagValue,
|
|
725
|
+
resolveTargetModules,
|
|
726
|
+
runDataGathering,
|
|
727
|
+
runDataGatheringAction,
|
|
728
|
+
runScriptFile,
|
|
729
|
+
getCompletionEventType,
|
|
730
|
+
validateTransferMode,
|
|
731
|
+
};
|
|
732
|
+
export default dataGatheringModule;
|