Skip to content

Commit

Permalink
chore(deps): Update config vis library to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
Göran Sander committed Aug 28, 2024
1 parent f76db6b commit ae49d81
Show file tree
Hide file tree
Showing 6 changed files with 1,843 additions and 859 deletions.
32 changes: 19 additions & 13 deletions src/lib/config-visualise.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function setupConfigVisServer(logger, config) {
configVisServer.setErrorHandler((error, request, reply) => {
if (error.statusCode === 429) {
globals.logger.warn(
`CONFIG VIS: Rate limit exceeded for source IP address ${request.ip}. Method=${request.method}, endpoint=${request.url}`,
`CONFIG VIS: Rate limit exceeded for source IP address ${request.ip}. Method=${request.method}, endpoint=${request.url}`
);
}
reply.send(error);
Expand All @@ -57,8 +57,9 @@ export async function setupConfigVisServer(logger, config) {

// Get directory contents of dirname
const dirContents = fs.readdirSync(globals.appBasePath);
globals.logger.verbose(`CONFIG VIS: Directory contents of "${globals.appBasePath}": ${dirContents}`);

globals.logger.verbose(
`CONFIG VIS: Directory contents of "${globals.appBasePath}": ${dirContents}`
);

const htmlDir = path.resolve(globals.appBasePath, 'static/configvis');
globals.logger.info(`CONFIG VIS: Serving static files from ${htmlDir}`);
Expand Down Expand Up @@ -89,18 +90,18 @@ export async function setupConfigVisServer(logger, config) {
// Read index.html from disk
// dirname points to the directory where this file (app.js) is located, taking into account
// if the app is running as a packaged app or as a Node.js app.
globals.logger.verbose(`----------------3: ${globals.appBasePath}`);
globals.logger.verbose(`----------------: ${globals.appBasePath}`);
const filePath = path.resolve(globals.appBasePath, 'static/configvis', 'index.html');
const template = fs.readFileSync(filePath, 'utf8');

// Compile handlebars template
const compiledTemplate = handlebars.compile(template);

// Get config as HTML encoded JSON string
const butlerConfigJsonEncoded = JSON.stringify(newConfig);
const butlerSosConfigJsonEncoded = JSON.stringify(newConfig);

// Render the template
const renderedText = compiledTemplate({ butlerConfigJsonEncoded, butlerConfigYaml });
const renderedText = compiledTemplate({ butlerSosConfigJsonEncoded, butlerConfigYaml });

globals.logger.debug(`CONFIG VIS: Rendered text: ${renderedText}`);

Expand All @@ -115,24 +116,29 @@ export async function setupConfigVisServer(logger, config) {
},
(err, address) => {
if (err) {
globals.logger.error(`CONFIG VIS: Could not set up config visualisation server on ${address}`);
globals.logger.error(
`CONFIG VIS: Could not set up config visualisation server on ${address}`
);
globals.logger.error(`CONFIG VIS: ${err.stack}`);
configVisServer.log.error(err);
process.exit(1);
}
globals.logger.info(`CONFIG VIS: Config visualisation server listening on ${address}`);

globals.logger.info(
`CONFIG VIS: Config visualisation server listening on ${address}`
);

configVisServer.ready((err2) => {
if (err2) throw err;
});
},
);
}
);
} catch (err) {
globals.logger.error(`CONFIG VIS: Error setting up config visualisation server: ${err.message}`);
globals.logger.error(
`CONFIG VIS: Error setting up config visualisation server: ${err.message}`
);
if (err.stack) {
globals.logger.error(`CONFIG VIS: ${err.stack}`);
}
throw err;
}
}

95 changes: 87 additions & 8 deletions static/configvis/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<html lang="en">
<head>
<title>Ctrl-Q</title>
<title>Butler SOS</title>

<link rel="stylesheet" href="jsontree.js.css" />
<script src="jsontree.js"></script>
Expand Down Expand Up @@ -125,6 +125,8 @@
border-radius: 5px;
overflow: auto;
}


</style>
</head>

