@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,146 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const DATA_GATHERING_SCHEMA_VERSION = 1;
|
|
4
|
+
|
|
5
|
+
const DATA_GATHERING_EXIT_CODES = Object.freeze({
|
|
6
|
+
success: 0,
|
|
7
|
+
partialFailure: 2,
|
|
8
|
+
invalidInput: 3,
|
|
9
|
+
missingDependency: 4,
|
|
10
|
+
internalError: 5,
|
|
11
|
+
interrupted: 130,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const SECRET_KEYS = new Set([
|
|
15
|
+
"password",
|
|
16
|
+
"user",
|
|
17
|
+
"username",
|
|
18
|
+
"connect",
|
|
19
|
+
"token",
|
|
20
|
+
"secret",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
function createTokenPatterns() {
|
|
24
|
+
return [
|
|
25
|
+
/oc\$hash:[^\s"',]+/gi,
|
|
26
|
+
/oc\$mask-[^\s"',]+/gi,
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createCliSecretPatterns() {
|
|
31
|
+
return [
|
|
32
|
+
/(--(?:password|user(?:name)?|connect|token|secret)\s+)([^\s]+)/gi,
|
|
33
|
+
/((?:password|user(?:name)?|connect|token|secret)=)([^\s&]+)/gi,
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class DataGatheringError extends Error {
|
|
38
|
+
constructor(message, options = {}) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = "DataGatheringError";
|
|
41
|
+
this.exitCode = options.exitCode ?? DATA_GATHERING_EXIT_CODES.internalError;
|
|
42
|
+
this.type = options.type ?? "command.failed";
|
|
43
|
+
this.data = options.data ?? {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createRunId(prefix = "dg") {
|
|
48
|
+
const now = new Date();
|
|
49
|
+
const stamp = [
|
|
50
|
+
now.getUTCFullYear(),
|
|
51
|
+
`${now.getUTCMonth() + 1}`.padStart(2, "0"),
|
|
52
|
+
`${now.getUTCDate()}`.padStart(2, "0"),
|
|
53
|
+
`${now.getUTCHours()}`.padStart(2, "0"),
|
|
54
|
+
`${now.getUTCMinutes()}`.padStart(2, "0"),
|
|
55
|
+
`${now.getUTCSeconds()}`.padStart(2, "0"),
|
|
56
|
+
].join("");
|
|
57
|
+
|
|
58
|
+
return `${prefix}_${stamp}_${crypto.randomBytes(4).toString("hex")}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function redactString(value) {
|
|
62
|
+
let redacted = value;
|
|
63
|
+
|
|
64
|
+
for (const pattern of createTokenPatterns()) {
|
|
65
|
+
redacted = redacted.replace(pattern, "[REDACTED]");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (const pattern of createCliSecretPatterns()) {
|
|
69
|
+
redacted = redacted.replace(pattern, "$1[REDACTED]");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return redacted;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function redactValue(value, key = "") {
|
|
76
|
+
if (SECRET_KEYS.has(String(key).toLowerCase())) {
|
|
77
|
+
return "[REDACTED]";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (typeof value === "string") {
|
|
81
|
+
return redactString(value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
return value.map((item) => redactValue(item, key));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (value && typeof value === "object") {
|
|
89
|
+
return Object.fromEntries(
|
|
90
|
+
Object.entries(value).map(([childKey, childValue]) => [
|
|
91
|
+
childKey,
|
|
92
|
+
redactValue(childValue, childKey),
|
|
93
|
+
]),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function normalizeDataGatheringExitCode(code) {
|
|
101
|
+
if (code === 0) {
|
|
102
|
+
return DATA_GATHERING_EXIT_CODES.success;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (Object.values(DATA_GATHERING_EXIT_CODES).includes(code)) {
|
|
106
|
+
return code;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return DATA_GATHERING_EXIT_CODES.internalError;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function createEventLogger({
|
|
113
|
+
runId = createRunId(),
|
|
114
|
+
redact = true,
|
|
115
|
+
stdout = (line) => console.log(line),
|
|
116
|
+
} = {}) {
|
|
117
|
+
function emit(type, data = {}) {
|
|
118
|
+
const payload = {
|
|
119
|
+
schemaVersion: DATA_GATHERING_SCHEMA_VERSION,
|
|
120
|
+
runId,
|
|
121
|
+
ts: new Date().toISOString(),
|
|
122
|
+
type,
|
|
123
|
+
data: redact ? redactValue(data) : data,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
stdout(JSON.stringify(payload));
|
|
127
|
+
return payload;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
runId,
|
|
132
|
+
redact,
|
|
133
|
+
emit,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
DATA_GATHERING_SCHEMA_VERSION,
|
|
139
|
+
DATA_GATHERING_EXIT_CODES,
|
|
140
|
+
DataGatheringError,
|
|
141
|
+
createEventLogger,
|
|
142
|
+
createRunId,
|
|
143
|
+
normalizeDataGatheringExitCode,
|
|
144
|
+
redactString,
|
|
145
|
+
redactValue,
|
|
146
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { opscompassHome } from "../../environment/current.js";
|
|
5
|
+
|
|
6
|
+
const LM_MODULE_FILE_NAME = "lm_module.json";
|
|
7
|
+
|
|
8
|
+
function getScriptsRoot() {
|
|
9
|
+
return path.join(opscompassHome, "scripts");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function listInstalledModules() {
|
|
13
|
+
const scriptsRoot = getScriptsRoot();
|
|
14
|
+
if (!fs.existsSync(scriptsRoot)) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return fs
|
|
19
|
+
.readdirSync(scriptsRoot, { withFileTypes: true })
|
|
20
|
+
.filter((entry) => entry.isDirectory())
|
|
21
|
+
.map((entry) => {
|
|
22
|
+
const metadataPath = path.join(scriptsRoot, entry.name, "metadata.json");
|
|
23
|
+
const lmModulePath = path.join(
|
|
24
|
+
scriptsRoot,
|
|
25
|
+
entry.name,
|
|
26
|
+
"src",
|
|
27
|
+
LM_MODULE_FILE_NAME,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
let metadata = undefined;
|
|
31
|
+
let lmModule = undefined;
|
|
32
|
+
try {
|
|
33
|
+
if (fs.existsSync(metadataPath)) {
|
|
34
|
+
metadata = JSON.parse(fs.readFileSync(metadataPath, "utf8"));
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
metadata = undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
if (fs.existsSync(lmModulePath)) {
|
|
42
|
+
lmModule = JSON.parse(fs.readFileSync(lmModulePath, "utf8"));
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
lmModule = undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
module: entry.name,
|
|
50
|
+
version: metadata?.version,
|
|
51
|
+
verification: metadata?.verification,
|
|
52
|
+
lmModulePath: fs.existsSync(lmModulePath) ? lmModulePath : undefined,
|
|
53
|
+
actions:
|
|
54
|
+
lmModule?.actions ||
|
|
55
|
+
lmModule?.collectorActions ||
|
|
56
|
+
lmModule?.moduleActions ||
|
|
57
|
+
[],
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { LM_MODULE_FILE_NAME, getScriptsRoot, listInstalledModules };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { opscompassHome } from "../../environment/current.js";
|
|
5
|
+
|
|
6
|
+
const OLM_DATA_PARMS_PATH = path.join(opscompassHome, "olm.dataParms");
|
|
7
|
+
const OLM_DATA_PARMS_MODE = 0o600;
|
|
8
|
+
const OLM_DATA_PARMS_HEADER = [
|
|
9
|
+
"# Opscompass data gathering parameter file",
|
|
10
|
+
"#",
|
|
11
|
+
"# Variables set here will be picked up by the environment",
|
|
12
|
+
"# Required variables will be prompted for as needed",
|
|
13
|
+
"# In the event a variable is also defined at the top level of a config file,",
|
|
14
|
+
"# the value in the config file will take precedence - UNLESS the name starts",
|
|
15
|
+
"# with OC_, in which case the value here will be taken as a global override",
|
|
16
|
+
"#",
|
|
17
|
+
"# Determine if we are supposed to auto-update stuff. These should get",
|
|
18
|
+
"# set by common.env according to customer preferences per config, but",
|
|
19
|
+
"# can also be overridden globally here",
|
|
20
|
+
"# OC_AUTOUPDATE_configs='true'",
|
|
21
|
+
"# OC_AUTOUPDATE_scripts='false'",
|
|
22
|
+
"#",
|
|
23
|
+
"# USE_FILEDROP='NO'",
|
|
24
|
+
"#",
|
|
25
|
+
"# Unknown keys are preserved when this file is updated.",
|
|
26
|
+
"#",
|
|
27
|
+
].join("\n");
|
|
28
|
+
|
|
29
|
+
function parseOlmValue(rawValue) {
|
|
30
|
+
const trimmed = rawValue.trim();
|
|
31
|
+
if (
|
|
32
|
+
(trimmed.startsWith("'") && trimmed.endsWith("'")) ||
|
|
33
|
+
(trimmed.startsWith('"') && trimmed.endsWith('"'))
|
|
34
|
+
) {
|
|
35
|
+
return trimmed.slice(1, -1).replace(/'\\''/g, "'");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return trimmed;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function quoteOlmValue(value) {
|
|
42
|
+
const normalized = `${value ?? ""}`;
|
|
43
|
+
return `'${normalized.replace(/'/g, "'\\''")}'`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function ensureOlmDataParmsFile() {
|
|
47
|
+
fs.mkdirSync(path.dirname(OLM_DATA_PARMS_PATH), { recursive: true, mode: 0o700 });
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
fs.writeFileSync(OLM_DATA_PARMS_PATH, `${OLM_DATA_PARMS_HEADER}\n`, {
|
|
51
|
+
mode: OLM_DATA_PARMS_MODE,
|
|
52
|
+
flag: "wx",
|
|
53
|
+
});
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (error.code !== "EEXIST") {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!fs.existsSync(OLM_DATA_PARMS_PATH)) {
|
|
61
|
+
fs.writeFileSync(OLM_DATA_PARMS_PATH, `${OLM_DATA_PARMS_HEADER}\n`, {
|
|
62
|
+
mode: OLM_DATA_PARMS_MODE,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fs.chmodSync(OLM_DATA_PARMS_PATH, OLM_DATA_PARMS_MODE);
|
|
67
|
+
return OLM_DATA_PARMS_PATH;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function readOlmDataParms() {
|
|
71
|
+
const filePath = ensureOlmDataParmsFile();
|
|
72
|
+
const source = fs.readFileSync(filePath, "utf8");
|
|
73
|
+
const lines = source === "" ? [] : source.split(/\r?\n/);
|
|
74
|
+
const values = {};
|
|
75
|
+
|
|
76
|
+
for (const line of lines) {
|
|
77
|
+
const match = line.match(/^\s*([A-Za-z0-9_]+)\s*=\s*(.*)$/);
|
|
78
|
+
if (!match) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
values[match[1]] = parseOlmValue(match[2]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
filePath,
|
|
87
|
+
lines,
|
|
88
|
+
values,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function writeOlmDataParms(updates) {
|
|
93
|
+
const state = readOlmDataParms();
|
|
94
|
+
const remainingUpdates = new Map(Object.entries(updates));
|
|
95
|
+
const nextLines = state.lines.map((line) => {
|
|
96
|
+
const match = line.match(/^\s*([A-Za-z0-9_]+)\s*=\s*(.*)$/);
|
|
97
|
+
if (!match) {
|
|
98
|
+
return line;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const key = match[1];
|
|
102
|
+
if (!remainingUpdates.has(key)) {
|
|
103
|
+
return line;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const value = remainingUpdates.get(key);
|
|
107
|
+
remainingUpdates.delete(key);
|
|
108
|
+
return `${key}=${quoteOlmValue(value)}`;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (remainingUpdates.size > 0) {
|
|
112
|
+
if (nextLines.length > 0 && nextLines[nextLines.length - 1] !== "") {
|
|
113
|
+
nextLines.push("");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const [key, value] of remainingUpdates.entries()) {
|
|
117
|
+
nextLines.push(`${key}=${quoteOlmValue(value)}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const nextSource = `${nextLines.join("\n").replace(/\n*$/, "\n")}`;
|
|
122
|
+
fs.writeFileSync(state.filePath, nextSource, { mode: OLM_DATA_PARMS_MODE });
|
|
123
|
+
fs.chmodSync(state.filePath, OLM_DATA_PARMS_MODE);
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
filePath: state.filePath,
|
|
127
|
+
values: {
|
|
128
|
+
...state.values,
|
|
129
|
+
...updates,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
OLM_DATA_PARMS_MODE,
|
|
136
|
+
OLM_DATA_PARMS_PATH,
|
|
137
|
+
ensureOlmDataParmsFile,
|
|
138
|
+
readOlmDataParms,
|
|
139
|
+
writeOlmDataParms,
|
|
140
|
+
};
|