@opscompass/opscompass-cli 1.3.1 → 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 +125 -42
- 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
package/modules/defaults.js
CHANGED
|
@@ -4,6 +4,7 @@ import { opscompassHome } from "../environment/current.js";
|
|
|
4
4
|
import { maskTypes } from "../lib/maskValues.js";
|
|
5
5
|
|
|
6
6
|
const defaultsPath = path.join(opscompassHome, "defaults.json");
|
|
7
|
+
const defaultsMode = 0o600;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Read the default parameters from the defaults.json file
|
|
@@ -33,51 +34,93 @@ async function readDefaults() {
|
|
|
33
34
|
return defaultParams;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
function applyDefaultsArgs(defaults, args) {
|
|
38
|
+
const nextDefaults = { ...defaults };
|
|
38
39
|
|
|
39
40
|
for (var i = 0; i < args.length - 1; i++) {
|
|
40
41
|
switch (args[i]?.toLowerCase()) {
|
|
41
42
|
case "--company":
|
|
42
|
-
|
|
43
|
+
nextDefaults.company = args[++i];
|
|
43
44
|
break;
|
|
44
45
|
case "--account":
|
|
45
|
-
|
|
46
|
+
nextDefaults.account = args[++i];
|
|
46
47
|
break;
|
|
47
48
|
case "--monitoring-configuration-id":
|
|
48
49
|
case "--monitoringConfigurationId":
|
|
49
|
-
|
|
50
|
+
nextDefaults.monitoringConfiguration = args[++i];
|
|
50
51
|
break;
|
|
51
52
|
case "--mask-values":
|
|
52
53
|
case "--maskvalues":
|
|
53
54
|
for (let input of args[++i].split(",")) {
|
|
54
|
-
const
|
|
55
|
+
const value = input.trim();
|
|
56
|
+
const separatorIndex = value.indexOf("=");
|
|
57
|
+
if (separatorIndex <= 0) {
|
|
58
|
+
console.error(`Invalid --mask-values argument: ${input}`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const property = value.slice(0, separatorIndex).trim();
|
|
63
|
+
const maskType = value.slice(separatorIndex + 1).trim();
|
|
64
|
+
|
|
65
|
+
if (!property) {
|
|
66
|
+
console.error(`Invalid --mask-values property: ${input}`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const clearMaskRule = maskType.toLowerCase() === "none";
|
|
71
|
+
|
|
55
72
|
// If maskType is not valid then return with error
|
|
56
|
-
if (!Object.values(maskTypes).includes(maskType)) {
|
|
73
|
+
if (!clearMaskRule && !Object.values(maskTypes).includes(maskType)) {
|
|
57
74
|
console.error(
|
|
58
75
|
`Invalid maskType ${maskType} for property ${property}`,
|
|
59
76
|
);
|
|
60
77
|
return;
|
|
61
78
|
}
|
|
62
79
|
// Delete any existing maskValues for the property
|
|
63
|
-
if (!
|
|
64
|
-
|
|
80
|
+
if (!nextDefaults.maskValues) {
|
|
81
|
+
nextDefaults.maskValues = [];
|
|
65
82
|
} else {
|
|
66
|
-
|
|
83
|
+
nextDefaults.maskValues = nextDefaults.maskValues.filter(
|
|
67
84
|
(maskValue) => maskValue.property !== property,
|
|
68
85
|
);
|
|
69
86
|
}
|
|
70
87
|
|
|
71
|
-
// If
|
|
72
|
-
if (
|
|
73
|
-
|
|
88
|
+
// If maskType is not "none", then set it
|
|
89
|
+
if (!clearMaskRule) {
|
|
90
|
+
nextDefaults.maskValues.push({ property, maskType });
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
break;
|
|
77
94
|
}
|
|
78
95
|
}
|
|
96
|
+
|
|
97
|
+
return nextDefaults;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function writeDefaultsFile(defaults) {
|
|
79
101
|
const data = JSON.stringify(defaults, null, 2);
|
|
80
|
-
fs.
|
|
102
|
+
fs.mkdirSync(path.dirname(defaultsPath), { recursive: true, mode: 0o700 });
|
|
103
|
+
fs.writeFileSync(defaultsPath, data + "\n", { mode: defaultsMode });
|
|
104
|
+
fs.chmodSync(defaultsPath, defaultsMode);
|
|
105
|
+
return defaults;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function updateDefaults(defaultValues) {
|
|
109
|
+
const defaults = await readDefaults();
|
|
110
|
+
return writeDefaultsFile({
|
|
111
|
+
...defaults,
|
|
112
|
+
...defaultValues,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function writeDefaults(args) {
|
|
117
|
+
const defaults = await readDefaults();
|
|
118
|
+
const nextDefaults = applyDefaultsArgs(defaults, args);
|
|
119
|
+
if (!nextDefaults) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
await writeDefaultsFile(nextDefaults);
|
|
81
124
|
|
|
82
125
|
console.log("Your default configuration is:");
|
|
83
126
|
readDefaults().then((defaultParams) => {
|
|
@@ -104,11 +147,13 @@ function printHelp() {
|
|
|
104
147
|
"--mask-values property=hash[,...]",
|
|
105
148
|
`Mask values sent between OpsCompass and ${global.company}`,
|
|
106
149
|
);
|
|
150
|
+
console.log("Use property=none to remove an existing mask rule.");
|
|
107
151
|
console.log(
|
|
108
152
|
"\ne.g. opscompass defaults set-defaults --company 'opscompass' --account '231' --monitoring-configuration-id '34232'",
|
|
109
153
|
);
|
|
110
154
|
console.log();
|
|
111
155
|
console.log("e.g. opscompass defaults set-defaults --mask-values server=md5");
|
|
156
|
+
console.log("e.g. opscompass defaults set-defaults --mask-values server=none");
|
|
112
157
|
console.log();
|
|
113
158
|
}
|
|
114
159
|
|
|
@@ -133,5 +178,13 @@ defaultsModule.requiresLogin = false;
|
|
|
133
178
|
defaultsModule.description =
|
|
134
179
|
"View and set default parameters for OpsCompass CLI.";
|
|
135
180
|
|
|
136
|
-
export {
|
|
181
|
+
export {
|
|
182
|
+
applyDefaultsArgs,
|
|
183
|
+
defaultsMode,
|
|
184
|
+
defaultsPath,
|
|
185
|
+
readDefaults,
|
|
186
|
+
updateDefaults,
|
|
187
|
+
writeDefaults,
|
|
188
|
+
writeDefaultsFile,
|
|
189
|
+
};
|
|
137
190
|
export default defaultsModule;
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "fs";
|
|
2
|
+
import { basename } from "path";
|
|
3
|
+
|
|
4
|
+
import { getOpsCompassClient } from "../../opscompass.js";
|
|
5
|
+
import { utilsModule as utils } from "../../lib/utils.js";
|
|
6
|
+
import maskValues from "../../lib/maskValues.js";
|
|
7
|
+
|
|
8
|
+
function printImportMonitoringConfigurationHelp(company = global.company) {
|
|
9
|
+
console.log(
|
|
10
|
+
"import-monitoring-configuration",
|
|
11
|
+
"Imports resources/settings from a bulk JSON file (bulk_load.js parity).",
|
|
12
|
+
);
|
|
13
|
+
console.log("Parameters:");
|
|
14
|
+
console.log("<file.json> [required]");
|
|
15
|
+
console.log(`--company [company_slug] (default: ${company})`);
|
|
16
|
+
console.log("--id (optional) import into existing monitoring configuration id");
|
|
17
|
+
console.log("--name (optional) name used only when creating a new configuration");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parseOracleConnect(connectValue) {
|
|
21
|
+
const match = String(connectValue).match(/^([^/@]+)\/([^@]+)@(.+)$/);
|
|
22
|
+
if (!match) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
user: match[1],
|
|
28
|
+
password: match[2],
|
|
29
|
+
server: match[3],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function hasAnyPatches(object) {
|
|
34
|
+
return Object.keys(object).some((key) => object[key] !== undefined);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function importMonitoringConfiguration(
|
|
38
|
+
args,
|
|
39
|
+
{ materializeMonitoringConfiguration } = {},
|
|
40
|
+
) {
|
|
41
|
+
let filePath = undefined;
|
|
42
|
+
let cfgName = undefined;
|
|
43
|
+
let configId = undefined;
|
|
44
|
+
|
|
45
|
+
for (let i = 0; i < args.length; i++) {
|
|
46
|
+
const arg = args[i];
|
|
47
|
+
switch ((arg || "").toLowerCase()) {
|
|
48
|
+
case "--name":
|
|
49
|
+
case "--configurationname":
|
|
50
|
+
case "--configuration-name":
|
|
51
|
+
if (i + 1 >= args.length || (args[i + 1] || "").startsWith("--")) {
|
|
52
|
+
console.error("Missing value for --name / --configuration-name");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
cfgName = args[++i];
|
|
56
|
+
break;
|
|
57
|
+
case "--id":
|
|
58
|
+
if (i + 1 >= args.length || (args[i + 1] || "").startsWith("--")) {
|
|
59
|
+
console.error("Missing value for --id");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
configId = args[++i];
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
if (!arg.startsWith("--")) {
|
|
66
|
+
filePath = arg;
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!filePath) {
|
|
73
|
+
console.error("No input file specified for import-monitoring-configuration");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!existsSync(filePath)) {
|
|
78
|
+
console.error("File not found:", filePath);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let bulk;
|
|
83
|
+
try {
|
|
84
|
+
bulk = JSON.parse(readFileSync(filePath, "utf8"));
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error("Failed to read/parse input file:", err.message || err);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
utils.decryptValues(bulk);
|
|
91
|
+
await maskValues.maskObjValues(bulk);
|
|
92
|
+
|
|
93
|
+
const client = await getOpsCompassClient();
|
|
94
|
+
|
|
95
|
+
let cfgId = bulk?.configurationId || configId;
|
|
96
|
+
if (!cfgId) {
|
|
97
|
+
const nameToUse = cfgName || basename(filePath, ".json");
|
|
98
|
+
try {
|
|
99
|
+
const newConfig = await client.licenseManager.createMonitoringConfiguration(
|
|
100
|
+
global.company,
|
|
101
|
+
nameToUse,
|
|
102
|
+
);
|
|
103
|
+
cfgId = newConfig?.id;
|
|
104
|
+
if (!cfgId) {
|
|
105
|
+
console.error("Error creating new configuration");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
console.log("New configuration created:", cfgId);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.error("Error creating new monitoring configuration:", err.message || err);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
console.log("Using configuration ID:", cfgId);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const errors = [];
|
|
118
|
+
const updateCfg = {
|
|
119
|
+
autoUpdateConfigurations: bulk?.OC_AUTOUPDATE_configs,
|
|
120
|
+
autoUpdateScripts: bulk?.OC_AUTOUPDATE_scripts,
|
|
121
|
+
dataFileRetainDays: bulk?.data_files?.retain_days,
|
|
122
|
+
dataFileRetainTextDays: bulk?.data_files?.retain_txt_days,
|
|
123
|
+
dataFileTag: bulk?.data_files?.file_tag,
|
|
124
|
+
forceFileEncryption: bulk?.data_files?.force_encryption,
|
|
125
|
+
mailFrom: bulk?.data_files?.mail_from,
|
|
126
|
+
emailTo: bulk?.data_files?.email_to,
|
|
127
|
+
notificationEmailTo: bulk?.notificationEmailTo,
|
|
128
|
+
logFileRetainDays: bulk?.log_files?.retain_days,
|
|
129
|
+
logFileTag: bulk?.log_files?.file_tag,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
if (hasAnyPatches(updateCfg)) {
|
|
133
|
+
try {
|
|
134
|
+
await client.licenseManager.updateMonitoringConfiguration(cfgId, updateCfg);
|
|
135
|
+
} catch (err) {
|
|
136
|
+
const message = err.message || err;
|
|
137
|
+
console.error(`Error updating configuration ${cfgId}:`, message);
|
|
138
|
+
errors.push({
|
|
139
|
+
step: "updateMonitoringConfiguration",
|
|
140
|
+
id: cfgId,
|
|
141
|
+
message: String(message),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
console.log("No optional settings to update");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const bulkCreate = bulk?.bulk_create;
|
|
149
|
+
if (bulkCreate) {
|
|
150
|
+
if (bulkCreate?.oracle_default_credentials) {
|
|
151
|
+
console.log("Setting Oracle default credential...");
|
|
152
|
+
try {
|
|
153
|
+
const response = await client.licenseManager.getOracleDefaultCredential(cfgId);
|
|
154
|
+
if (response) {
|
|
155
|
+
await client.licenseManager.updateOracleSharedCredential(response.id, {
|
|
156
|
+
user: bulkCreate.oracle_default_credentials?.user,
|
|
157
|
+
password: bulkCreate.oracle_default_credentials?.password,
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
await client.licenseManager.createOracleSharedCredential(cfgId, {
|
|
161
|
+
user: bulkCreate.oracle_default_credentials?.user,
|
|
162
|
+
password: bulkCreate.oracle_default_credentials?.password,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
} catch (err) {
|
|
166
|
+
const message = err.message || err;
|
|
167
|
+
console.error("Error updating Oracle shared credential:", message);
|
|
168
|
+
errors.push({ step: "oracle_default_credentials", message: String(message) });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (bulkCreate?.microsoft_default_credentials) {
|
|
173
|
+
console.log("Setting Microsoft default credential...");
|
|
174
|
+
try {
|
|
175
|
+
const response = await client.licenseManager.mssql.getMssqlDefaultCredential(cfgId);
|
|
176
|
+
if (response) {
|
|
177
|
+
await client.licenseManager.mssql.updateMssqlSharedCredential(response.id, {
|
|
178
|
+
user: bulkCreate.microsoft_default_credentials?.user,
|
|
179
|
+
password: bulkCreate.microsoft_default_credentials?.password,
|
|
180
|
+
directory_auth: bulkCreate.microsoft_default_credentials?.directory_auth,
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
await client.licenseManager.mssql.createMssqlSharedCredential(cfgId, {
|
|
184
|
+
user: bulkCreate.microsoft_default_credentials?.user,
|
|
185
|
+
password: bulkCreate.microsoft_default_credentials?.password,
|
|
186
|
+
directory_auth: bulkCreate.microsoft_default_credentials?.directory_auth,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
} catch (err) {
|
|
190
|
+
const message = err.message || err;
|
|
191
|
+
console.error("Error updating SQL Server shared credential:", message);
|
|
192
|
+
errors.push({ step: "microsoft_default_credentials", message: String(message) });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (Array.isArray(bulk?.oracle_dbs)) {
|
|
198
|
+
for (const oraCfg of bulk.oracle_dbs) {
|
|
199
|
+
console.log("Adding oracle config:", oraCfg.name || "(unnamed)");
|
|
200
|
+
try {
|
|
201
|
+
let cfgObj = {
|
|
202
|
+
actions: oraCfg?.actions || [],
|
|
203
|
+
server: oraCfg?.server,
|
|
204
|
+
user: oraCfg?.user,
|
|
205
|
+
password: oraCfg?.password,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
if (oraCfg?.connect) {
|
|
209
|
+
const parsedConnect = parseOracleConnect(oraCfg.connect);
|
|
210
|
+
if (!parsedConnect) {
|
|
211
|
+
const message =
|
|
212
|
+
`Malformed oracle connect string for ${oraCfg.name || oraCfg.config_id || "(unnamed)"}: ` +
|
|
213
|
+
`${oraCfg.connect}`;
|
|
214
|
+
console.error(message);
|
|
215
|
+
errors.push({
|
|
216
|
+
step: "createOracleDatabase",
|
|
217
|
+
name: oraCfg.name,
|
|
218
|
+
config_id: oraCfg.config_id,
|
|
219
|
+
message,
|
|
220
|
+
});
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
cfgObj = {
|
|
225
|
+
server: oraCfg?.server || parsedConnect.server,
|
|
226
|
+
user: oraCfg?.user || parsedConnect.user,
|
|
227
|
+
password: oraCfg?.password || parsedConnect.password,
|
|
228
|
+
actions: ["dblicensing"],
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
Object.keys(cfgObj).forEach((key) => {
|
|
233
|
+
if (cfgObj[key] === null || cfgObj[key] === undefined) {
|
|
234
|
+
delete cfgObj[key];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
await client.licenseManager.createOracleDatabaseConfiguration(
|
|
238
|
+
cfgId,
|
|
239
|
+
oraCfg.name,
|
|
240
|
+
cfgObj,
|
|
241
|
+
);
|
|
242
|
+
} catch (err) {
|
|
243
|
+
const message = err.message || err;
|
|
244
|
+
if (
|
|
245
|
+
err.response?.status === 500 &&
|
|
246
|
+
typeof oraCfg.config_id === "number" &&
|
|
247
|
+
oraCfg.config_id > 0
|
|
248
|
+
) {
|
|
249
|
+
console.error("Failed to create oracle config (may already exist):", message);
|
|
250
|
+
} else {
|
|
251
|
+
console.error("Error creating oracle config:", message);
|
|
252
|
+
}
|
|
253
|
+
errors.push({
|
|
254
|
+
step: "createOracleDatabase",
|
|
255
|
+
name: oraCfg.name,
|
|
256
|
+
config_id: oraCfg.config_id,
|
|
257
|
+
message: String(message),
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (Array.isArray(bulk?.microsoft_dbs)) {
|
|
264
|
+
for (const sqlCfg of bulk.microsoft_dbs) {
|
|
265
|
+
console.log("Adding microsoft config:", sqlCfg.name || "(unnamed)");
|
|
266
|
+
try {
|
|
267
|
+
await client.licenseManager.mssql.createMssqlConfiguration(cfgId, sqlCfg.name, {
|
|
268
|
+
actions: sqlCfg?.actions || [],
|
|
269
|
+
server: sqlCfg?.server,
|
|
270
|
+
user: sqlCfg?.user,
|
|
271
|
+
password: sqlCfg?.password,
|
|
272
|
+
});
|
|
273
|
+
} catch (err) {
|
|
274
|
+
const message = err.message || err;
|
|
275
|
+
console.error("Error creating microsoft config:", message);
|
|
276
|
+
errors.push({
|
|
277
|
+
step: "createMssqlConfiguration",
|
|
278
|
+
name: sqlCfg.name,
|
|
279
|
+
message: String(message),
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (Array.isArray(bulk?.nxprisms)) {
|
|
286
|
+
for (const nxCfg of bulk.nxprisms) {
|
|
287
|
+
console.log("Adding Nutanix config:", nxCfg.name || "(unnamed)");
|
|
288
|
+
try {
|
|
289
|
+
await client.licenseManager.nutanix.createConfiguration(cfgId, nxCfg.name, {
|
|
290
|
+
actions: nxCfg?.actions || [],
|
|
291
|
+
server: nxCfg?.server,
|
|
292
|
+
user: nxCfg?.user,
|
|
293
|
+
password: nxCfg?.password,
|
|
294
|
+
});
|
|
295
|
+
} catch (err) {
|
|
296
|
+
const message = err.message || err;
|
|
297
|
+
console.error("Error creating nutanix config:", message);
|
|
298
|
+
errors.push({
|
|
299
|
+
step: "createNutanixConfiguration",
|
|
300
|
+
name: nxCfg.name,
|
|
301
|
+
message: String(message),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (Array.isArray(bulk?.vcenters)) {
|
|
308
|
+
for (const vmwCfg of bulk.vcenters) {
|
|
309
|
+
console.log("Adding vCenter config:", vmwCfg.name || "(unnamed)");
|
|
310
|
+
try {
|
|
311
|
+
await client.licenseManager.vcenter.createConfiguration(cfgId, vmwCfg.name, {
|
|
312
|
+
actions: vmwCfg?.actions || [],
|
|
313
|
+
connection: vmwCfg?.connect,
|
|
314
|
+
user: vmwCfg?.user,
|
|
315
|
+
password: vmwCfg?.password,
|
|
316
|
+
});
|
|
317
|
+
} catch (err) {
|
|
318
|
+
const message = err.message || err;
|
|
319
|
+
console.error("Error creating vcenter config:", message);
|
|
320
|
+
errors.push({
|
|
321
|
+
step: "createVcenterConfiguration",
|
|
322
|
+
name: vmwCfg.name,
|
|
323
|
+
message: String(message),
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (bulk?.network_discovery) {
|
|
330
|
+
console.log("Adding network discovery...");
|
|
331
|
+
try {
|
|
332
|
+
await client.licenseManager.createNetworkDiscoveryConfiguration(
|
|
333
|
+
cfgId,
|
|
334
|
+
bulk.network_discovery?.ip_subnets,
|
|
335
|
+
bulk.network_discovery?.dns_servers,
|
|
336
|
+
{
|
|
337
|
+
oracle_ports: bulk.network_discovery?.ora_ports?.toString(),
|
|
338
|
+
mssql_ports: bulk.network_discovery?.sql_ports?.toString(),
|
|
339
|
+
other_ports: bulk.network_discovery?.other_ports?.toString(),
|
|
340
|
+
},
|
|
341
|
+
);
|
|
342
|
+
} catch (err) {
|
|
343
|
+
const message = err.message || err;
|
|
344
|
+
console.error("Error creating network discovery:", message);
|
|
345
|
+
errors.push({
|
|
346
|
+
step: "createNetworkDiscoveryConfiguration",
|
|
347
|
+
message: String(message),
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
try {
|
|
353
|
+
if (typeof materializeMonitoringConfiguration !== "function") {
|
|
354
|
+
throw new Error("materializeMonitoringConfiguration dependency is required");
|
|
355
|
+
}
|
|
356
|
+
await materializeMonitoringConfiguration({ configId: cfgId, saveFile: true });
|
|
357
|
+
} catch (err) {
|
|
358
|
+
const message = err.message || err;
|
|
359
|
+
console.error("Error pulling/saving config:", message);
|
|
360
|
+
errors.push({ step: "materializeMonitoringConfiguration", message: String(message) });
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (errors.length > 0) {
|
|
364
|
+
console.error("Import completed with errors:", JSON.stringify(errors, null, 2));
|
|
365
|
+
throw new Error("Import completed with errors");
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export { importMonitoringConfiguration, printImportMonitoringConfigurationHelp };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getOpsCompassClient } from "../../opscompass.js";
|
|
2
2
|
import { utilsModule as utils } from "../../lib/utils.js";
|
|
3
3
|
import maskValues from "../../lib/maskValues.js";
|
|
4
|
+
import resolveMonitoringConfigId from "./resolveMonitoringConfigId.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @module license-manager:microsoft
|
|
@@ -384,11 +385,17 @@ async function deleteMssqlConfiguration(args) {
|
|
|
384
385
|
}
|
|
385
386
|
|
|
386
387
|
async function listMssqlConfigurations(args) {
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
// Resolve monitoring configuration id (prefer global, fallback to args)
|
|
389
|
+
const resolved = resolveMonitoringConfigId(args);
|
|
390
|
+
if (resolved === undefined || resolved === null || resolved === "") {
|
|
391
|
+
console.error(
|
|
392
|
+
"ERROR: Monitoring configuration is not set. Use --monitoring-configuration-id <id> or configure a default.",
|
|
391
393
|
);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const client = await getOpsCompassClient();
|
|
398
|
+
const listMssqlConfigs = await client.licenseManager.mssql.listMssqlConfigurations(resolved);
|
|
392
399
|
|
|
393
400
|
console.log(JSON.stringify(listMssqlConfigs, null, 2));
|
|
394
401
|
}
|
|
@@ -26,11 +26,17 @@ async function deleteNutanixConfiguration(args) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async function listNutanixConfigurations(args) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const { default: resolveMonitoringConfigId } = await import("./resolveMonitoringConfigId.js");
|
|
30
|
+
const resolved = resolveMonitoringConfigId(args);
|
|
31
|
+
if (resolved === undefined || resolved === null || resolved === "") {
|
|
32
|
+
console.error(
|
|
33
|
+
"ERROR: Monitoring configuration is not set. Use --monitoring-configuration-id <id> or configure a default.",
|
|
33
34
|
);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const client = await getOpsCompassClient();
|
|
39
|
+
const listNutanixConfigs = await client.licenseManager.nutanix.listConfigurations(resolved);
|
|
34
40
|
|
|
35
41
|
// For listing show the raw data (do not unmask the data here)
|
|
36
42
|
// if (listNutanixConfigs && listNutanixConfigs.length > 0) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Helper to resolve monitoring configuration id for license-manager commands
|
|
2
|
+
// Preference order:
|
|
3
|
+
// 1) global.monitoringConfig when explicitly set (not undefined/null/"")
|
|
4
|
+
// 2) raw args: --monitoring-configuration-id or --monitoringconfigurationid
|
|
5
|
+
// Returns the resolved id string or undefined when not found
|
|
6
|
+
export function resolveMonitoringConfigId(args = []) {
|
|
7
|
+
// Prefer explicit global setting when present (explicitly check for undefined/null/empty)
|
|
8
|
+
if (global.monitoringConfig !== undefined && global.monitoringConfig !== null && global.monitoringConfig !== "") {
|
|
9
|
+
return global.monitoringConfig;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Scan raw args for flags
|
|
13
|
+
for (let i = 0; i < args.length - 0; i++) {
|
|
14
|
+
const a = (args[i] || "").toLowerCase();
|
|
15
|
+
if (a === "--monitoring-configuration-id" || a === "--monitoringconfigurationid") {
|
|
16
|
+
// return next token if present and not another flag
|
|
17
|
+
const val = args[i + 1];
|
|
18
|
+
if (val === undefined || val === null || val === "" || (typeof val === "string" && val.startsWith("--"))) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return val;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default resolveMonitoringConfigId;
|
|
@@ -26,11 +26,17 @@ async function deleteVcenterConfiguration(args) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async function listVcenterConfigurations(args) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const { default: resolveMonitoringConfigId } = await import("./resolveMonitoringConfigId.js");
|
|
30
|
+
const resolved = resolveMonitoringConfigId(args);
|
|
31
|
+
if (resolved === undefined || resolved === null || resolved === "") {
|
|
32
|
+
console.error(
|
|
33
|
+
"ERROR: Monitoring configuration is not set. Use --monitoring-configuration-id <id> or configure a default.",
|
|
33
34
|
);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const client = await getOpsCompassClient();
|
|
39
|
+
const listVcenterConfigs = await client.licenseManager.vcenter.listConfigurations(resolved);
|
|
34
40
|
|
|
35
41
|
console.log(JSON.stringify(listVcenterConfigs, null, 2));
|
|
36
42
|
}
|