Expand All @@ -139,7 +141,11 @@
<div id="pageTitle">
<h1>
Current Butler SOS configuration (docs
<a href="https://butler-sos.ptarmiganlabs.com/docs/reference/config_file_format/" target="_blank">here</a>)
<a
href="https://butler-sos.ptarmiganlabs.com/docs/reference/config_file_format/"
target="_blank"
>here</a
>)
</h1>
</div>
</div>
Expand All @@ -149,15 +155,22 @@ <h1>
<img
src="download-solid.svg"
alt="Download icon"
style="vertical-align: middle; margin-right: 5px; height: 32px; width: 32px"
style="
vertical-align: middle;
margin-right: 5px;
height: 32px;
width: 32px;
"
/>
Download obfuscated YAML
</button>
</div>
<!-- Tab links -->
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'YAML')">YAML</button>
<button class="tablinks" onclick="openTab(event, 'JSONTree')">JSON tree view</button>
<button class="tablinks" onclick="openTab(event, 'JSONTree')">
JSON tree view
</button>
</div>
</div>
</div>
Expand All @@ -181,10 +194,73 @@ <h3>JSON tree view</h3>
showCounts: true,
sortPropertyNames: false,
sortPropertyNamesInAlphabeticalOrder: false,
data: {{butlerConfigJsonEncoded}} }"
style="width: 100%"
data: {{butlerSosConfigJsonEncoded}},
tooltip: {
delay: 50,
offset: 15
},
valueToolTips: {
'Butler-SOS\\logLevel': 'Possible log levels are silly, debug, verbose, info, warn, error',
'Butler-SOS\\fileLogging': 'true/false to enable/disable logging to disk file',
'Butler-SOS\\logDirectory': 'Directory where log files are stored. Relative to Butler-SOS executable',
'Butler-SOS\\anonTelemetry': 'Can Butler SOS send anonymous data about what computer it is running on? <br><br>More info on whata data is collected: https://butler-sos.ptarmiganlabs.com/docs/about/telemetry/',
'Butler-SOS\\configVisualisation': 'Should Butler SOS start a web server that serves an obfuscated view of the Butler SOS config file?',
'Butler-SOS\\configVisualisation\\enable': 'true/false to enable/disable the web UI for config file visualisation',
'Butler-SOS\\configVisualisation\\host': 'Hostname or IP address where the web server will listen. Should be localhost in most cases.',
'Butler-SOS\\configVisualisation\\port': 'Port where the web server will listen. Change if port 3100 is already in use.',
'Butler-SOS\\configVisualisation\\obfuscate': 'Should the config file shown in the web UI be obfuscated? true/false',
'Butler-SOS\\heartbeat': '',
'Butler-SOS\\heartbeat\\enable': '',
'Butler-SOS\\heartbeat\\remoteURL': '',
'Butler-SOS\\heartbeat\\frequency': '',
'Butler-SOS\\dockerHealthCheck': '',
'Butler-SOS\\dockerHealthCheck\\enable': '',
'Butler-SOS\\dockerHealthCheck\\port': '',
'Butler-SOS\\uptimeMonitor': '',
'Butler-SOS\\uptimeMonitor\\enable': '',
'Butler-SOS\\uptimeMonitor\\frequency': '',
'Butler-SOS\\uptimeMonitor\\logLevel': '',
'Butler-SOS\\uptimeMonitor\\storeInInfluxdb\\butlerSOSMemoryUsage': '',
'Butler-SOS\\uptimeMonitor\\storeInInfluxdb\\instanceTag': '',
'Butler-SOS\\uptimeMonitor\\storeNewRelic': '',
'Butler-SOS\\uptimeMonitor\\storeNewRelic\\enable': '',
'Butler-SOS\\uptimeMonitor\\storeNewRelic\\destinationAccount': '',
'Butler-SOS\\uptimeMonitor\\storeNewRelic\\metric': '',
'Butler-SOS\\uptimeMonitor\\storeNewRelic\\metric\\dynamic': '',
'Butler-SOS\\uptimeMonitor\\storeNewRelic\\metric\\dynamic\\butlerMemoryUsage.enable': '',
'Butler-SOS\\uptimeMonitor\\storeNewRelic\\metric\\dynamic\\butlerUptime.enable': '',
'Butler-SOS\\uptimeMonitor\\storeNewRelic\\attribute': '',
'..\\..\\name': 'Name of New Relic attribute',
'Butler-SOS\\uptimeMonitor\\storeNewRelic\\attribute\\dynamic.butlerVersion.enable': '',
'Butler-SOS\\thirdPartyToolsCredentials': '',
'Butler-SOS\\thirdPartyToolsCredentials\\newRelic': '',
'Butler-SOS\\userEvents': '',
'Butler-SOS\\userEvents\\enable': '',
'Butler-SOS\\userEvents\\excludeUser': '',
'Butler-SOS\\userEvents\\udpServerConfig': '',
'Butler-SOS\\userEvents\\udpServerConfig\\serverHost': '',
'Butler-SOS\\userEvents\\udpServerConfig\\portUserActivityEvents': '',
'Butler-SOS\\userEvents\\tags': '',
'Butler-SOS\\userEvents\\sendToMQTT\\enable': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\everythingTopic.enable': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\everythingTopic.topic': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\sessionStartTopic.enable': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\sessionStartTopic.topic': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\sessionStopTopic.enable': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\sessionStopTopic.topic': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\connectionOpenTopic.enable': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\connectionOpenTopic.topic': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\connectionCloseTopic.enable': '',
'Butler-SOS\\userEvents\\sendToMQTT\\postTo\\connectionCloseTopic.topic': '',
'Butler-SOS\\userEvents\\sendToInfluxdb\\enable': '',
'Butler-SOS\\userEvents\\sendToNewRelic\\enable': '',
'Butler-SOS\\userEvents\\sendToNewRelic\\destinationAccount': '',
'Butler-SOS\\logEvents': '',
'Butler-SOS\\logEvents\\udpServerConfig': '',
}
}"
style="width: 100%; max-width: 100%"
>
Your HTML.
</div>
</div>

Expand All @@ -195,7 +271,10 @@ <h3>JSON tree view</h3>
const yamlData = `{{butlerConfigYaml}}`;
return yamlData;
} catch (error) {
console.error('There was a problem getting YAML config data from Handlebars template:', error);
console.error(
'There was a problem getting YAML config data from Handlebars template:',
error
);
}
}

Expand Down
Loading

0 comments on commit ae49d81

Please sign in to comment.