@opscompass/opscompass-cli 1.0.14 → 1.0.15

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 CHANGED
@@ -1,10 +1,40 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const modules = require("./modules.js");
4
- const handleError = require('./error.js');
4
+ const handleError = require("./error.js");
5
5
  const { canReadStoredCredentials } = require("./credentials.js");
6
- const { versionCheck } = require("./updates.js");
7
- const { isLocal } = require("./environment/current.js");
6
+ const { versionCheck } = require("./updates.js");
7
+ const { isLocal, opscompassHome } = require("./environment/current.js");
8
+ const fs = require("fs");
9
+ const path = require("path");
10
+
11
+ let defaultParams = JSON.parse("{}");
12
+
13
+ function checkDefaults() {
14
+ const defaultsPath = path.join(opscompassHome, 'defaults.json');
15
+ let rawdata;
16
+ try {
17
+ rawdata = fs.readFileSync(defaultsPath);
18
+ defaultParams = JSON.parse(rawdata);
19
+ } catch (err) {
20
+ // We just want to catch the error, no logging necessary
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
+ companySlug = defaultParams.company;
27
+ company = defaultParams.company;
28
+ account = defaultParams.account;
29
+ monitoringConfig = defaultParams.monitoringConfiguration;
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.
33
+ * Other properties can still be added to the callParams object. Unneeded default parameters may be included, but are ignored by the API.
34
+ */
35
+ callParams = defaultParams;
36
+
37
+ }
8
38
 
9
39
  function requiresLogin() {
10
40
  console.log("You aren't logged in. Please run `opscompass login` to log in.");
@@ -18,7 +48,9 @@ function help() {
18
48
  console.log("OpsCompass Command-Line Interface");
19
49
  console.log();
20
50
  console.log("Command format:");
21
- console.log(" opscompass module action --parameter1 value --parameter2 value");
51
+ console.log(
52
+ " opscompass module action --parameter1 value --parameter2 value"
53
+ );
22
54
  console.log();
23
55
  console.log("Available modules:");
24
56
  console.log();
@@ -29,10 +61,13 @@ function help() {
29
61
  }
30
62
  }
31
63
 
32
- (async function() {
64
+ (async function () {
33
65
  if (!isLocal) {
34
66
  versionCheck();
35
67
  }
68
+
69
+ checkDefaults();
70
+
36
71
  const [proc, command, commandModule, ...args] = process.argv;
37
72
  const moduleName = commandModule?.toLowerCase() ?? "";
38
73
  if (moduleName === "" || moduleName === "help") {
@@ -1,7 +1,7 @@
1
1
  const { getOpsCompassClient } = require("../opscompass.js");
2
2
 
3
3
  async function listAccounts(args) {
4
- const callParams = {};
4
+
5
5
  for (let i = 0; i < args.length - 1; i++) {
6
6
  switch (args[i].toLowerCase()) {
7
7
  case "--company":
@@ -17,6 +17,14 @@ const { getCredentials } = require("../credentials.js");
17
17
  console.log(JSON.stringify(response, null, 2));
18
18
  }
19
19
 
20
+ async function transferNetworkDiscoveryMetadata(args) {
21
+ const callParams = genericMetadataTrasfer(args);
22
+ const client = await getOpsCompassClient();
23
+ const response = await client.compliance.transferNetworkDiscoveryMetadata(callParams.company, callParams.filePath);
24
+
25
+ console.log(JSON.stringify(response, null, 2));
26
+ }
27
+
20
28
  async function transferSqlServerDatabaseMetadata(args) {
21
29
  const callParams = genericMetadataTrasfer(args);
22
30
  const client = await getOpsCompassClient();
@@ -26,7 +34,7 @@ const { getCredentials } = require("../credentials.js");
26
34
  }
27
35
 
28
36
  function genericMetadataTrasfer(args) {
29
- const callParams = {};
37
+
30
38
  for (let i = 0; i < args.length - 1; i++) {
31
39
  switch (args[i].toLowerCase()) {
32
40
  case "--type":
@@ -122,7 +130,6 @@ const { getCredentials } = require("../credentials.js");
122
130
  }
123
131
 
124
132
  async function updateComplianceException(args) {
125
- const callParams = {};
126
133
  for (let i = 0; i < args.length - 1; i++) {
127
134
  switch (args[i].toLowerCase()) {
128
135
  case "--id":
@@ -153,7 +160,6 @@ const { getCredentials } = require("../credentials.js");
153
160
  let callParamsArray = [];
154
161
  let jsonIndex = args.indexOf('--json-updates');
155
162
  let idIndex = args.indexOf('--id');
156
- let callParams = {};
157
163
 
158
164
  /* Process bulk update with JSON */
159
165
  if (jsonIndex !== -1) {
@@ -244,6 +250,11 @@ const { getCredentials } = require("../credentials.js");
244
250
  console.log("--type [licensing | compliance]")
245
251
  console.log("--filePath [path] Path of the file to transfer to OpsCompass for processing.");
246
252
  console.log();
253
+ console.log("transfer-network-discovery-metadata", "Transfers OpsCompass Network Discovery metadata into OpsCompass for processing");
254
+ console.log("Parameters:");
255
+ console.log("--company [company_slug]");
256
+ console.log("--filePath [path] Path of the file to transfer to OpsCompass for processing.");
257
+ console.log();
247
258
  console.log("list-compliance-exceptions", "Gets list of policy exceptions and mitigations");
248
259
  console.log("Parameters:");
249
260
  console.log("--company [company_slug]");
@@ -294,6 +305,8 @@ const { getCredentials } = require("../credentials.js");
294
305
 
295
306
  const complianceModule = (action, ...args) => {
296
307
  switch (action?.toLowerCase() ?? "") {
308
+ case "transfer-network-discovery-metadata":
309
+ return transferNetworkDiscoveryMetadata(args);
297
310
  case "transfer-vmware-vsphere-metadata":
298
311
  return transferVMwareVsphereMetadata(args);
299
312
  case "transfer-oracle-database-metadata":
@@ -2,6 +2,9 @@ const { getOpsCompassClient } = require("../opscompass.js");
2
2
  const { ScriptType, cliCommand } = require("../environment/current.js");
3
3
  const { downloadScriptsToHome, findOrCreateScriptTypeFolder, SRC_FOLDER_NAME, BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH, getInstalledScriptVersion, previousScriptsDownloaded } = require("../lib/homeInteraction.js");
4
4
  const { canReadFile } = require("../lib/cliHelpers.js");
5
+ const { readDefaults, writeDefaults, checkDefaults} = require ("./defaults")
6
+ const { opscompassHome } = require("../environment/current.js");
7
+
5
8
  const semver = require("semver");
6
9
  const path = require("path");
7
10
  const fs = require("fs-extra");
@@ -12,8 +15,9 @@ const exec = util.promisify(require('child_process').exec);
12
15
  * Downloads data gathering scripts based on the given scriptType.
13
16
  */
14
17
 
18
+
15
19
  async function downloadScripts(args) {
16
- let companySlug = undefined;
20
+ const defaultsPath = `${opscompassHome}/defaults.json`
17
21
  let scriptType = undefined;
18
22
  let scriptVersion = undefined
19
23
  for (let i = 0; i < args.length - 1; i++) {
@@ -55,7 +59,6 @@ async function downloadScripts(args) {
55
59
  * Checks the installed scripts version against the latest scripts version for a given scriptType.
56
60
  */
57
61
  async function checkScriptUpdates(args) {
58
- let companySlug = undefined;
59
62
  let scriptType = undefined;
60
63
  for (let i = 0; i < args.length - 1; i++) {
61
64
  switch (args[i].toLowerCase()) {
@@ -99,7 +102,6 @@ async function checkScriptUpdates(args) {
99
102
  }
100
103
 
101
104
  async function autoCheckScriptUpdates(args) {
102
- let companySlug = undefined;
103
105
  let scriptType = undefined;
104
106
  for (let i = 0; i < args.length - 1; i++) {
105
107
  switch (args[i].toLowerCase()) {
@@ -0,0 +1,91 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { opscompassHome } = require("../environment/current.js");
4
+
5
+ const defaultsPath = path.join(opscompassHome, 'defaults.json');
6
+
7
+
8
+
9
+
10
+ async function readDefaults() {
11
+ let rawdata;
12
+ let defaultParams = JSON.parse("{}");
13
+ try {
14
+ rawdata = fs.readFileSync(defaultsPath);
15
+ defaultParams = JSON.parse(rawdata);
16
+ } catch (err) {
17
+ if (err.code === "ENOENT") {
18
+ console.error("\nDefaults file not found: %s", defaultsPath);
19
+ } else {
20
+ //console.error(err);
21
+ console.error("\nError reading defaults: %s", defaultsPath);
22
+ }
23
+ }
24
+ console.log(defaultParams, "\n");
25
+ return defaultParams;
26
+ }
27
+
28
+ async function writeDefaults(args) {
29
+ let defaults = {
30
+ company: undefined,
31
+ account: undefined,
32
+ monitoringConfiguration: undefined,
33
+ };
34
+
35
+ for (let i = 0; i < args.length - 1; i++) {
36
+ if (args[i]?.toLowerCase() === "--company") {
37
+ defaults.company = args[++i];
38
+ } else if (args[i].toLowerCase() === "--account") {
39
+ defaults.account = args[++i];
40
+ } else if (args[i].toLowerCase() === "--monitoring-configuration-id") {
41
+ defaults.monitoringConfiguration = args[++i];
42
+ }
43
+ }
44
+
45
+ const data = JSON.stringify(defaults);
46
+
47
+ fs.writeFileSync(defaultsPath, data);
48
+ console.log("Your default configuration is:");
49
+ readDefaults();
50
+ }
51
+
52
+ function printHelp() {
53
+ console.log("Actions available for defaults:");
54
+ console.log();
55
+ console.log("list-defaults", "See current default settings.");
56
+ console.log("Parameters:");
57
+ console.log("None");
58
+ console.log();
59
+ console.log(
60
+ "set-defaults",
61
+ "Allows you to set default parameter such as company, account, or monitoring configuration."
62
+ );
63
+ console.log("Parameters:");
64
+ console.log(
65
+ "--company 'value' --account 'value' --monitoring-configuration-id 'value'"
66
+ );
67
+ console.log("e.g. opscompass defaults set-defaults --company 'opscompass' --account '231' --monitoring-configuration-id '34232'" )
68
+ console.log();
69
+ }
70
+
71
+ const defaultsModule = (action, ...args) => {
72
+ switch (action?.toLowerCase() ?? "") {
73
+ case "list-defaults":
74
+ return readDefaults();
75
+ case "set-defaults":
76
+ return writeDefaults(args);
77
+ case "help":
78
+ case "":
79
+ return printHelp();
80
+ default:
81
+ console.log("Unknown command:", action);
82
+ return printHelp();
83
+ }
84
+ };
85
+
86
+ defaultsModule.requiresLogin = false;
87
+ defaultsModule.description =
88
+ "View and set default parameters for OpsCompass CLI.";
89
+
90
+ module.exports = { readDefaults, writeDefaults, defaultsPath };
91
+ module.exports = defaultsModule;
@@ -3,7 +3,6 @@ const { setArgumentArrays } = require("../lib/cliHelpers.js");
3
3
  const { getOpsCompassClient } = require("../opscompass.js");
4
4
 
5
5
  async function listMonitoringConfigurations(args) {
6
- let company = undefined;
7
6
  for (let i = 0; i < args.length - 1; i++) {
8
7
  switch (args[i].toLowerCase()) {
9
8
  case "--company":
@@ -82,11 +81,33 @@ async function deleteOracleDatabaseConfiguration(args){
82
81
  console.log(JSON.stringify(response, null, 2));
83
82
  }
84
83
 
84
+ async function deleteMssqlEntitlements(args){
85
+ args = setArgumentArrays(["--id"], args);
86
+
87
+ let recordIds = undefined;
88
+ let company = undefined;
89
+ for (let i = 0; i < args.length - 1; i++) {
90
+ switch (args[i].toLowerCase()) {
91
+ case "--company":
92
+ company = args[++i];
93
+ break;
94
+ case "--id":
95
+ recordIds = args[++i];
96
+ break;
97
+ }
98
+ }
99
+
100
+ const client = await getOpsCompassClient();
101
+ const response = await client.licenseManager.deleteMssqlEntitlements(company, recordIds);
102
+
103
+ console.log(JSON.stringify(response, null, 2));
104
+ }
105
+
85
106
  async function listOracleDatabaseConfigurations(args) {
86
- let monitoringConfigurationId = undefined;
87
107
  for (let i = 0; i < args.length - 1; i++) {
88
108
  switch (args[i].toLowerCase()) {
89
109
  case "--monitoringconfigurationid":
110
+ case "--monitoring-configuration-id":
90
111
  monitoringConfigurationId = args[++i];
91
112
  break;
92
113
  }
@@ -155,7 +176,6 @@ async function getMonitoringConfiguration(args) {
155
176
  }
156
177
 
157
178
  async function createMonitoringConfiguration(args) {
158
- let company = undefined;
159
179
  let name = undefined;
160
180
  for (let i = 0; i < args.length - 1; i++) {
161
181
  switch (args[i].toLowerCase()) {
@@ -179,6 +199,7 @@ async function listVCenterConfigurations(args) {
179
199
  for (let i = 0; i < args.length - 1; i++) {
180
200
  switch (args[i].toLowerCase()) {
181
201
  case "--monitoringconfigurationid":
202
+ case "--monitoring-configuration-id":
182
203
  id = args[++i];
183
204
  break;
184
205
  }
@@ -213,6 +234,7 @@ async function createVCenterConfiguration(args) {
213
234
  for (let i = 0; i < args.length - 1; i++) {
214
235
  switch (args[i].toLowerCase()) {
215
236
  case "--monitoringconfigurationid":
237
+ case "--monitoring-configuration-id":
216
238
  id = args[++i];
217
239
  break;
218
240
  case "--name":
@@ -310,6 +332,22 @@ async function getMsqlConfiguration(args) {
310
332
  console.log(JSON.stringify(getMsqlConfig, null, 2));
311
333
  }
312
334
 
335
+ async function getMssqlEntitlements(args) {
336
+ let company = undefined;
337
+ for (let i = 0; i < args.length - 1; i++) {
338
+ switch (args[i].toLowerCase()) {
339
+ case "--company":
340
+ company = args[++i];
341
+ break;
342
+ }
343
+ }
344
+
345
+ const client = await getOpsCompassClient();
346
+ const mssqlEntitlements = await client.licenseManager.getMssqlEntitlements(company);
347
+
348
+ console.log(JSON.stringify(mssqlEntitlements, null, 2));
349
+ }
350
+
313
351
  async function createOracleDatabaseConfiguration(args) {
314
352
  let id = undefined;
315
353
  let name = undefined;
@@ -317,6 +355,7 @@ async function createOracleDatabaseConfiguration(args) {
317
355
  for (let i = 0; i < args.length - 1; i++) {
318
356
  switch (args[i].toLowerCase()) {
319
357
  case "--monitoringconfigurationid":
358
+ case "--monitoring-configuration-id":
320
359
  id = args[++i];
321
360
  break;
322
361
  case "--name":
@@ -342,7 +381,6 @@ async function updateMonitoringConfiguration(args) {
342
381
  // Prep any arguments that are arrays
343
382
  args = setArgumentArrays(["--mailFrom", "--emailTo"], args);
344
383
 
345
- const callParams = {};
346
384
  for (let i = 0; i < args.length - 1; i++) {
347
385
  switch (args[i].toLowerCase()) {
348
386
  case "--id":
@@ -387,7 +425,6 @@ async function updateMonitoringConfiguration(args) {
387
425
  }
388
426
 
389
427
  async function updateOracleDatabaseConfiguration(args) {
390
- const callParams = {};
391
428
  for (let i = 0; i < args.length - 1; i++) {
392
429
  switch (args[i].toLowerCase()) {
393
430
  case "--id":
@@ -456,8 +493,7 @@ async function updateOracleDatabaseConfigurations(args) {
456
493
 
457
494
 
458
495
  async function updateVCenterConfiguration(args) {
459
- const callParams = {
460
- };
496
+
461
497
  for (let i = 0; i < args.length - 1; i++) {
462
498
  switch (args[i].toLowerCase()) {
463
499
  case "--id":
@@ -490,7 +526,6 @@ async function updateVCenterConfiguration(args) {
490
526
  }
491
527
 
492
528
  async function updateVCenterConfigurations(args) {
493
-
494
529
  let callParamsArray = [];
495
530
  let jsonIndex = args.indexOf('--json-updates')
496
531
  let idIndex = args.indexOf('--id')
@@ -502,135 +537,250 @@ async function updateVCenterConfigurations(args) {
502
537
  callParamsArray = JSON.parse(jsonString);
503
538
  } else if (idIndex !== -1) {
504
539
  /* If no '--json-update' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
505
- for(let i = 0; i < args.length - 1; i++) {
506
- if(args[i] === '--id') {
507
- /* Reset callParams object when a second id is encountered */
508
- callParams = {
540
+ for(let i = 0; i < args.length - 1; i++) {
541
+ if(args[i] === '--id') {
542
+ /* Reset callParams object when a second id is encountered */
543
+ callParams = {
509
544
  };
510
- /* if theres an existing callParams object, toss it into the array and move on. */
511
- callParamsArray.push(callParams)
512
- /* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
513
- callParams.id = args[i + 1];
514
- } else if(args[i].toLowerCase() === '--configurationname' || args[i].toLowerCase() === '--configuration-name' || args[i].toLowerCase() === "--name" ) {
515
- callParams.configurationName = args[i + 1];
545
+ /* if theres an existing callParams object, toss it into the array and move on. */
546
+ callParamsArray.push(callParams)
547
+ /* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
548
+ callParams.id = args[i + 1];
549
+ } else if(args[i].toLowerCase() === '--configurationname' || args[i].toLowerCase() === '--configuration-name' || args[i].toLowerCase() === "--name" ) {
550
+ callParams.configurationName = args[i + 1];
516
551
  } else if(args[i].toLowerCase() === '--action') {
517
552
  if (callParams.actions === undefined) callParams.actions = [];
518
553
  callParams.actions.push(args[i + 1]);
519
- } else if(args[i.toLowerCase] === '--connection') {
520
- callParams.connection = args[i + 1];
521
- } else if(args[i.toLowerCase] === '--user') {
522
- callParams.user = args[i + 1];
523
- } else if(args[i.toLowerCase] === '--password') {
524
- callParams.password = args[i + 1];
554
+ } else if(args[i.toLowerCase] === '--connection') {
555
+ callParams.connection = args[i + 1];
556
+ } else if(args[i.toLowerCase] === '--user') {
557
+ callParams.user = args[i + 1];
558
+ } else if(args[i.toLowerCase] === '--password') {
559
+ callParams.password = args[i + 1];
525
560
  }
526
- }
527
- } else {
528
- console.warn("Invalid input, please see help for examples.")
529
- return console.log("")
530
561
  }
562
+ } else {
563
+ console.warn("Invalid input, please see help for examples.")
564
+ return console.log("")
565
+ }
531
566
 
532
567
  /* Call the API and print to console */
533
- const client = await getOpsCompassClient();
534
- const vCenterConfigurations = await client.licenseManager.updateVCenterConfigurations(callParamsArray);
535
- console.log(JSON.stringify(vCenterConfigurations, null, 2));
568
+ const client = await getOpsCompassClient();
569
+ const vCenterConfigurations = await client.licenseManager.updateVCenterConfigurations(callParamsArray);
570
+ console.log(JSON.stringify(vCenterConfigurations, null, 2));
571
+ }
572
+
573
+ async function updateMsqlConfiguration(args) {
574
+
575
+ for (let i = 0; i < args.length - 1; i++) {
576
+ switch (args[i].toLowerCase()) {
577
+ case "--id":
578
+ callParams.id = args[++i];
579
+ break;
580
+ case "--name":
581
+ case "--configurationname":
582
+ case "--configuration-name":
583
+ callParams.configurationName = args[++i];
584
+ break;
585
+ case "--action":
586
+ if (callParams.actions === undefined) callParams.actions = [];
587
+ callParams.actions.push(args[++i]);
588
+ break;
589
+ case "--server":
590
+ callParams.server = args[++i];
591
+ break;
592
+ case "--user":
593
+ callParams.user = args[++i];
594
+ break;
595
+ case "--password":
596
+ callParams.password = args[++i];
597
+ break;
598
+ }
536
599
  }
600
+ const client = await getOpsCompassClient();
601
+ const msqlConfiguration = await client.licenseManager.updateMsqlConfiguration(callParams.id, callParams);
602
+ console.log(JSON.stringify(msqlConfiguration, null, 2));
603
+ }
537
604
 
538
- async function updateMsqlConfiguration(args) {
539
- const callParams = {
540
- };
541
- for (let i = 0; i < args.length - 1; i++) {
542
- switch (args[i].toLowerCase()) {
543
- case "--id":
544
- callParams.id = args[++i];
545
- break;
546
- case "--name":
547
- case "--configurationname":
548
- case "--configuration-name":
549
- callParams.configurationName = args[++i];
550
- break;
551
- case "--action":
552
- if (callParams.actions === undefined) callParams.actions = [];
553
- callParams.actions.push(args[++i]);
554
- break;
555
- case "--server":
556
- callParams.server = args[++i];
557
- break;
558
- case "--user":
559
- callParams.user = args[++i];
560
- break;
561
- case "--password":
562
- callParams.password = args[++i];
563
- break;
564
- }
605
+
606
+ async function updateMsqlConfigurations(args) {
607
+
608
+ let callParamsArray = [];
609
+ let jsonIndex = args.indexOf('--json-updates')
610
+ let idIndex = args.indexOf('--id')
611
+ let callParams = {};
612
+
613
+ /* Process bulk update with JSON */
614
+ if (jsonIndex !== -1) {
615
+ const jsonString = args[jsonIndex + 1];
616
+ callParamsArray = JSON.parse(jsonString);
617
+
618
+ /* If no '--json-updates' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
619
+ } else if (idIndex !== -1) {
620
+ for(let i = 0; i < args.length - 1; i++) {
621
+ if(args[i] === '--id') {
622
+ /* Reset callParams object when a second id is encountered */
623
+ callParams = {
624
+ };
625
+ /* if theres an existing callParams object, toss it into the array and move on. */
626
+ callParamsArray.push(callParams)
627
+ /* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
628
+ callParams.id = args[i + 1];
629
+ } else if(args[i].toLowerCase() === '--configurationname' || args[i].toLowerCase() === '--configuration-name' || args[i].toLowerCase() === "--name" ) {
630
+ callParams.configurationName = args[i + 1];
631
+ } else if(args[i].toLowerCase() === '--action') {
632
+ if (callParams.actions === undefined) callParams.actions = [];
633
+ callParams.actions.push(args[i + 1]);
634
+ } else if(args[i].toLowerCase() === '--server') {
635
+ callParams.server = args[i + 1];
636
+ } else if(args[i].toLowerCase() === '--user') {
637
+ callParams.user = args[i + 1];
638
+ } else if(args[i].toLowerCase() === '--password') {
639
+ callParams.password = args[i + 1];
640
+ }
641
+ }
642
+ } else {
643
+ console.warn("Invalid input, please see help for examples.")
644
+ return console.log("")
565
645
  }
646
+
647
+ /* Call the API and print to console */
566
648
  const client = await getOpsCompassClient();
567
- const msqlConfiguration = await client.licenseManager.updateMsqlConfiguration(callParams.id, callParams);
568
- console.log(JSON.stringify(msqlConfiguration, null, 2));
649
+ const msqlConfigurations = await client.licenseManager.updateMsqlConfigurations(callParamsArray);
650
+ console.log(JSON.stringify(msqlConfigurations, null, 2));
569
651
  }
570
652
 
653
+ async function getMssqlEntitlementComponents(args) {
654
+ let company = undefined;
655
+ for (let i = 0; i < args.length - 1; i++) {
656
+ switch (args[i].toLowerCase()) {
657
+ case "--company":
658
+ company = args[++i];
659
+ break;
660
+ }
661
+ }
571
662
 
572
- async function updateMsqlConfigurations(args) {
663
+ const client = await getOpsCompassClient();
664
+ const entitlementComponents = await client.licenseManager.getMssqlEntitlementComponents(company);
665
+ console.log(JSON.stringify(entitlementComponents, null, 2));
666
+ }
573
667
 
574
- let callParamsArray = [];
575
- let jsonIndex = args.indexOf('--json-updates')
576
- let idIndex = args.indexOf('--id')
577
- let callParams = {};
578
-
579
- /* Process bulk update with JSON */
580
- if (jsonIndex !== -1) {
581
- const jsonString = args[jsonIndex + 1];
582
- callParamsArray = JSON.parse(jsonString);
583
-
584
- /* If no '--json-updates' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
585
- } else if (idIndex !== -1) {
586
- for(let i = 0; i < args.length - 1; i++) {
587
- if(args[i] === '--id') {
588
- /* Reset callParams object when a second id is encountered */
589
- callParams = {
590
- };
591
- /* if theres an existing callParams object, toss it into the array and move on. */
592
- callParamsArray.push(callParams)
593
- /* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
594
- callParams.id = args[i + 1];
595
- } else if(args[i].toLowerCase() === '--configurationname' || args[i].toLowerCase() === '--configuration-name' || args[i].toLowerCase() === "--name" ) {
596
- callParams.configurationName = args[i + 1];
597
- } else if(args[i].toLowerCase() === '--action') {
598
- if (callParams.actions === undefined) callParams.actions = [];
599
- callParams.actions.push(args[i + 1]);
600
- } else if(args[i].toLowerCase() === '--server') {
601
- callParams.server = args[i + 1];
602
- } else if(args[i].toLowerCase() === '--user') {
603
- callParams.user = args[i + 1];
604
- } else if(args[i].toLowerCase() === '--password') {
605
- callParams.password = args[i + 1];
606
- }
607
- }
608
- } else {
609
- console.warn("Invalid input, please see help for examples.")
610
- return console.log("")
611
- }
612
-
613
- /* Call the API and print to console */
614
- const client = await getOpsCompassClient();
615
- const msqlConfigurations = await client.licenseManager.updateMsqlConfigurations(callParamsArray);
616
- console.log(JSON.stringify(msqlConfigurations, null, 2));
668
+ async function createMssqlEntitlement(args) {
669
+ let company = undefined;
670
+ let newRecord = {
671
+ purchaseDate: undefined,
672
+ quantity: undefined,
673
+ supportStart: undefined,
674
+ supportEnd: undefined,
675
+ msqlProduct: undefined,
676
+ msqlEdition: undefined,
677
+ msqlVersion: undefined,
678
+ msqlMetric: undefined
679
+ };
680
+ for (let i = 0; i < args.length - 1; i++) {
681
+ switch (args[i].toLowerCase()) {
682
+ case "--company":
683
+ company = args[++i];
684
+ break;
685
+ case "--purchase-date":
686
+ case "--purchasedate":
687
+ newRecord.purchaseDate = args[++i];
688
+ break;
689
+ case "--quantity":
690
+ newRecord.quantity = args[++i];
691
+ break;
692
+ case "--support-start":
693
+ case "--supportstart":
694
+ newRecord.supportStart = args[++i];
695
+ break;
696
+ case "--support-end":
697
+ case "--supportend":
698
+ newRecord.supportEnd = args[++i];
699
+ break;
700
+ case "--mssql-product":
701
+ case "--mssqlproduct":
702
+ newRecord.msqlProduct = args[++i];
703
+ break;
704
+ case "--mssql-edition":
705
+ case "--mssqledition":
706
+ newRecord.msqlEdition = args[++i];
707
+ break;
708
+ case "--mssql-version":
709
+ case "--mssqlversion":
710
+ newRecord.msqlVersion = args[++i];
711
+ break;
712
+ case "--mssql-metric":
713
+ case "--mssqlmetric":
714
+ newRecord.msqlMetric = args[++i];
715
+ break;
617
716
  }
618
-
619
- async function getMssqlEntitlementComponents(args) {
620
- let company = undefined;
621
- for (let i = 0; i < args.length - 1; i++) {
622
- switch (args[i].toLowerCase()) {
623
- case "--company":
624
- company = args[++i];
625
- break;
626
- }
717
+ }
718
+
719
+ const client = await getOpsCompassClient();
720
+ const response = await client.licenseManager.createMssqlEntitlements(company, [newRecord]);
721
+ console.log(JSON.stringify(response, null, 2));
722
+ }
723
+
724
+ async function updateMssqlEntitlement(args) {
725
+ let company = undefined;
726
+ let updateRecord = {
727
+ id: undefined,
728
+ purchaseDate: undefined,
729
+ quantity: undefined,
730
+ supportStart: undefined,
731
+ supportEnd: undefined,
732
+ msqlProduct: undefined,
733
+ msqlEdition: undefined,
734
+ msqlVersion: undefined,
735
+ msqlMetric: undefined
736
+ };
737
+ for (let i = 0; i < args.length - 1; i++) {
738
+ switch (args[i].toLowerCase()) {
739
+ case "--company":
740
+ company = args[++i];
741
+ break;
742
+ case "--id":
743
+ updateRecord.id = args[++i];
744
+ break;
745
+ case "--purchase-date":
746
+ case "--purchasedate":
747
+ updateRecord.purchaseDate = args[++i];
748
+ break;
749
+ case "--quantity":
750
+ updateRecord.quantity = args[++i];
751
+ break;
752
+ case "--support-start":
753
+ case "--supportstart":
754
+ updateRecord.supportStart = args[++i];
755
+ break;
756
+ case "--support-end":
757
+ case "--supportend":
758
+ updateRecord.supportEnd = args[++i];
759
+ break;
760
+ case "--mssql-product":
761
+ case "--mssqlproduct":
762
+ updateRecord.msqlProduct = args[++i];
763
+ break;
764
+ case "--mssql-edition":
765
+ case "--mssqledition":
766
+ updateRecord.msqlEdition = args[++i];
767
+ break;
768
+ case "--mssql-version":
769
+ case "--mssqlversion":
770
+ updateRecord.msqlVersion = args[++i];
771
+ break;
772
+ case "--mssql-metric":
773
+ case "--mssqlmetric":
774
+ updateRecord.msqlMetric = args[++i];
775
+ break;
627
776
  }
628
-
629
- const client = await getOpsCompassClient();
630
- const entitlementComponents = await client.licenseManager.getMssqlEntitlementComponents(company);
631
- console.log(JSON.stringify(entitlementComponents, null, 2));
632
777
  }
633
778
 
779
+ const client = await getOpsCompassClient();
780
+ const response = await client.licenseManager.updateMssqlEntitlements(company, [updateRecord]);
781
+ console.log(JSON.stringify(response, null, 2));
782
+ }
783
+
634
784
  async function printHelp() {
635
785
  console.log("Actions available for license-manager:");
636
786
  console.log();
@@ -655,7 +805,7 @@ async function printHelp() {
655
805
  console.log();
656
806
  console.log("list-oracle-database-configurations", "Lists all of the oracle database configurations associated with the given monitoring configuration");
657
807
  console.log("Parameters:");
658
- console.log("--monitoringConfigurationId [monitoring_configuration_id]");
808
+ console.log("--monitoring-configuration-id [monitoring_configuration_id]");
659
809
  console.log();
660
810
  console.log("get-oracle-database-configuration", "Get a single oracle database configuration associated with the given monitoring configuration");
661
811
  console.log("Parameters:");
@@ -663,7 +813,7 @@ async function printHelp() {
663
813
  console.log();
664
814
  console.log("list-vcenter-configurations", "Lists all of the vcenter configurations associated with the given monitoring configuration");
665
815
  console.log("Parameters:");
666
- console.log("--monitoringConfigurationId [monitoring_configuration_id]");
816
+ console.log("--monitoring-configuration-id [monitoring_configuration_id]");
667
817
  console.log();
668
818
  console.log("get-vcenter-configuration", "Get a single vcenter configuration associated with the given monitoring configuration");
669
819
  console.log("Parameters:");
@@ -671,7 +821,7 @@ async function printHelp() {
671
821
  console.log();
672
822
  console.log("create-vcenter-configuration", "Create a single vcenter configuration associated with the given monitoring configuration.");
673
823
  console.log("Parameters:");
674
- console.log("--monitoringConfigurationId [monitoring_configuration_id]");
824
+ console.log("--monitoring-configuration-id [monitoring_configuration_id]");
675
825
  console.log("--name [unique name]");
676
826
  console.log(`--action (optional) pass multiple times to define which actions this connection can take e.g. --action "skip" --action "vmotion"`);
677
827
  console.log("--connection (optional) [the hostname or ip address]");
@@ -697,7 +847,7 @@ async function printHelp() {
697
847
  console.log();
698
848
  console.log("create-oracle-database-configuration", "Create a single oracle database configuration associated with the given monitoring configuration.");
699
849
  console.log("Parameters:");
700
- console.log("--monitoringConfigurationId [monitoring_configuration_id]");
850
+ console.log("--monitoring-configuration-id [monitoring_configuration_id]");
701
851
  console.log("--name [unique name]");
702
852
  console.log(`--action (optional) pass multiple times to define which actions this connection can take e.g. --action "skip" --action "dbcompliance"`);
703
853
  console.log("--connectionString (optional) [the database connection string]");
@@ -801,6 +951,41 @@ async function printHelp() {
801
951
  console.log("Parameters:");
802
952
  console.log("--company [company_slug]");
803
953
  console.log();
954
+ console.log("create-mssql-entitlement", "Creates a Mssql Entitlement record.");
955
+ console.log("Parameters:");
956
+ console.log("--company [company_slug]");
957
+ console.log("--purchase-date [Date] the date of purchase.");
958
+ console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to set August 8th, 2022 at 17:00 UTC.");
959
+ console.log("--quantity [number] the number for this entry");
960
+ console.log("--support-start (optional) [Date] the date when support started");
961
+ console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to set August 8th, 2022 at 17:00 UTC.");
962
+ console.log("--support-end (optional) [Date] the date when support ended");
963
+ console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to set August 8th, 2022 at 17:00 UTC.");
964
+ console.log("--mssql-product [string] the slug of the associated mssql product");
965
+ console.log("--mssql-edition [string] the slug of the associated mssql edition");
966
+ console.log("--mssql-version [string] the slug of the associated mssql version");
967
+ console.log("--mssql-metric [string] the slug of the associated mssql metric");
968
+ console.log();
969
+ console.log("update-mssql-entitlement", "Creates a Mssql Entitlement record.");
970
+ console.log("Parameters:");
971
+ console.log("--company [company_slug]");
972
+ console.log("--id [number] the mssql entitlement record id");
973
+ console.log("--purchase-date [Date] the date of purchase.");
974
+ console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to set August 8th, 2022 at 17:00 UTC.");
975
+ console.log("--quantity [number] the number for this entry");
976
+ console.log("--support-start (optional) [Date] the date when support started");
977
+ console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to set August 8th, 2022 at 17:00 UTC.");
978
+ console.log("--support-end (optional) [Date] the date when support ended");
979
+ console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to set August 8th, 2022 at 17:00 UTC.");
980
+ console.log("--mssql-product [string] the slug of the associated mssql product");
981
+ console.log("--mssql-edition [string] the slug of the associated mssql edition");
982
+ console.log("--mssql-version [string] the slug of the associated mssql version");
983
+ console.log("--mssql-metric [string] the slug of the associated mssql metric");
984
+ console.log();
985
+ console.log("delete-mssql-entitlements", "Deletes Mssql Entitlement records.");
986
+ console.log("Parameters:");
987
+ console.log("--company [string] The slug of the company.");
988
+ console.log("--id [string] Use parameter multiple times to delete multiple records.");
804
989
  }
805
990
 
806
991
  const licenseManagerModule = (action, ...args) => {
@@ -825,6 +1010,8 @@ const licenseManagerModule = (action, ...args) => {
825
1010
  return createMsqlConfiguration(args);
826
1011
  case "get-msql-configuration":
827
1012
  return getMsqlConfiguration(args);
1013
+ case "get-mssql-entitlements":
1014
+ return getMssqlEntitlements(args);
828
1015
  case "get-oracle-database-configuration":
829
1016
  return getOracleDatabaseConfiguration(args);
830
1017
  case "list-oracle-database-configurations":
@@ -855,6 +1042,12 @@ const licenseManagerModule = (action, ...args) => {
855
1042
  return updateMsqlConfigurations(args);
856
1043
  case "get-mssql-entitlement-components":
857
1044
  return getMssqlEntitlementComponents(args);
1045
+ case "create-mssql-entitlement":
1046
+ return createMssqlEntitlement(args);
1047
+ case "update-mssql-entitlement":
1048
+ return updateMssqlEntitlement(args);
1049
+ case "delete-mssql-entitlements":
1050
+ return deleteMssqlEntitlements(args);
858
1051
  case "help":
859
1052
  case "":
860
1053
  return printHelp();
@@ -4,11 +4,13 @@ const actionMap = {
4
4
  "get": "get",
5
5
  "get-compliance": "getCompliance",
6
6
  "get-drift": "getDrift",
7
+ "get-tags": "getTags",
8
+ "add-tags": "addTags",
9
+ "remove-tags": "removeTags",
7
10
  "list": "list",
8
11
  };
9
12
 
10
13
  async function get(action, args) {
11
- const callParams = {};
12
14
  for (let i = 0; i < args.length - 1; i++) {
13
15
  switch (args[i].toLowerCase()) {
14
16
  case "--company":
@@ -60,7 +62,6 @@ async function get(action, args) {
60
62
  }
61
63
 
62
64
  async function list(args) {
63
- const callParams = {};
64
65
  for (let i = 0; i < args.length - 1; i++) {
65
66
  switch (args[i].toLowerCase()) {
66
67
  case "--company":
@@ -108,6 +109,16 @@ async function list(args) {
108
109
  callParams.resourceTypes = args[++i];
109
110
  }
110
111
  break;
112
+ case "--tags":
113
+ if (typeof callParams.tags === "string") {
114
+ callParams.tags = [callParams.tags];
115
+ }
116
+ if (Array.isArray(callParams.tags)) {
117
+ callParams.tags.push(args[++i]);
118
+ } else {
119
+ callParams.tags = args[++i];
120
+ }
121
+ break;
111
122
  case "--resource-creation-date-beginning":
112
123
  case "--resourcecreationdatebeginning":
113
124
  callParams.resourceCreationDateBeginning = args[++i];
@@ -135,6 +146,35 @@ async function list(args) {
135
146
  console.log(JSON.stringify(resource, null, 2));
136
147
  }
137
148
 
149
+ async function tags(action, args) {
150
+ const callData = {};
151
+ for (let i = 0; i < args.length - 1; i++) {
152
+ switch (args[i].toLowerCase()) {
153
+ case "--company":
154
+ callData.company = args[++i];
155
+ break;
156
+ case "--id":
157
+ callData.id = args[++i];
158
+ break;
159
+ case "--resourceid":
160
+ case "--resource-id":
161
+ callData.resourceId = args[++i];
162
+ break;
163
+ case "--tag":
164
+ if (Array.isArray(callData.tags)) {
165
+ callData.tags.push(args[++i]);
166
+ } else {
167
+ callData.tags = [args[++i]];
168
+ }
169
+ break;
170
+ }
171
+ }
172
+
173
+ const client = await getOpsCompassClient();
174
+ const resource = await client.resources[actionMap[action]](callData);
175
+ console.log(JSON.stringify(resource, null, 2));
176
+ }
177
+
138
178
  async function getUsageAnalytics(args) {
139
179
  let resourceId = undefined;
140
180
  let metricType = undefined;
@@ -219,6 +259,12 @@ async function printHelp() {
219
259
  console.log("--concern \"concern name\"");
220
260
  console.log("--type [configuration_alert | security_alert]");
221
261
  console.log();
262
+ console.log("get-tags", "Gets tags attached to a resource.");
263
+ console.log("Parameters:");
264
+ console.log("--company [company_id]");
265
+ console.log("--id [12345]");
266
+ console.log("--resource-id [cloud-resource-id]");
267
+ console.log();
222
268
  console.log("list", "Lists a set of resources that match any given criteria.");
223
269
  console.log("Parameters:");
224
270
  console.log("--company [company_id]");
@@ -226,12 +272,27 @@ async function printHelp() {
226
272
  console.log("--cloud-providers [aws | azure | gcp | microsoft365]");
227
273
  console.log("--resource-types [resource-type-name]");
228
274
  console.log("--region-ids [region-id]");
275
+ console.log("--tags [tag-value]")
229
276
  console.log("--resource-creation-date-beginning [\"2020-11-11 00:00:00.000\"]");
230
277
  console.log("--resource-creation-date-end [\"2021-11-11 00:00:00.000\"]");
231
278
  console.log("--open-compliance-issues [true | false]");
232
279
  console.log("--unacknowledged-changes [true | false]");
233
280
  console.log("--skip [12345]");
234
281
  console.log();
282
+ console.log("add-tags", "Attaches one or more tags to a resource.");
283
+ console.log("Parameters:");
284
+ console.log("--company [company_id]");
285
+ console.log("--id [12345]");
286
+ console.log("--resource-id [cloud-resource-id]");
287
+ console.log("--tag [tag-value]");
288
+ console.log();
289
+ console.log("remove-tags", "Removes one or more tags to a resource.");
290
+ console.log("Parameters:");
291
+ console.log("--company [company_id]");
292
+ console.log("--id [12345]");
293
+ console.log("--resource-id [cloud-resource-id]");
294
+ console.log("--tag [tag-value]");
295
+ console.log();
235
296
  console.log("get-usage-analytics", "Calculates the resource usage analytics for given criteria.");
236
297
  console.log("Parameters:");
237
298
  console.log("--id [resource_id]");
@@ -253,7 +314,11 @@ const resourcesModule = (action, ...args) => {
253
314
  case "get":
254
315
  case "get-compliance":
255
316
  case "get-drift":
317
+ case "get-tags":
256
318
  return get(action, args);
319
+ case "add-tags":
320
+ case "remove-tags":
321
+ return tags(action, args);
257
322
  case "list":
258
323
  return list(args)
259
324
  case "get-usage-analytics":
package/modules.js CHANGED
@@ -3,6 +3,7 @@ const accounts = require("./modules/accounts.js");
3
3
  const licenseManager = require("./modules/license-manager.js");
4
4
  const compliance = require("./modules/compliance.js");
5
5
  const dataGatheringScripts = require("./modules/data-gathering-scripts.js");
6
+ const defaults = require("./modules/defaults.js");
6
7
 
7
8
 
8
9
  /* login acts like a module, even though it's special */
@@ -12,7 +13,8 @@ module.exports = {
12
13
  login,
13
14
  resources,
14
15
  accounts,
15
- compliance,
16
+ compliance,
17
+ defaults,
16
18
  "license-manager": licenseManager,
17
19
  "data-gathering-scripts": dataGatheringScripts
18
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opscompass/opscompass-cli",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
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.14",
18
+ "@opscompass/opscompass-api": "^1.0.15",
19
19
  "adm-zip": "^0.5.9",
20
20
  "axios": "^0.21.1",
21
21
  "fs-extra": "^10.1.0",