UNPKG

@mindconnect/mindconnect-nodejs

Version:

NodeJS Library for Siemens Insights Hub Connectivity - TypeScript SDK for Insights Hub and Industrial IoT - Command Line Interface - Insights Hub Development Proxy (Siemens Insights Hub was formerly known as MindSphere)

90 lines 5.1 kB
"use strict"; 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 utils_1 = require("../../api/utils"); const command_utils_1 = require("./command-utils"); let color = (0, command_utils_1.getColor)("magenta"); exports.default = (program) => { program .command("get-diagnostic") .alias("gd") .option("-c, --config <agentconfig>", "config file with agent configuration") .option("-a, --agentid <agentid>", "agent id") .option("-k, --passkey <passkey>", "passkey") .option("-l, --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 { checkRequiredParamaters(options); const sdk = (0, command_utils_1.getSdk)(options); color = (0, command_utils_1.adjustColor)(color, options); (0, command_utils_1.homeDirLog)(options.verbose, color); (0, command_utils_1.proxyLog)(options.verbose, color); const mcApiclient = sdk.GetMindConnectApiClient(); let agentid = options.agentid; const configFile = path.resolve(options.config); if (fs.existsSync(configFile)) { const configuration = require(configFile); agentid = configuration.content.clientId; (0, command_utils_1.verboseLog)(`getting diagnostic data for agent with agent id ${color(agentid)}`, options.verbose); } const activations = yield mcApiclient.GetDiagnosticActivations(); (0, console_1.log)(`There are ${color(activations.content.length + " agent(s)")} registered for diagnostic`); (0, 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) { (0, console_1.log)(element); } else if (options.text) { (0, console_1.log)(`${element.timestamp},${element.severity},${element.agentId},${element.correlationId},${element.state},${element.source},${element.message}`); } else { (0, console_1.log)(`${chalk.cyanBright(element.timestamp)} ${chalk.greenBright(element.severity)} ${color(element.source)} ${element.message}`); } } } const information = yield mcApiclient.GetAllDiagnosticInformation(agentid, printDiagnosticInformation, options, !options.all); (0, console_1.log)(`There are ${color(information.totalElements + " ")}total log entries`); } catch (err) { (0, command_utils_1.verboseLog)(color("This operation requires additionaly the service credentials."), options.verbose); (0, command_utils_1.errorLog)(err, options.verbose); } }))(); }) .on("--help", () => { (0, console_1.log)(`\n Examples: \n`); (0, console_1.log)(` mdsp gd -k mypasskey`); (0, console_1.log)(` mdsp get-diagnostic --config someagent.json --passkey mypasskey`); (0, console_1.log)(` mdsp get-diagnostic --passkey mypasskey --text --all > log.csv`); (0, command_utils_1.serviceCredentialLog)(); }); }; function checkRequiredParamaters(options) { !options.agentid && !options.config && (0, command_utils_1.errorLog)("you have to provide a filename for the agent configuration or assetid of the agent", true); !options.agentid && options.config && !fs.existsSync(options.config) && (0, utils_1.throwError)(`the config file ${color(options.config)} doesn't exist.`); } //# sourceMappingURL=mc-get-diagnostic.js.map