@opscompass/opscompass-cli 1.0.40 → 1.0.42
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/environment/current.js +2 -0
- package/environment/demo.js +2 -0
- package/environment/dev.js +2 -0
- package/environment/local.js +2 -0
- package/environment/production.js +2 -0
- package/index.js +1 -0
- package/lib/consts.js +1 -0
- package/lib/maskValues.js +7 -7
- package/lib/utils.js +168 -47
- package/modules/compliance.js +24 -0
- package/modules/data-gathering-scripts.js +2 -6
- package/modules/defaults.js +1 -1
- package/modules/license-manager/maskedConfig.js +114 -0
- package/modules/license-manager/microsoft.js +862 -0
- package/modules/license-manager/nutanix.js +285 -0
- package/modules/license-manager/vcenter.js +281 -0
- package/modules/license-manager.js +211 -1243
- package/opscompass.js +14 -1
- package/package.json +2 -2
package/environment/current.js
CHANGED
|
@@ -4,6 +4,7 @@ const {
|
|
|
4
4
|
OpsCompassClient,
|
|
5
5
|
ScriptType,
|
|
6
6
|
OAuthHandler,
|
|
7
|
+
licenseManagerConfigurationTypes,
|
|
7
8
|
} = require("@opscompass/opscompass-api");
|
|
8
9
|
|
|
9
10
|
const path = require("path");
|
|
@@ -19,6 +20,7 @@ const isLocal = false;
|
|
|
19
20
|
|
|
20
21
|
module.exports = {
|
|
21
22
|
OpsCompassClient,
|
|
23
|
+
licenseManagerConfigurationTypes,
|
|
22
24
|
ScriptType,
|
|
23
25
|
oAuthClient,
|
|
24
26
|
opscompassHome,
|
package/environment/demo.js
CHANGED
|
@@ -4,6 +4,7 @@ const {
|
|
|
4
4
|
OpsCompassClient,
|
|
5
5
|
ScriptType,
|
|
6
6
|
OAuthHandler,
|
|
7
|
+
licenseManagerConfigurationTypes,
|
|
7
8
|
} = require("@opscompass/opscompass-api-demo");
|
|
8
9
|
|
|
9
10
|
const path = require("path");
|
|
@@ -19,6 +20,7 @@ const isLocal = false;
|
|
|
19
20
|
|
|
20
21
|
module.exports = {
|
|
21
22
|
OpsCompassClient,
|
|
23
|
+
licenseManagerConfigurationTypes,
|
|
22
24
|
ScriptType,
|
|
23
25
|
oAuthClient,
|
|
24
26
|
opscompassHome,
|
package/environment/dev.js
CHANGED
|
@@ -4,6 +4,7 @@ const {
|
|
|
4
4
|
OpsCompassClient,
|
|
5
5
|
ScriptType,
|
|
6
6
|
OAuthHandler,
|
|
7
|
+
licenseManagerConfigurationTypes,
|
|
7
8
|
} = require("@opscompass/opscompass-api-dev");
|
|
8
9
|
|
|
9
10
|
const path = require("path");
|
|
@@ -19,6 +20,7 @@ const isLocal = false;
|
|
|
19
20
|
|
|
20
21
|
module.exports = {
|
|
21
22
|
OpsCompassClient,
|
|
23
|
+
licenseManagerConfigurationTypes,
|
|
22
24
|
ScriptType,
|
|
23
25
|
oAuthClient,
|
|
24
26
|
opscompassHome,
|
package/environment/local.js
CHANGED
|
@@ -5,6 +5,7 @@ const {
|
|
|
5
5
|
OpsCompassClient,
|
|
6
6
|
ScriptType,
|
|
7
7
|
OAuthHandler,
|
|
8
|
+
licenseManagerConfigurationTypes,
|
|
8
9
|
} = require("@opscompass/opscompass-api");
|
|
9
10
|
|
|
10
11
|
const path = require("path");
|
|
@@ -20,6 +21,7 @@ const isLocal = true;
|
|
|
20
21
|
|
|
21
22
|
module.exports = {
|
|
22
23
|
OpsCompassClient,
|
|
24
|
+
licenseManagerConfigurationTypes,
|
|
23
25
|
ScriptType,
|
|
24
26
|
oAuthClient,
|
|
25
27
|
opscompassHome,
|
|
@@ -4,6 +4,7 @@ const {
|
|
|
4
4
|
OpsCompassClient,
|
|
5
5
|
ScriptType,
|
|
6
6
|
OAuthHandler,
|
|
7
|
+
licenseManagerConfigurationTypes,
|
|
7
8
|
} = require("@opscompass/opscompass-api");
|
|
8
9
|
|
|
9
10
|
const path = require("path");
|
|
@@ -19,6 +20,7 @@ const isLocal = false;
|
|
|
19
20
|
|
|
20
21
|
module.exports = {
|
|
21
22
|
OpsCompassClient,
|
|
23
|
+
licenseManagerConfigurationTypes,
|
|
22
24
|
ScriptType,
|
|
23
25
|
oAuthClient,
|
|
24
26
|
opscompassHome,
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const handleError = require("./error.js");
|
|
|
5
5
|
const { canReadStoredCredentials } = require("./credentials.js");
|
|
6
6
|
const { versionCheck } = require("./updates.js");
|
|
7
7
|
const { isLocal, opscompassHome } = require("./environment/current.js");
|
|
8
|
+
|
|
8
9
|
const fs = require("fs");
|
|
9
10
|
const path = require("path");
|
|
10
11
|
|
package/lib/consts.js
CHANGED
package/lib/maskValues.js
CHANGED
|
@@ -258,7 +258,7 @@ function processArgs(action, args) {
|
|
|
258
258
|
// case "get": // not meant to call directly
|
|
259
259
|
case "lookup":
|
|
260
260
|
// The type is after the '-' in oc$mask-{type}
|
|
261
|
-
const matchResult = args[0]
|
|
261
|
+
const matchResult = args[0]?.match(/.*-(.+):{(.*)}/);
|
|
262
262
|
if (!matchResult) {
|
|
263
263
|
return printHelp("invalid mask format");
|
|
264
264
|
}
|
|
@@ -276,7 +276,7 @@ function processArgs(action, args) {
|
|
|
276
276
|
case "dumptable":
|
|
277
277
|
case "dump-table":
|
|
278
278
|
// Special case for dumpTable allow property=hash (as specified in defaults.maskValues)
|
|
279
|
-
if (action.startsWith("dump")) {
|
|
279
|
+
if (action.startsWith("dump") && args[0]?.indexOf("=") > 0) {
|
|
280
280
|
maskType = maskTypes[args[0].split("=")[1]];
|
|
281
281
|
break;
|
|
282
282
|
}
|
|
@@ -304,14 +304,14 @@ function processArgs(action, args) {
|
|
|
304
304
|
* Print the help message for the maskValues module
|
|
305
305
|
*/
|
|
306
306
|
function printHelp(errMsg) {
|
|
307
|
-
console.
|
|
308
|
-
console.
|
|
307
|
+
console.log("Actions available for maskValues:\n");
|
|
308
|
+
console.log(
|
|
309
309
|
" dumpTable:",
|
|
310
310
|
"dumps the mask table for the specified property"
|
|
311
311
|
);
|
|
312
|
-
console.
|
|
313
|
-
console.
|
|
314
|
-
console.
|
|
312
|
+
console.log(" lookup:", "gets a value from mask");
|
|
313
|
+
console.log(" set:", "sets a value to mask");
|
|
314
|
+
console.log(
|
|
315
315
|
"\nParameters:\n",
|
|
316
316
|
" --type (",
|
|
317
317
|
Object.keys(maskTypes).join(" | "),
|
package/lib/utils.js
CHANGED
|
@@ -10,7 +10,14 @@
|
|
|
10
10
|
const crypto = require("crypto");
|
|
11
11
|
const fs = require("fs");
|
|
12
12
|
const path = require("path");
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
opscompassHome,
|
|
16
|
+
decoder,
|
|
17
|
+
cliCommand,
|
|
18
|
+
} = require("../environment/current");
|
|
19
|
+
const defaultsPath = path.join(opscompassHome, "defaults.json");
|
|
20
|
+
|
|
14
21
|
const { resourceTypes, encryptAttrs } = require("./consts");
|
|
15
22
|
const findRemoveSync = require("find-remove");
|
|
16
23
|
|
|
@@ -68,6 +75,36 @@ function processStandardArgs(args) {
|
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Parse a configuration JSON string
|
|
80
|
+
* @param {*} jsonString
|
|
81
|
+
* @returns any
|
|
82
|
+
*/
|
|
83
|
+
function parseConfigurationJson(jsonString) {
|
|
84
|
+
if (!jsonString) return null;
|
|
85
|
+
|
|
86
|
+
let obj = JSON.parse("{}");
|
|
87
|
+
try {
|
|
88
|
+
// replace non-esaped backslahes to avoid problems parsing
|
|
89
|
+
// these probably come from SQL Server names
|
|
90
|
+
obj = JSON.parse(jsonString.replace(/(?<!\\)\\(?!\\)/g, "\\\\"));
|
|
91
|
+
if (!Array.isArray(obj)) {
|
|
92
|
+
obj = [obj];
|
|
93
|
+
}
|
|
94
|
+
// If configId (as in data gathering config file), replace with just "id"
|
|
95
|
+
for (let i = 0; i < obj.length; i++) {
|
|
96
|
+
if (obj[i].config_id && !obj[i].id) {
|
|
97
|
+
obj[i].id = obj[i].config_id;
|
|
98
|
+
delete obj[i].config_id;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error("Invalid JSON string provided.");
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return obj;
|
|
106
|
+
}
|
|
107
|
+
|
|
71
108
|
/**
|
|
72
109
|
* Function to determine where to write a configuration file
|
|
73
110
|
*
|
|
@@ -76,14 +113,39 @@ function processStandardArgs(args) {
|
|
|
76
113
|
*/
|
|
77
114
|
function getConfigFilePath(args = []) {
|
|
78
115
|
processStandardArgs(args); // in case it has not already been called
|
|
116
|
+
// Warn if no defaults file is found
|
|
117
|
+
if (!fs.existsSync(defaultsPath)) {
|
|
118
|
+
console.error(
|
|
119
|
+
`\nWARNING: %s not found,\n to create it, run: \`${cliCommand} defaults ...\``,
|
|
120
|
+
defaultsPath
|
|
121
|
+
);
|
|
122
|
+
}
|
|
79
123
|
|
|
80
124
|
// Handle any additional arguments
|
|
81
125
|
let explicitFilePath = undefined;
|
|
82
|
-
for (let i = args.length
|
|
126
|
+
for (let i = 0; i < args.length; i += 2) {
|
|
83
127
|
switch (args[i].toLowerCase()) {
|
|
84
128
|
case "--config":
|
|
85
|
-
|
|
129
|
+
// This is an optional qaualifier for the filename
|
|
130
|
+
case "--savefile":
|
|
131
|
+
case "--save-file":
|
|
132
|
+
// This means we are supposed to save the file
|
|
86
133
|
explicitFilePath = args[i + 1];
|
|
134
|
+
if (["true", "false"].includes(explicitFilePath)) {
|
|
135
|
+
// If the next argument is true or false, then it is not a file path
|
|
136
|
+
explicitFilePath = undefined;
|
|
137
|
+
} else {
|
|
138
|
+
// If explicitFilePath is an existing directory, use the default file name
|
|
139
|
+
if (
|
|
140
|
+
fs.existsSync(explicitFilePath) &&
|
|
141
|
+
fs.lstatSync(explicitFilePath).isDirectory()
|
|
142
|
+
) {
|
|
143
|
+
explicitFilePath = path.join(
|
|
144
|
+
explicitFilePath,
|
|
145
|
+
`${global.monitoringConfig}-dgConfig.json`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
87
149
|
break;
|
|
88
150
|
case "--client":
|
|
89
151
|
// This is a legacy synonym for account
|
|
@@ -91,22 +153,32 @@ function getConfigFilePath(args = []) {
|
|
|
91
153
|
break;
|
|
92
154
|
case "--id":
|
|
93
155
|
// This is a synonym for monitoring-configuration-id
|
|
94
|
-
global.monitoringConfig = args[i + 1];
|
|
156
|
+
global.monitoringConfig = Number(args[i + 1]);
|
|
95
157
|
break;
|
|
96
158
|
}
|
|
97
159
|
}
|
|
98
160
|
|
|
161
|
+
// If we have defaults and company is not set, flag an error
|
|
162
|
+
if (!global.company) {
|
|
163
|
+
console.error(
|
|
164
|
+
"\nERROR: Company is not set. Please use --company <company-slug>."
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
99
168
|
// If there's an extra argument, use it as the explicit file path
|
|
100
169
|
// the file may not exist yet if we are creating it ...
|
|
101
|
-
if (args.length & 1) {
|
|
170
|
+
if (args.length & 1 && !explicitFilePath) {
|
|
102
171
|
explicitFilePath = args[args.length - 1];
|
|
103
172
|
}
|
|
104
173
|
|
|
105
174
|
const cfgPath = path.join(opscompassHome, "configs");
|
|
106
175
|
const cfgName = "dgConfig.json";
|
|
107
176
|
|
|
177
|
+
// Create a default configuration file object
|
|
108
178
|
var cfgFile = new Object({
|
|
109
|
-
CUST_NAME
|
|
179
|
+
// CUST_NAME is the name of the Licensing Account
|
|
180
|
+
// Company can come from either defaults.json or command line
|
|
181
|
+
CUST_NAME: `Licensing Account for ${global.company}`,
|
|
110
182
|
CUST_TOKEN: global.account,
|
|
111
183
|
configurationId: global.monitoringConfig,
|
|
112
184
|
});
|
|
@@ -117,8 +189,6 @@ function getConfigFilePath(args = []) {
|
|
|
117
189
|
console.error("\nWARNING: filePath missing values:", cfgFile);
|
|
118
190
|
// console.error(`remaining args (${args.length}):`, args);
|
|
119
191
|
return undefined;
|
|
120
|
-
} else {
|
|
121
|
-
cfgFile.configurationId = 0; // This implies it was null or undefined
|
|
122
192
|
}
|
|
123
193
|
}
|
|
124
194
|
|
|
@@ -126,7 +196,16 @@ function getConfigFilePath(args = []) {
|
|
|
126
196
|
if (explicitFilePath && !explicitFilePath.startsWith("--")) {
|
|
127
197
|
cfgFile.filePath = explicitFilePath;
|
|
128
198
|
} else {
|
|
129
|
-
|
|
199
|
+
try {
|
|
200
|
+
cfgFile.filePath = path.join(
|
|
201
|
+
cfgPath,
|
|
202
|
+
global.company, // This is the company slug as opposed to name
|
|
203
|
+
cfgFile.CUST_TOKEN,
|
|
204
|
+
`${cfgFile.configurationId || 0}-${cfgName}`
|
|
205
|
+
);
|
|
206
|
+
} catch {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
130
209
|
}
|
|
131
210
|
|
|
132
211
|
// If it's a relative path prepend PWD
|
|
@@ -134,6 +213,17 @@ function getConfigFilePath(args = []) {
|
|
|
134
213
|
cfgFile.filePath = `${process.env.PWD}/${cfgFile.filePath}`;
|
|
135
214
|
}
|
|
136
215
|
|
|
216
|
+
// If it is an explicit directory or missing .json
|
|
217
|
+
if (cfgFile.filePath.endsWith("/")) {
|
|
218
|
+
cfgFile.filePath += `${cfgFile.configurationId || 0}-${cfgName}`;
|
|
219
|
+
} else if (
|
|
220
|
+
// If file extension is not already json, add it
|
|
221
|
+
!cfgFile.filePath.endsWith(".json") &&
|
|
222
|
+
!fs.existsSync(cfgFile.filePath)
|
|
223
|
+
) {
|
|
224
|
+
cfgFile.filePath += ".json";
|
|
225
|
+
}
|
|
226
|
+
|
|
137
227
|
// If they specified an existing file, use the ID from the file
|
|
138
228
|
if (fs.existsSync(cfgFile.filePath)) {
|
|
139
229
|
// get configurationId from the file
|
|
@@ -147,20 +237,16 @@ function getConfigFilePath(args = []) {
|
|
|
147
237
|
`Error reading file: ${cfgFile.filePath} - ${error.message}`
|
|
148
238
|
);
|
|
149
239
|
}
|
|
150
|
-
if (fileObj
|
|
151
|
-
|
|
240
|
+
if (fileObj) {
|
|
241
|
+
fileObj.filePath = cfgFile.filePath; // Add filePath to the object
|
|
242
|
+
cfgFile = fileObj; // Use the file object as the configuration
|
|
152
243
|
}
|
|
153
244
|
} else {
|
|
154
|
-
// try to get configurationId from the file name
|
|
245
|
+
// try to get configurationId from the file name and override the default
|
|
155
246
|
const fParts = cfgFile.filePath.split("-")[0].replace(/^.*\//, "");
|
|
156
247
|
if (+fParts > 0) {
|
|
157
248
|
cfgFile.configurationId = +fParts;
|
|
158
249
|
}
|
|
159
|
-
|
|
160
|
-
// If file extension is not already json, add it
|
|
161
|
-
if (!cfgFile.filePath.endsWith(".json")) {
|
|
162
|
-
cfgFile.filePath += ".json";
|
|
163
|
-
}
|
|
164
250
|
}
|
|
165
251
|
|
|
166
252
|
// If filePath contains undefined, we do not have all the needed pieces
|
|
@@ -185,11 +271,15 @@ function readConfigFile(args) {
|
|
|
185
271
|
console.error("Configuration file does not exist:", cfgFile.filePath);
|
|
186
272
|
return undefined;
|
|
187
273
|
}
|
|
274
|
+
delete cfgFile.filePath; // Remove the filePath attribute first
|
|
188
275
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
276
|
+
// If the file contains CUST_TOKEN, we need to decrypt with it
|
|
277
|
+
if (cfgFile.CUST_TOKEN) {
|
|
278
|
+
global.account = cfgFile.CUST_TOKEN;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
decryptValues(cfgFile);
|
|
282
|
+
return cfgFile;
|
|
193
283
|
}
|
|
194
284
|
|
|
195
285
|
/**
|
|
@@ -201,6 +291,19 @@ function readConfigFile(args) {
|
|
|
201
291
|
* If there is an existing file (based on args), we'll create a copy first
|
|
202
292
|
*/
|
|
203
293
|
async function writeConfigFile(args, cfgData = undefined, overwrite = false) {
|
|
294
|
+
// If the cfgData has values, use them to override the global values
|
|
295
|
+
// from defaults.json
|
|
296
|
+
// CUST_NAME is the name of the Licensing Account. Company is not in cfgData.
|
|
297
|
+
if (cfgData) {
|
|
298
|
+
if (cfgData.configurationId) {
|
|
299
|
+
global.monitoringConfig = cfgData.configurationId;
|
|
300
|
+
}
|
|
301
|
+
if (cfgData.CUST_TOKEN) {
|
|
302
|
+
global.account = cfgData.CUST_TOKEN;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Args will override the global values and/or cfgData
|
|
204
307
|
var cfgFile = getConfigFilePath(args);
|
|
205
308
|
if (!cfgFile) return undefined;
|
|
206
309
|
|
|
@@ -208,8 +311,7 @@ async function writeConfigFile(args, cfgData = undefined, overwrite = false) {
|
|
|
208
311
|
// console.error("cfgFile:", cfgFile);
|
|
209
312
|
|
|
210
313
|
// Allow command line overwrite flag as well
|
|
211
|
-
|
|
212
|
-
if (argOverwrite) overwrite = true;
|
|
314
|
+
overwrite = args?.indexOf("--overwrite") >= 0 ? true : false;
|
|
213
315
|
|
|
214
316
|
// Figure out the name of the config file to write
|
|
215
317
|
if (!cfgFile) {
|
|
@@ -229,11 +331,15 @@ async function writeConfigFile(args, cfgData = undefined, overwrite = false) {
|
|
|
229
331
|
|
|
230
332
|
var newConfig = cfgData;
|
|
231
333
|
if (newConfig === undefined) {
|
|
232
|
-
// We did not get anything to write,
|
|
233
|
-
newConfig =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
334
|
+
// We did not get anything to write, use the default config
|
|
335
|
+
newConfig = cfgFile;
|
|
336
|
+
} else if (cfgData) {
|
|
337
|
+
// If cfgData is provided, copy any missing values from cfgFile
|
|
338
|
+
for (const key of Object.keys(cfgFile)) {
|
|
339
|
+
if (newConfig[key] === undefined) {
|
|
340
|
+
newConfig[key] = cfgFile[key];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
237
343
|
}
|
|
238
344
|
|
|
239
345
|
const fExt = cfgName.split(".").pop();
|
|
@@ -561,39 +667,54 @@ function sha256sum(input) {
|
|
|
561
667
|
}
|
|
562
668
|
|
|
563
669
|
/**
|
|
564
|
-
* Read from stdin if anything is present
|
|
670
|
+
* Read synchronously from stdin if anything is present
|
|
671
|
+
* @param
|
|
672
|
+
* @returns {Promise<string> | undefined} - resolves with the input data as a string
|
|
565
673
|
*/
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
if (
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
674
|
+
|
|
675
|
+
async function readFromStdinSync() {
|
|
676
|
+
return new Promise((resolve, reject) => {
|
|
677
|
+
if (!process.stdin.isTTY) {
|
|
678
|
+
let inputData = Buffer.alloc(0);
|
|
679
|
+
|
|
680
|
+
process.stdin.on("data", (chunk) => {
|
|
681
|
+
inputData = Buffer.concat([inputData, chunk]);
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
process.stdin.on("end", () => {
|
|
685
|
+
resolve(inputData.toString("utf8")); // Convert buffer to string using UTF-8 encoding
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
process.stdin.on("error", (err) => {
|
|
689
|
+
if (["EAGAIN", "EBADF", "EOF"].includes(err.code)) {
|
|
690
|
+
// EAGAIN Happens on OS X (not Windows)
|
|
691
|
+
// EBADF Happens on Ubuntu under nohup
|
|
692
|
+
// EOF Happens on Windows, but not OS X
|
|
693
|
+
} else {
|
|
694
|
+
console.error(err);
|
|
695
|
+
// Do not reject, we want to continue if nothing is there
|
|
696
|
+
// reject(err);
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
process.stdin.resume();
|
|
580
701
|
} else {
|
|
581
|
-
|
|
702
|
+
resolve(undefined);
|
|
582
703
|
}
|
|
583
|
-
|
|
584
|
-
}
|
|
704
|
+
});
|
|
585
705
|
}
|
|
586
706
|
|
|
587
707
|
// Export module artifacts
|
|
588
708
|
const utilsModule = {
|
|
589
709
|
processStandardArgs,
|
|
710
|
+
parseConfigurationJson,
|
|
590
711
|
decryptValues,
|
|
591
712
|
encryptValues,
|
|
592
713
|
getConfigFilePath,
|
|
593
714
|
getTimestamp,
|
|
594
715
|
opscompassHome,
|
|
595
716
|
readConfigFile,
|
|
596
|
-
|
|
717
|
+
readFromStdinSync,
|
|
597
718
|
writeConfigFile,
|
|
598
719
|
isIPv4,
|
|
599
720
|
isIPv6,
|
package/modules/compliance.js
CHANGED
|
@@ -219,6 +219,17 @@ async function listDisabledChecks(args) {
|
|
|
219
219
|
console.log(JSON.stringify(response, null, 2));
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
async function transferNutanixPrismMetadata(args) {
|
|
223
|
+
const callParams = genericMetadataTrasfer(args);
|
|
224
|
+
const client = await getOpsCompassClient();
|
|
225
|
+
const response = await client.compliance.transferNutanixPrismMetadata(
|
|
226
|
+
callParams.company,
|
|
227
|
+
callParams.filePath
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
console.log(JSON.stringify(response, null, 2));
|
|
231
|
+
}
|
|
232
|
+
|
|
222
233
|
async function transferVMwareVsphereMetadata(args) {
|
|
223
234
|
const callParams = genericMetadataTrasfer(args);
|
|
224
235
|
const client = await getOpsCompassClient();
|
|
@@ -260,6 +271,7 @@ function genericMetadataTrasfer(args) {
|
|
|
260
271
|
callParams.type = args[++i];
|
|
261
272
|
break;
|
|
262
273
|
case "--filepath":
|
|
274
|
+
case "--file-path":
|
|
263
275
|
callParams.filePath = args[++i];
|
|
264
276
|
break;
|
|
265
277
|
case "--company":
|
|
@@ -592,6 +604,16 @@ async function printHelp() {
|
|
|
592
604
|
"--filePath [path] Path of the file to transfer to OpsCompass for processing."
|
|
593
605
|
);
|
|
594
606
|
console.log();
|
|
607
|
+
console.log(
|
|
608
|
+
"transfer-nutanix-prism-metadata",
|
|
609
|
+
"Transfers Nutanix Prism server metadata report into OpsCompass for processing"
|
|
610
|
+
);
|
|
611
|
+
console.log("Parameters:");
|
|
612
|
+
console.log("--company [company_slug]");
|
|
613
|
+
console.log(
|
|
614
|
+
"--filePath [path] Path of the file to transfer to OpsCompass for processing."
|
|
615
|
+
);
|
|
616
|
+
console.log();
|
|
595
617
|
console.log(
|
|
596
618
|
"transfer-vmware-vsphere-metadata",
|
|
597
619
|
"Transfers OpsCompass VMware VSphere metadata report into OpsCompass for processing"
|
|
@@ -773,6 +795,8 @@ const complianceModule = (action, ...args) => {
|
|
|
773
795
|
return getComplianceProblemsOverTime(args);
|
|
774
796
|
case "transfer-network-discovery-metadata":
|
|
775
797
|
return transferNetworkDiscoveryMetadata(args);
|
|
798
|
+
case "transfer-nutanix-prism-metadata":
|
|
799
|
+
return transferNutanixPrismMetadata(args);
|
|
776
800
|
case "transfer-vmware-vsphere-metadata":
|
|
777
801
|
return transferVMwareVsphereMetadata(args);
|
|
778
802
|
case "transfer-oracle-database-metadata":
|
|
@@ -422,9 +422,7 @@ async function printHelp() {
|
|
|
422
422
|
);
|
|
423
423
|
console.log("Parameters:");
|
|
424
424
|
console.log("--company [company_slug]");
|
|
425
|
-
console.log(
|
|
426
|
-
"--script-type ['discovery-tools', 'oracle-compliance', 'oracle-features', 'vsphere', 'msql-license', 'msql-compliance']"
|
|
427
|
-
);
|
|
425
|
+
console.log("--script-type", JSON.stringify(Object.values(ScriptType)));
|
|
428
426
|
console.log(
|
|
429
427
|
"--script-version (optional) [version] if not provided, the latest script will be downloaded"
|
|
430
428
|
);
|
|
@@ -436,9 +434,7 @@ async function printHelp() {
|
|
|
436
434
|
console.log("Parameters:");
|
|
437
435
|
console.log("--auto-update automatically downloads any needed updates");
|
|
438
436
|
console.log("--company [company_slug]");
|
|
439
|
-
console.log(
|
|
440
|
-
"--script-type ['oracle-compliance', 'oracle-features', 'vsphere', 'msql-license', 'msql-compliance']"
|
|
441
|
-
);
|
|
437
|
+
console.log("--script-type", JSON.stringify(Object.values(ScriptType)));
|
|
442
438
|
console.log();
|
|
443
439
|
console.log(
|
|
444
440
|
"manually-run-scripts",
|
package/modules/defaults.js
CHANGED
|
@@ -36,7 +36,7 @@ async function readDefaults() {
|
|
|
36
36
|
async function writeDefaults(args) {
|
|
37
37
|
let defaults = await readDefaults();
|
|
38
38
|
|
|
39
|
-
for (
|
|
39
|
+
for (var i = 0; i < args.length - 1; i++) {
|
|
40
40
|
switch (args[i]?.toLowerCase()) {
|
|
41
41
|
case "--company":
|
|
42
42
|
defaults.company = args[++i];
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getOpsCompassClient } from "../../opscompass.js";
|
|
2
|
+
import maskValues from "../../lib/maskValues.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Function to get the configuration type name from the function name
|
|
6
|
+
*/
|
|
7
|
+
function getConfigType(funcName) {
|
|
8
|
+
// Match all capitalized words in the camel case string
|
|
9
|
+
const matches = funcName.match(/[A-Z][a-z]*/g); // Return the first match if it exists
|
|
10
|
+
return matches ? matches[0] : funcName;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Function to find the correct license-manager API client function
|
|
15
|
+
*/
|
|
16
|
+
function getConfigClient(client, funcName) {
|
|
17
|
+
// Get the configuration type name
|
|
18
|
+
const configType = getConfigType(funcName);
|
|
19
|
+
const configName = configType.toLowerCase();
|
|
20
|
+
var apiFunction = undefined;
|
|
21
|
+
|
|
22
|
+
// Check if the client has an appropriate function
|
|
23
|
+
if (client[funcName]) {
|
|
24
|
+
apiFunction = client[funcName];
|
|
25
|
+
} else if (configType && client[configName]) {
|
|
26
|
+
if (client[configName][funcName]) {
|
|
27
|
+
// If the specified function exists, use it
|
|
28
|
+
apiFunction = client[configName][funcName];
|
|
29
|
+
} else {
|
|
30
|
+
// For modular license-manager configurations the configType
|
|
31
|
+
// would be redundant, so try without it
|
|
32
|
+
const modularName = funcName.replace(configType, "");
|
|
33
|
+
if (client[configName][modularName]) {
|
|
34
|
+
apiFunction = client[configName][modularName];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// If we found a function return it, otherwise throw an error
|
|
40
|
+
if (typeof apiFunction === "function") {
|
|
41
|
+
// Bind the method to the client instance to ensure the apiCaller
|
|
42
|
+
// has been initialized
|
|
43
|
+
return apiFunction.bind(client);
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Function ${funcName} not found in license-manager client`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create a masked configuration to prevent it from being sent to OpsCompass in the clear
|
|
50
|
+
*
|
|
51
|
+
* @param {string} funcName
|
|
52
|
+
* @param {string} configurationName - Name for the specific configuration object
|
|
53
|
+
* @param {object} optionalParams - values to send (and potentially mask)
|
|
54
|
+
*/
|
|
55
|
+
export async function createMaskedConfig(
|
|
56
|
+
funcName,
|
|
57
|
+
configurationName,
|
|
58
|
+
optionalParams
|
|
59
|
+
) {
|
|
60
|
+
const client = await getOpsCompassClient();
|
|
61
|
+
|
|
62
|
+
// Get the apiClient function
|
|
63
|
+
const apiFunction = getConfigClient(client.licenseManager, funcName);
|
|
64
|
+
|
|
65
|
+
// Make sure we have a valid function name
|
|
66
|
+
if (!funcName || !apiFunction) {
|
|
67
|
+
throw new Error("createMaskedConfig: invalid function name:", funcName);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Mask the data
|
|
71
|
+
await maskValues.maskObjValues(optionalParams);
|
|
72
|
+
|
|
73
|
+
// Call the API and return the results
|
|
74
|
+
const monitoringConfiguration = await apiFunction(
|
|
75
|
+
global.monitoringConfig,
|
|
76
|
+
configurationName,
|
|
77
|
+
optionalParams
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return monitoringConfiguration;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Update a masked configuration to prevent it from being sent to OpsCompass in the clear
|
|
85
|
+
*
|
|
86
|
+
* @param {string} funcName
|
|
87
|
+
* @param {string} configurationId - ID of the configuration to be updated
|
|
88
|
+
* @param {object} optionalParams - values to send (and potentially mask)
|
|
89
|
+
*/
|
|
90
|
+
export async function updateMaskedConfig(
|
|
91
|
+
funcName,
|
|
92
|
+
configurationId,
|
|
93
|
+
optionalParams
|
|
94
|
+
) {
|
|
95
|
+
const client = await getOpsCompassClient();
|
|
96
|
+
|
|
97
|
+
// Get the apiClient function
|
|
98
|
+
const apiFunction = getConfigClient(client.licenseManager, funcName);
|
|
99
|
+
|
|
100
|
+
// Make sure we have a valid function name
|
|
101
|
+
if (!funcName || !apiFunction) {
|
|
102
|
+
throw new Error("updateMaskedConfig: invalid function name:", funcName);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Mask the data
|
|
106
|
+
await maskValues.maskObjValues(optionalParams);
|
|
107
|
+
|
|
108
|
+
// Call the API and return the results
|
|
109
|
+
const targetConfiguration = await apiFunction(
|
|
110
|
+
configurationId,
|
|
111
|
+
optionalParams
|
|
112
|
+
);
|
|
113
|
+
return targetConfiguration;
|
|
114
|
+
}
|