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;
},
getReport: function(req, res) {
const diagnosticsOptions = settings.diagnosticsOptions || {};
const diagnosticsOpts = settings.diagnostics || {};
const opts = {
user: req.user,
scope: diagnosticsOptions.level || "basic"
scope: diagnosticsOpts.level || "basic"
}
if(diagnosticsOptions.enabled === false || diagnosticsOptions.enabled === "false") {
apiUtil.rejectHandler(req, res, {message: "disabled", status: 403, code: "diagnosticsOptions.enabled" })
if(diagnosticsOpts.enabled === false || diagnosticsOpts.enabled === "false") {
apiUtil.rejectHandler(req, res, {message: "disabled", status: 403, code: "diagnostics.enabled" })
} else {
runtimeAPI.diagnostics.get(opts)
.then(function(result) { res.json(result); })

View File

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

View File

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