@mindconnect/mindconnect-nodejs
Version:
MindConnect Library for NodeJS (community based)
81 lines • 4.75 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk = require("chalk");
const console_1 = require("console");
const fs = require("fs");
const path = require("path");
const __1 = require("../..");
const utils_1 = require("../../api/utils");
const command_utils_1 = require("./command-utils");
const color = command_utils_1.getColor("magenta");
exports.default = (program) => {
program
.command("get-diagnostic")
.alias("gd")
.option("-c, --config <agentconfig>", "config file with agent configuration", "agentconfig.json")
.option("-k, --passkey <passkey>", "passkey")
.option("-a, --all", "display all entries not just the last page")
.option("-j, --json", "json output")
.option("-t, --text", "text (raw) output")
.option("-v, --verbose", "verbose output")
.description(color("get diagnostic information *"))
.action(options => {
(() => __awaiter(void 0, void 0, void 0, function* () {
try {
if (!options.passkey) {
command_utils_1.errorLog("you have to provide a passkey (run mc gd --help for full description)", true);
}
command_utils_1.homeDirLog(options.verbose, color);
command_utils_1.proxyLog(options.verbose, color);
const auth = utils_1.loadAuth();
const setup = new __1.MindConnectSetup(auth.gateway, utils_1.decrypt(auth, options.passkey), auth.tenant);
const configFile = path.resolve(options.config);
if (!fs.existsSync(configFile)) {
throw new Error(`Can't find file ${configFile}`);
}
const configuration = require(configFile);
command_utils_1.verboseLog(`getting diagnostic data for agent with agent id ${color(configuration.content.clientId)}`, options.verbose);
const activations = yield setup.GetDiagnosticActivations();
console_1.log(`There are ${color(activations.content.length + " agent(s)")} registered for diagnostic`);
command_utils_1.verboseLog(JSON.stringify(activations.content), options.verbose);
function printDiagnosticInformation(diag, options) {
for (const iterator of diag) {
const element = iterator;
if (options.json) {
console_1.log(element);
}
else if (options.text) {
console_1.log(`${element.timestamp},${element.severity},${element.agentId},${element.correlationId},${element.state},${element.source},${element.message}`);
}
else {
console_1.log(`${chalk.cyanBright(element.timestamp)} ${chalk.greenBright(element.severity)} ${color(element.source)} ${element.message}`);
}
}
}
const information = yield setup.GetDiagnosticInformation(configuration.content.clientId, printDiagnosticInformation, options, !options.all);
console_1.log(`There are ${color(information.totalElements + " ")}total log entries`);
}
catch (err) {
command_utils_1.verboseLog(color("This operation requires additionaly the service credentials."), options.verbose);
command_utils_1.errorLog(err, options.verbose);
}
}))();
})
.on("--help", () => {
console_1.log(`\n Examples: \n`);
console_1.log(` mc gd -k mypasskey`);
console_1.log(` mc get-diagnostic --config someagent.json --passkey mypasskey`);
console_1.log(` mc get-diagnostic --passkey mypasskey --text --all > log.csv`);
command_utils_1.serviceCredentialLog();
});
};
//# sourceMappingURL=mc-get-diagnostic.js.map