@opscompass/opscompass-cli 1.0.24 → 1.0.25
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/index.js +14 -11
- package/lib/homeInteraction.js +39 -7
- package/modules/data-gathering-scripts.js +37 -24
- package/modules/license-manager.js +11 -1
- package/modules.js +13 -3
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -11,29 +11,28 @@ const path = require("path");
|
|
|
11
11
|
let defaultParams = JSON.parse("{}");
|
|
12
12
|
|
|
13
13
|
function checkDefaults() {
|
|
14
|
-
const defaultsPath = path.join(opscompassHome,
|
|
14
|
+
const defaultsPath = path.join(opscompassHome, "defaults.json");
|
|
15
15
|
let rawdata;
|
|
16
16
|
try {
|
|
17
17
|
rawdata = fs.readFileSync(defaultsPath);
|
|
18
18
|
defaultParams = JSON.parse(rawdata);
|
|
19
19
|
} catch (err) {
|
|
20
20
|
// We just want to catch the error, no logging necessary
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* When an individual string is passed to the API, default param will be provided if it exists.
|
|
24
|
+
* Default value is overwritten when explicitly included in CLI command.
|
|
25
|
+
*/
|
|
26
26
|
companySlug = defaultParams.company;
|
|
27
27
|
company = defaultParams.company;
|
|
28
28
|
account = defaultParams.account;
|
|
29
29
|
monitoringConfig = defaultParams.monitoringConfiguration;
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
* When a callParams object is passed to the API rather than one of the above strings, default values will be used unless explicitly replaced.
|
|
31
|
+
/**
|
|
32
|
+
* When a callParams object is passed to the API rather than one of the above strings, default values will be used unless explicitly replaced.
|
|
33
33
|
* Other properties can still be added to the callParams object. Unneeded default parameters may be included, but are ignored by the API.
|
|
34
|
-
*/
|
|
34
|
+
*/
|
|
35
35
|
callParams = defaultParams;
|
|
36
|
-
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
function requiresLogin() {
|
|
@@ -77,7 +76,11 @@ function help() {
|
|
|
77
76
|
const module = modules[moduleName];
|
|
78
77
|
if (!module.requiresLogin || loggedIn()) {
|
|
79
78
|
try {
|
|
80
|
-
|
|
79
|
+
if (typeof module === "function") {
|
|
80
|
+
await module(...args);
|
|
81
|
+
} else {
|
|
82
|
+
console.log(JSON.stringify(module, null, 2));
|
|
83
|
+
}
|
|
81
84
|
} catch (e) {
|
|
82
85
|
handleError(e);
|
|
83
86
|
}
|
package/lib/homeInteraction.js
CHANGED
|
@@ -19,6 +19,8 @@ const {
|
|
|
19
19
|
} = require("./cliHelpers.js");
|
|
20
20
|
const { nextTick } = require("process");
|
|
21
21
|
|
|
22
|
+
const semver = require("semver");
|
|
23
|
+
|
|
22
24
|
const SRC_FOLDER_NAME = "src";
|
|
23
25
|
const METADATA_FILE_NAME = "metadata.json";
|
|
24
26
|
const BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH = "scripts/runall.sh";
|
|
@@ -127,21 +129,51 @@ function scriptTypeFolderPath(scriptType) {
|
|
|
127
129
|
* @param {string} companySlug company slug to use when downloading scripts
|
|
128
130
|
* @param {OpsCompassClient} client client to use to call OpsCompass api
|
|
129
131
|
*/
|
|
132
|
+
var scriptsAvailable = undefined;
|
|
130
133
|
async function downloadScriptsToHome(
|
|
131
134
|
scriptType,
|
|
132
135
|
scriptVersion,
|
|
133
136
|
companySlug,
|
|
134
137
|
client
|
|
135
138
|
) {
|
|
136
|
-
// Ensure base scripts are downloaded/updated
|
|
139
|
+
// Ensure base scripts are downloaded/updated for all modules
|
|
137
140
|
if (scriptType !== ScriptType.baseScripts) {
|
|
138
|
-
const
|
|
139
|
-
ScriptType.baseScripts
|
|
140
|
-
undefined,
|
|
141
|
-
companySlug,
|
|
142
|
-
client
|
|
141
|
+
const localBaseVersion = await getInstalledScriptVersion(
|
|
142
|
+
ScriptType.baseScripts
|
|
143
143
|
);
|
|
144
|
-
|
|
144
|
+
|
|
145
|
+
// Determine what is available
|
|
146
|
+
if (!scriptsAvailable) {
|
|
147
|
+
console.log("Fetching remote versions...");
|
|
148
|
+
scriptsAvailable = await client.dataGatheringScripts.getScriptVersions(
|
|
149
|
+
companySlug
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
var availableBase = undefined;
|
|
154
|
+
if (
|
|
155
|
+
Array.isArray(scriptsAvailable?.versions) &&
|
|
156
|
+
scriptsAvailable.versions?.length > 0
|
|
157
|
+
) {
|
|
158
|
+
availableBase = scriptsAvailable.versions.find(
|
|
159
|
+
(version) => version.scriptType === ScriptType.baseScripts
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// If base is available and not installed or out of date
|
|
164
|
+
if (
|
|
165
|
+
availableBase &&
|
|
166
|
+
(!localBaseVersion ||
|
|
167
|
+
semver.gt(availableBase.scriptVersion, localBaseVersion))
|
|
168
|
+
) {
|
|
169
|
+
const baseVersion = await downloadScriptsToHome(
|
|
170
|
+
ScriptType.baseScripts,
|
|
171
|
+
undefined,
|
|
172
|
+
companySlug,
|
|
173
|
+
client
|
|
174
|
+
);
|
|
175
|
+
console.log("Base scripts updated (v%s)", baseVersion);
|
|
176
|
+
}
|
|
145
177
|
}
|
|
146
178
|
|
|
147
179
|
// Download specific script
|
|
@@ -20,7 +20,7 @@ const util = require("util");
|
|
|
20
20
|
const exec = util.promisify(require("child_process").exec);
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Lists script types that are locally
|
|
23
|
+
* Lists script types that are locally downloaded
|
|
24
24
|
*/
|
|
25
25
|
async function listLocalScripts(args) {
|
|
26
26
|
let quiet = false;
|
|
@@ -84,7 +84,7 @@ async function downloadScripts(args) {
|
|
|
84
84
|
for (let i = 0; i < args.length - 1; i++) {
|
|
85
85
|
switch (args[i].toLowerCase()) {
|
|
86
86
|
case "--company":
|
|
87
|
-
|
|
87
|
+
company = args[++i];
|
|
88
88
|
break;
|
|
89
89
|
case "--script-type":
|
|
90
90
|
case "--scripttype":
|
|
@@ -110,7 +110,7 @@ async function downloadScripts(args) {
|
|
|
110
110
|
const rcvdVersion = await downloadScriptsToHome(
|
|
111
111
|
scriptType,
|
|
112
112
|
scriptVersion,
|
|
113
|
-
|
|
113
|
+
company,
|
|
114
114
|
client
|
|
115
115
|
);
|
|
116
116
|
|
|
@@ -129,7 +129,7 @@ async function listAvailableScripts(args) {
|
|
|
129
129
|
for (let i = 0; i < args.length; i++) {
|
|
130
130
|
switch (args[i].toLowerCase()) {
|
|
131
131
|
case "--company":
|
|
132
|
-
|
|
132
|
+
company = args[++i];
|
|
133
133
|
break;
|
|
134
134
|
case "--quiet":
|
|
135
135
|
quiet = true;
|
|
@@ -156,7 +156,7 @@ async function listAvailableScripts(args) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
|
-
* Checks the
|
|
159
|
+
* Checks the downloaded scripts version against the latest scripts version for a given scriptType.
|
|
160
160
|
* or all scriptTypes if not specified
|
|
161
161
|
*/
|
|
162
162
|
async function checkScriptUpdates(args) {
|
|
@@ -169,7 +169,7 @@ async function checkScriptUpdates(args) {
|
|
|
169
169
|
autoUpdate = true;
|
|
170
170
|
break;
|
|
171
171
|
case "--company":
|
|
172
|
-
|
|
172
|
+
company = args[++i];
|
|
173
173
|
break;
|
|
174
174
|
case "--script-type":
|
|
175
175
|
case "--scripttype":
|
|
@@ -193,7 +193,7 @@ async function checkScriptUpdates(args) {
|
|
|
193
193
|
|
|
194
194
|
if (!currentScriptVersion) {
|
|
195
195
|
console.log(
|
|
196
|
-
`Local scripts for type ${scriptType} not found. Please make sure they are
|
|
196
|
+
`Local scripts for type ${scriptType} not found. Please make sure they are downloaded.`
|
|
197
197
|
);
|
|
198
198
|
console.log("If the issue persists, please contact your OpsCompass rep.");
|
|
199
199
|
return;
|
|
@@ -201,10 +201,7 @@ async function checkScriptUpdates(args) {
|
|
|
201
201
|
|
|
202
202
|
console.log("Checking for latest version of module %s...", scriptType);
|
|
203
203
|
const latestScriptVersion =
|
|
204
|
-
await client.dataGatheringScripts.checkScriptUpdates(
|
|
205
|
-
companySlug,
|
|
206
|
-
scriptType
|
|
207
|
-
);
|
|
204
|
+
await client.dataGatheringScripts.checkScriptUpdates(company, scriptType);
|
|
208
205
|
|
|
209
206
|
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
210
207
|
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
@@ -214,8 +211,25 @@ async function checkScriptUpdates(args) {
|
|
|
214
211
|
);
|
|
215
212
|
console.log(
|
|
216
213
|
greenText,
|
|
217
|
-
` ${cliCommand} data-gathering-scripts download-scripts --company ${
|
|
214
|
+
` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptType} `
|
|
218
215
|
);
|
|
216
|
+
if (autoUpdate) {
|
|
217
|
+
console.log("Updating...");
|
|
218
|
+
try {
|
|
219
|
+
// Get the latest version
|
|
220
|
+
const rcvdVersion = await downloadScriptsToHome(
|
|
221
|
+
scriptType,
|
|
222
|
+
undefined,
|
|
223
|
+
company,
|
|
224
|
+
client
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
console.log("Downloaded %s (v%s)", scriptVer.scriptType, rcvdVersion);
|
|
228
|
+
} catch (err) {
|
|
229
|
+
console.log("Download failed...");
|
|
230
|
+
console.log(err);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
219
233
|
console.log();
|
|
220
234
|
} else {
|
|
221
235
|
console.log(
|
|
@@ -234,7 +248,7 @@ async function checkScriptUpdates(args) {
|
|
|
234
248
|
) {
|
|
235
249
|
// We have at least one scriptType downloaded
|
|
236
250
|
} else {
|
|
237
|
-
console.error("
|
|
251
|
+
console.error("\nScripts available for download:");
|
|
238
252
|
listAvailableScripts(args);
|
|
239
253
|
return;
|
|
240
254
|
}
|
|
@@ -270,15 +284,16 @@ async function checkScriptUpdates(args) {
|
|
|
270
284
|
);
|
|
271
285
|
console.log(
|
|
272
286
|
greenText,
|
|
273
|
-
` ${cliCommand} data-gathering-scripts download-scripts --company ${
|
|
287
|
+
` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptVer.scriptType} \n`
|
|
274
288
|
);
|
|
275
289
|
if (autoUpdate) {
|
|
290
|
+
console.log("Updating...");
|
|
276
291
|
try {
|
|
277
292
|
// Get the latest version
|
|
278
293
|
const rcvdVersion = await downloadScriptsToHome(
|
|
279
294
|
scriptVer.scriptType,
|
|
280
295
|
undefined,
|
|
281
|
-
|
|
296
|
+
company,
|
|
282
297
|
client
|
|
283
298
|
);
|
|
284
299
|
|
|
@@ -292,6 +307,7 @@ async function checkScriptUpdates(args) {
|
|
|
292
307
|
console.log(err);
|
|
293
308
|
}
|
|
294
309
|
}
|
|
310
|
+
console.log();
|
|
295
311
|
} else {
|
|
296
312
|
console.log(
|
|
297
313
|
"\nmodule %s: Local=%s, is up to date",
|
|
@@ -309,7 +325,7 @@ async function autoCheckScriptUpdates(args) {
|
|
|
309
325
|
for (let i = 0; i < args.length - 1; i++) {
|
|
310
326
|
switch (args[i].toLowerCase()) {
|
|
311
327
|
case "--company":
|
|
312
|
-
|
|
328
|
+
company = args[++i];
|
|
313
329
|
break;
|
|
314
330
|
case "--script-type":
|
|
315
331
|
case "--scripttype":
|
|
@@ -326,17 +342,14 @@ async function autoCheckScriptUpdates(args) {
|
|
|
326
342
|
const currentScriptVersion = await getInstalledScriptVersion(scriptType);
|
|
327
343
|
if (!currentScriptVersion) {
|
|
328
344
|
console.log(
|
|
329
|
-
`Local scripts for type ${scriptType} not found. Please make sure they are
|
|
345
|
+
`Local scripts for type ${scriptType} not found. Please make sure they are downloaded.`
|
|
330
346
|
);
|
|
331
347
|
console.log("If the issue persists, please contact your OpsCompass rep.");
|
|
332
348
|
return;
|
|
333
349
|
}
|
|
334
350
|
|
|
335
351
|
const latestScriptVersion =
|
|
336
|
-
await client.dataGatheringScripts.checkScriptUpdates(
|
|
337
|
-
companySlug,
|
|
338
|
-
scriptType
|
|
339
|
-
);
|
|
352
|
+
await client.dataGatheringScripts.checkScriptUpdates(company, scriptType);
|
|
340
353
|
|
|
341
354
|
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
342
355
|
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
@@ -347,15 +360,15 @@ async function autoCheckScriptUpdates(args) {
|
|
|
347
360
|
console.log();
|
|
348
361
|
console.log(
|
|
349
362
|
greenText,
|
|
350
|
-
` ${cliCommand} data-gathering-scripts download-scripts --company ${
|
|
363
|
+
` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptType} `
|
|
351
364
|
);
|
|
352
365
|
console.log();
|
|
353
366
|
}
|
|
354
367
|
}
|
|
355
368
|
|
|
356
369
|
/**
|
|
357
|
-
* Manually runs the
|
|
358
|
-
*
|
|
370
|
+
* Manually runs the configured scripts. The base scripts has a runall.sh file.
|
|
371
|
+
* The runall.sh file runs all configured modules.
|
|
359
372
|
*/
|
|
360
373
|
async function manuallyRunScripts() {
|
|
361
374
|
try {
|
|
@@ -622,7 +622,7 @@ async function getMssqlEntitlements(args) {
|
|
|
622
622
|
|
|
623
623
|
async function createOracleDatabaseConfiguration(args) {
|
|
624
624
|
let name = undefined;
|
|
625
|
-
let optionalParams = {
|
|
625
|
+
let optionalParams = {};
|
|
626
626
|
for (let i = 0; i < args.length - 1; i++) {
|
|
627
627
|
switch (args[i].toLowerCase()) {
|
|
628
628
|
case "--monitoringconfigurationid":
|
|
@@ -674,6 +674,14 @@ async function updateMonitoringConfiguration(args) {
|
|
|
674
674
|
case "--configuration-name":
|
|
675
675
|
callParams.configurationName = args[++i];
|
|
676
676
|
break;
|
|
677
|
+
case "--autoupdateconfigurations":
|
|
678
|
+
case "--auto-update-configurations":
|
|
679
|
+
callParams.autoUpdateConfigurations = args[++i];
|
|
680
|
+
break;
|
|
681
|
+
case "--autoupdatescripts":
|
|
682
|
+
case "--auto-update-scripts":
|
|
683
|
+
callParams.autoUpdateScripts = args[++i];
|
|
684
|
+
break;
|
|
677
685
|
case "--datafileretaindays":
|
|
678
686
|
callParams.dataFileRetainDays = args[++i];
|
|
679
687
|
break;
|
|
@@ -1601,6 +1609,8 @@ async function printHelp() {
|
|
|
1601
1609
|
console.log("Parameters:");
|
|
1602
1610
|
console.log("--id [monitoring_configuration id]");
|
|
1603
1611
|
console.log("--name or --configuration-name (optional) [unique name]");
|
|
1612
|
+
console.log("--autoUpdateConfigurations (optional) [true | false]");
|
|
1613
|
+
console.log("--autoUpdateScripts (optional) [true | false]");
|
|
1604
1614
|
console.log(
|
|
1605
1615
|
"--dataFileRetainDays (optional) [determines how many days to retain encrypted output files locally]"
|
|
1606
1616
|
);
|
package/modules.js
CHANGED
|
@@ -2,9 +2,19 @@ const resources = require("./modules/resources.js");
|
|
|
2
2
|
const accounts = require("./modules/accounts.js");
|
|
3
3
|
const licenseManager = require("./modules/license-manager.js");
|
|
4
4
|
const compliance = require("./modules/compliance.js");
|
|
5
|
-
const dataGatheringScripts = require("./modules/data-gathering-scripts.js");
|
|
6
5
|
const defaults = require("./modules/defaults.js");
|
|
7
6
|
|
|
7
|
+
// Dynaimcally loaded modules - may be optional
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const dataGatheringScripts = fs.existsSync(
|
|
11
|
+
path.join(__dirname, "modules/data-gathering-scripts.js")
|
|
12
|
+
)
|
|
13
|
+
? require("./modules/data-gathering-scripts.js")
|
|
14
|
+
: {
|
|
15
|
+
requiresLogin: false,
|
|
16
|
+
description: "removed for security",
|
|
17
|
+
};
|
|
8
18
|
|
|
9
19
|
/* login acts like a module, even though it's special */
|
|
10
20
|
const login = require("./login.js");
|
|
@@ -14,7 +24,7 @@ module.exports = {
|
|
|
14
24
|
resources,
|
|
15
25
|
accounts,
|
|
16
26
|
compliance,
|
|
17
|
-
defaults,
|
|
27
|
+
defaults,
|
|
18
28
|
"license-manager": licenseManager,
|
|
19
|
-
"data-gathering-scripts": dataGatheringScripts
|
|
29
|
+
"data-gathering-scripts": dataGatheringScripts,
|
|
20
30
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opscompass/opscompass-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "Calls OpsCompass's APIs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"author": "opscompass",
|
|
16
16
|
"license": "SEE LICENSE IN license.txt",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@opscompass/opscompass-api": "^1.0.
|
|
18
|
+
"@opscompass/opscompass-api": "^1.0.25",
|
|
19
19
|
"adm-zip": "^0.5.9",
|
|
20
20
|
"axios": "^0.21.1",
|
|
21
21
|
"fs-extra": "^10.1.0",
|