Update diagnostics as per Issue discussion

This commit is contained in:
Steve-Mcl 2022-03-29 20:48:29 +01:00
parent cf6df1556c
commit 03763a1423
3 changed files with 66 additions and 64 deletions

View File

@ -7,13 +7,13 @@ module.exports = {
runtimeAPI = _runtimeAPI; runtimeAPI = _runtimeAPI;
}, },
getReport: function(req, res) { getReport: function(req, res) {
const diagnosticsOptions = settings.diagnosticsOptions || {}; const diagnosticsOpts = settings.diagnostics || {};
const opts = { const opts = {
user: req.user, user: req.user,
scope: diagnosticsOptions.level || "basic" scope: diagnosticsOpts.level || "basic"
} }
if(diagnosticsOptions.enabled === false || diagnosticsOptions.enabled === "false") { if(diagnosticsOpts.enabled === false || diagnosticsOpts.enabled === "false") {
apiUtil.rejectHandler(req, res, {message: "disabled", status: 403, code: "diagnosticsOptions.enabled" }) apiUtil.rejectHandler(req, res, {message: "disabled", status: 403, code: "diagnostics.enabled" })
} else { } else {
runtimeAPI.diagnostics.get(opts) runtimeAPI.diagnostics.get(opts)
.then(function(result) { res.json(result); }) .then(function(result) { res.json(result); })

View File

@ -69,19 +69,17 @@ function buildDiagnosticReport(scope, callback) {
} }
const now = new Date(); const now = new Date();
const {locale, timeZone} = Intl.DateTimeFormat().resolvedOptions();
const report = { const report = {
report: "diagnostics", report: "diagnostics",
scope: scope, scope: scope,
version: runtime.settings.version,
isStarted: runtime.isStarted(),
containerised: isInContainer(),
wsl: isInWsl(),
time: { time: {
timestamp: now.valueOf(), utc: now.toUTCString(),
utc: "" + now.toUTCString(), local: now.toLocaleString(),
locale: now.toLocaleString(), },
intl: {
locale, timeZone
}, },
intl: Intl.DateTimeFormat().resolvedOptions(),
nodejs: { nodejs: {
version: process.version, version: process.version,
arch: process.arch, arch: process.arch,
@ -89,6 +87,8 @@ function buildDiagnosticReport(scope, callback) {
memoryUsage: process.memoryUsage(), memoryUsage: process.memoryUsage(),
}, },
os: { os: {
containerised: isInContainer(),
wsl: isInWsl(),
totalmem: os.totalmem(), totalmem: os.totalmem(),
freemem: os.freemem(), freemem: os.freemem(),
arch: os.arch(), arch: os.arch(),
@ -100,67 +100,69 @@ function buildDiagnosticReport(scope, callback) {
version: os.version(), version: os.version(),
}, },
runtime: { runtime: {
isStarted: runtime.isStarted(),
modules: modules, modules: modules,
version: runtime.settings.version,
settings: { settings: {
available: runtime.settings.available(), available: runtime.settings.available(),
apiMaxLength: runtime.settings.apiMaxLength || "NO SETTING", apiMaxLength: runtime.settings.apiMaxLength || "UNSET",
//coreNodesDir: runtime.settings.coreNodesDir, //coreNodesDir: runtime.settings.coreNodesDir,
disableEditor: runtime.settings.disableEditor, disableEditor: runtime.settings.disableEditor,
contextStorage: listContextModules(), contextStorage: listContextModules(),
debugMaxLength: runtime.settings.debugMaxLength || "NO SETTING", debugMaxLength: runtime.settings.debugMaxLength || "UNSET",
editorTheme: runtime.settings.editorTheme || "NO SETTING", editorTheme: runtime.settings.editorTheme || "UNSET",
flowFile: runtime.settings.flowFile || "NO SETTING", flowFile: runtime.settings.flowFile || "UNSET",
mqttReconnectTime: runtime.settings.mqttReconnectTime || "NO SETTING", mqttReconnectTime: runtime.settings.mqttReconnectTime || "UNSET",
serialReconnectTime: runtime.settings.serialReconnectTime || "NO SETTING", serialReconnectTime: runtime.settings.serialReconnectTime || "UNSET",
adminAuth: runtime.settings.adminAuth ? "HAS SETTING" : "NO SETTING", adminAuth: runtime.settings.adminAuth ? "SET" : "UNSET",
httpAdminRoot: runtime.settings.adminAuth ? "HAS SETTING" : "NO SETTING", httpAdminRoot: runtime.settings.adminAuth ? "SET" : "UNSET",
httpAdminCors: runtime.settings.httpAdminCors ? "HAS SETTING" : "NO SETTING", httpAdminCors: runtime.settings.httpAdminCors ? "SET" : "UNSET",
httpNodeAuth: runtime.settings.httpNodeAuth ? "HAS SETTING" : "NO SETTING", httpNodeAuth: runtime.settings.httpNodeAuth ? "SET" : "UNSET",
httpAdminRoot: runtime.settings.httpAdminRoot || "NO SETTING", httpAdminRoot: runtime.settings.httpAdminRoot || "UNSET",
httpAdminCors: runtime.settings.httpAdminCors ? "HAS SETTING" : "NO SETTING", httpAdminCors: runtime.settings.httpAdminCors ? "SET" : "UNSET",
httpNodeRoot: runtime.settings.httpNodeRoot || "NO SETTING", httpNodeRoot: runtime.settings.httpNodeRoot || "UNSET",
httpNodeCors: runtime.settings.httpNodeCors ? "HAS SETTING" : "NO SETTING", httpNodeCors: runtime.settings.httpNodeCors ? "SET" : "UNSET",
httpStatic: runtime.settings.httpStatic ? "HAS SETTING" : "NO SETTING", httpStatic: runtime.settings.httpStatic ? "SET" : "UNSET",
httpStatic: runtime.settings.httpStaticRoot || "NO SETTING", httpStatic: runtime.settings.httpStaticRoot || "UNSET",
httpStaticCors: runtime.settings.httpStaticCors ? "HAS SETTING" : "NO SETTING", httpStaticCors: runtime.settings.httpStaticCors ? "SET" : "UNSET",
uiHost: runtime.settings.uiHost ? "HAS SETTING" : "NO SETTING", uiHost: runtime.settings.uiHost ? "SET" : "UNSET",
uiPort: runtime.settings.uiPort ? "HAS SETTING" : "NO SETTING", uiPort: runtime.settings.uiPort ? "SET" : "UNSET",
userDir: runtime.settings.userDir ? "HAS SETTING" : "NO SETTING", userDir: runtime.settings.userDir ? "SET" : "UNSET",
} }
} }
} }
if (scope == "admin") { // if (scope == "admin") {
const moreSettings = { // const moreSettings = {
adminAuth_type: (runtime.settings.adminAuth && runtime.settings.adminAuth.type) ? runtime.settings.adminAuth.type : "NO SETTING", // adminAuth_type: (runtime.settings.adminAuth && runtime.settings.adminAuth.type) ? runtime.settings.adminAuth.type : "UNSET",
httpAdminCors: runtime.settings.httpAdminCors ? runtime.settings.httpAdminCors : "NO SETTING", // httpAdminCors: runtime.settings.httpAdminCors ? runtime.settings.httpAdminCors : "UNSET",
httpNodeCors: runtime.settings.httpNodeCors ? runtime.settings.httpNodeCors : "NO SETTING", // httpNodeCors: runtime.settings.httpNodeCors ? runtime.settings.httpNodeCors : "UNSET",
httpStaticCors: runtime.settings.httpStaticCors ? "HAS SETTING" : "NO SETTING", // httpStaticCors: runtime.settings.httpStaticCors ? "SET" : "UNSET",
settingsFile: runtime.settings.settingsFile ? runtime.settings.settingsFile : "NO SETTING", // settingsFile: runtime.settings.settingsFile ? runtime.settings.settingsFile : "UNSET",
uiHost: runtime.settings.uiHost ? runtime.settings.uiHost : "NO SETTING", // uiHost: runtime.settings.uiHost ? runtime.settings.uiHost : "UNSET",
uiPort: runtime.settings.uiPort ? runtime.settings.uiPort : "NO SETTING", // uiPort: runtime.settings.uiPort ? runtime.settings.uiPort : "UNSET",
userDir: runtime.settings.userDir ? runtime.settings.userDir : "NO SETTING", // userDir: runtime.settings.userDir ? runtime.settings.userDir : "UNSET",
} // }
const moreNodejs = { // const moreNodejs = {
execPath: process.execPath, // execPath: process.execPath,
pid: process.pid, // pid: process.pid,
} // }
const moreOs = { // const moreOs = {
cpus: os.cpus(), // cpus: os.cpus(),
homedir: os.homedir(), // homedir: os.homedir(),
hostname: os.hostname(), // hostname: os.hostname(),
networkInterfaces: os.networkInterfaces(), // networkInterfaces: os.networkInterfaces(),
} // }
report.runtime.settings = Object.assign({}, report.runtime.settings, moreSettings); // report.runtime.settings = Object.assign({}, report.runtime.settings, moreSettings);
report.nodejs = Object.assign({}, report.nodejs, moreNodejs); // report.nodejs = Object.assign({}, report.nodejs, moreNodejs);
report.os = Object.assign({}, report.os, moreOs); // report.os = Object.assign({}, report.os, moreOs);
} // }
callback(report); callback(report);

View File

@ -224,7 +224,7 @@ module.exports = {
/******************************************************************************* /*******************************************************************************
* Runtime Settings * Runtime Settings
* - lang * - lang
* - diagnosticsOptions * - diagnostics
* - logging * - logging
* - contextStorage * - contextStorage
* - exportGlobalContextKeys * - exportGlobalContextKeys
@ -240,14 +240,14 @@ module.exports = {
/** ### Configure diagnostics options /** ### Configure diagnostics options
* - `.enabled`: When `enabled` is `true` (or unset), diagnostics data will * - `.enabled`: When `enabled` is `true` (or unset), diagnostics data will
* be available at http://localhost:1880/diagnostics * be available at http://localhost:1880/diagnostics
* - `.level`: When `level` is "basic" (or unset), the diagnostics will not * - `.ui`: When `ui` is `true` (or unset), the action `show-system-info` will
* include sensitive data. Set level to "admin" for detailed diagnostics * be available to logged in users of node-red editor
*/ */
diagnosticsOptions: { diagnostics: {
/** @type {boolean} enable or disable diagnostics. Must be set to `false` to disable */ /** @type {boolean} `enabled` - enable or disable diagnostics endpoint. Must be set to `false` to disable */
enabled: true, enabled: true,
/** @type {"basic"|"admin"} diagnostic level can be "basic" (default) or "admin" (more sensitive details are included) */ /** @type {boolean} `ui` - enable or disable diagnostics display in the node-red editor. Must be set to `false` to disable */
level: "basic", ui: true,
}, },
/** Configure the logging output */ /** Configure the logging output */